Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB3 - Separate local and remote interfaces needed?

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jon Wetherbee
author
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default type will be Local, when no annotations are specified.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic