Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Caching references to RemoteInterface

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Will caching a reference to the EJB 3 RemoteInterface be technically feasible?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I googled through many topics and I'm not able to find any suitable answer to this. I hope that javaranch will give me some hints.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jothi,
Why can't you cache it the same way as in EJB 2? Do a JNDI lookup and cache the returned value.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have heard many different stories about caching Remote Interface references. Take a look at this for example,

http://www.theserverside.com/discussions/thread.tss?thread_id=32307
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Jothi,
Why can't you cache it the same way as in EJB 2? Do a JNDI lookup and cache the returned value.


How can I cache RemoteInterface references?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
I have heard many different stories about caching Remote Interface references. Take a look at this for example,

http://www.theserverside.com/discussions/thread.tss?thread_id=32307

That thread says it is ok to cache remote home interfaces and not the remote bean reference. This is correct. You should request the bean from the home interface each time. The (relatively) expensive JNDI call to look up the home is what you are trying to avoid.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
How can I cache RemoteInterface references?

Take a look at the ServiceLocator pattern. If you scroll down, there is an example from Sun using JNDI on the page.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne for the link. But even in that link, they only cache the Home interface and not the Remote interface. So still my question is un answered. Is it possible and feasible to cache references to Remote Interfaces?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJBHome is the remote home interface. You shouldn't cache the actual remote interface as that is the bean. I meant RemoteHome when I was talking about remote interfaces you can cache above.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
EJBHome is the remote home interface. You shouldn't cache the actual remote interface as that is the bean. I meant RemoteHome when I was talking about remote interfaces you can cache above.


Thanks Jeanne. That was what I was looking for. If I cache a RemoteInterface reference what implications that it would bring to my system? I guess if we do this, we would not be returning the instance to the container's pool and very soon when all the references from the container are exhausted just because of our caching....is it something like this?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don"t we see this as a setback in EJB 3 as everytime I have to do a JNDI lookup to my Remote Interface but with EJB 2.x, I can avoid such JNDI lookups by caching my Remote Home Interface reference.

What do you guys say?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
Don"t we see this as a setback in EJB 3 as everytime I have to do a JNDI lookup to my Remote Interface but with EJB 2.x, I can avoid such JNDI lookups by caching my Remote Home Interface reference.

What do you guys say?

Why can't you do the JNDI lookup and cache the remote home interface? There is a @RemoteHome annotation so you can still create a remote interface and look it up in the JNDI.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But my client class is not managed, meaning it does not live in EJB aware enviornment. So I cannot use the @RemoteHome annotation. But by the way, is there such an annotation in EJB 3? I heard that there is not more Home interfaces in EJB 3? Did I go wrong somewhere?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@RemoteHome is defined on the server/ejb. Your client uses JNDI the way it always was. I've seen that Home interfaces are not required, not that they are forbidden. The fact that @RemoteHome exists (I read about it in EJB 3 in Action) implies you can still define it.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the spec says that we can have a Home interface defined for EJB 3 Stateless beans?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
Does the spec says that we can have a Home interface defined for EJB 3 Stateless beans?

See this blog entry on sun.com for an example of @RemoteHome. It's written by "the lead architect for the EJB 3.0 container in the Java EE 5 SDK." so he knows what he is talking about. I also read about this annotation in a book.

I'm sure the spec says it is legal. You are welcome to download the spec to verify this if you'd like.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne, you have been of a great help!

Thank you very much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic