aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB3 - Separate local and remote interfaces needed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB3 - Separate local and remote interfaces needed?" Watch "EJB3 - Separate local and remote interfaces needed?" New topic
Author

EJB3 - Separate local and remote interfaces needed?

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10263
    
168

Jon/Raghu,

I was going through the Sample Chapter2 from your book. In your example(on Page 10 - Section "The Business Interface"), you have a SearchFacadeBean which has a remote interface and a local interface:

Remote Interface(SearchFacade.java):




Local Interface (SearchFacadeLocal.java):



Looking at these 2 interfaces, there's no difference between them except for the annotations that have been used on each of them. Unlike EJB2.x the method signatures are the same for both these interfaces. Couldn't we do with just one interface for both remote as well as local interface?


[My Blog] [JavaRanch Journal]
Jon Wetherbee
author
Ranch Hand

Joined: Oct 05, 2006
Posts: 33
Hi Jaikiran-
Good question. I don't know if the reason for this is spelled out in the spec, but I believe the reason why you can't collapse @Local and @Remote behavior onto the same interface is this would confuse the implicit lookup semantics. Remote interfaces pass objects by value, whereas Local interfaces pass by reference, so the EJB container needs to know which one it's dealing with when it serves up a session bean to a client. When injecting an EJB using @EJB injection (or the XML equivalent), the container determines, from the interface specified by the lookup, which way to go. If the interface is ambiguously declared as both @Local and @Remote, it wouldn't be able figure this out, so this is illegal.

Regards,
Jon
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10263
    
168

Thanks Jon, for the reply.

When injecting an EJB using @EJB injection (or the XML equivalent), the container determines, from the interface specified by the lookup, which way to go. If the interface is ambiguously declared as both @Local and @Remote, it wouldn't be able figure this out, so this is illegal.


That makes sense.

However, i do see a alternate approach that might have been used - to avoid specifying redundant interfaces. A single interface could have been allowed to be annotated as @Remote as well as @Local. And when a bean has to be injected we could have had annotations like @EJBRemote and @EJBLocal which would tell the container which one to inject.

Just my thoughts.
S Thiyanesh
Ranch Hand

Joined: Mar 19, 2006
Posts: 142
The default type will be Local, when no annotations are specified.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB3 - Separate local and remote interfaces needed?