• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB3 - Separate local and remote interfaces needed?

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The default type will be Local, when no annotations are specified.
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic