Meaningless Drivel is fun!*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Service Locator patterm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Service Locator patterm" Watch "Service Locator patterm" New topic
Author

Service Locator patterm

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Hi,
Is service pattern useful for local EJB lookup.
The caching benefits are not useful in these case, I guess.


Groovy
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The caching benefit is still there as you need to lookup the EJBLocalHome just as you had to lookup EJBHome with remote beans.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Since the EJBHOME is local and not remote , I feel that there is no caching benefits.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Well, the benefits are definitely smaller than with remote homes but still you can avoid the JNDI lookup. I really have no idea whether the local home lookup can be optimized by the container. Try and see whether there is any difference... (btw, it would be nice if you posted the results here )
Siddharth Mehrotra
Ranch Hand

Joined: Aug 21, 2001
Posts: 185
hi,
Caching of lookups, will definately be an advantage,
cause the local reference gives you the advantage only in calls, as the passing og parameters will be by reference. But as far as I Know there are no specs in EJB2.0 that says that since the reference is local there has to be any change in the way lookup has to be performed.
You might get that advantage by the wat appserver implements its lookup operation, but for that you have to go through your selected appserver.
So as long as you are caching lookups, there is no harm as to where you deploy the code.
And also tom if you decide to change to older ejb spces, ot drop the idea of using local reference. you code will be efficient in that case also.


SCJP, SCJD.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Piggybacking on a topic ... What does anybody do about stale references in your cache? Frinstance if a remote server is bounced - shut down and restarted - your cached homes will be no good. Right?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stan James:
Piggybacking on a topic ... What does anybody do about stale references in your cache? Frinstance if a remote server is bounced - shut down and restarted - your cached homes will be no good. Right?

So you need to basically do two things: identify outdated cache contents and updating it. The more problematic one is probably the former. One idea I would have is using a proxy for the EJBHome. Any comments from more experienced EJB developers?
BTW, this is one of the reasons why I would hesitate implementing the cache until I really needed to - even if it doesn't do any other harm, it invariably increases the complexity of the system.
If you fear that adding the Service Locator pattern later will be costly, you can start with a dummy implementation...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Here is an article from javaworld
www.javaworld.com/javaworld/jw-07-2002/jw-0703-service.html
It uses a separate thread to identify invalid cache. The thread does the check at a specified frequency. What happens if the client tries to access the invalid cached entry before the thread gets a new one? Waiting for answers.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I had seen that approach and it did not make me warm & fuzzy. That's why I was fishing here for any better answers.
One thing we considered was the client wraps the remote work in a try-catch, and on exception removes the bad home from the cache. But that's making all the clients responsible for pool cleaning, which smells even worse.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stan James:
One thing we considered was the client wraps the remote work in a try-catch, and on exception removes the bad home from the cache. But that's making all the clients responsible for pool cleaning, which smells even worse.

That's why I was thinking about a proxy: it could delegate to the actual object and try to get a new one if an exception occurs. All transparently to the client.
How does that sound?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Better!
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Are we talking about a dynamic or a static proxy? How would the client get a hold of this proxy?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Lasse Koskela:
Are we talking about a dynamic or a static proxy?

Isn't that secondary? I would probably go with a dynamic one - it's more complex at first, but you don't need to adopt it everytime your home-interfaces change.
How would the client get a hold of this proxy?

The Service Locator would hand out the proxies instead of the actual ejb homes, as far as I understand.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Ilja Preuss:
The Service Locator would hand out the proxies instead of the actual ejb homes, as far as I understand.

Doh. Of course. My thoughts seem to have spontaneously departed from the context of this thread...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Service Locator patterm
 
Similar Threads
WA #1.....word association
Should I learn web services?
J2EE 1.4 support Web Service
To the Author
What are these services?