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?
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.
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
posted
0
The default type will be Local, when no annotations are specified.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: EJB3 - Separate local and remote interfaces needed?