It's not a secret anymore!*
The moose likes EJB and other Java EE Technologies and the fly likes Caching references to RemoteInterface 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 "Caching references to RemoteInterface" Watch "Caching references to RemoteInterface" New topic
Author

Caching references to RemoteInterface

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9350
    
    2

Guys,

Will caching a reference to the EJB 3 RemoteInterface be technically feasible?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9350
    
    2

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

Jothi,
Why can't you cache it the same way as in EJB 2? Do a JNDI lookup and cache the returned value.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9350
    
    2

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

Joined: Sep 26, 2006
Posts: 9350
    
    2

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

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

Joined: Sep 26, 2006
Posts: 9350
    
    2

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

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

Joined: Sep 26, 2006
Posts: 9350
    
    2

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

Joined: Sep 26, 2006
Posts: 9350
    
    2

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

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

Joined: Sep 26, 2006
Posts: 9350
    
    2

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

@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

Joined: Sep 26, 2006
Posts: 9350
    
    2

Does the spec says that we can have a Home interface defined for EJB 3 Stateless beans?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

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

Joined: Sep 26, 2006
Posts: 9350
    
    2

Jeanne, you have been of a great help!

Thank you very much!
 
 
subject: Caching references to RemoteInterface