Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When to use the servicesLocator pattern, question about petstore1.3

 
James Liu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Today when I looked at petstore source code, I found this:
1. When signonEJB sessionbean calls the UserEJB entitybean local interface, it just simply lookup, it did not use serviceLocator.
2 .Then I found when shoppingClientFacadeLocalEJB session lookup the Customer entitybean, it uses serviceLocator.
3. Then I check the CORE PATTERN books, from the UML, it looks like if you try to lookup the sessionfacade from outside EJB container , using serviceLocator, if a sessionbean calls a entitybean, it does not use serviceLocator.
So anybody can explain this, I am really confuse by this. I am so suprised about this, before I thought we should always use serviceLocator whenever you try to lookup a EJB, I have been using this for a while in our project.
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think if you locate the REMOTE interface,the servicelocator can reduce the times to the jndi lookups,but to the LOCAL interface,i don't think the servicelocator make sense.
 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServiceLocator pattern can be used (as the name suggests) for any Service. You can use this for getting the Datasources, database Connection from connection pool, JNDI lookups etc. The main purpose is to reduce the network calls. If your looking for an EJBHome object for the first time it will look for it on the network and cache it for later use. So you do not have to make a number of network calls again and again.
try:
http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html
http://www.precisejava.com
 
James Liu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the post, but the problem is :
in petstore example, when signonEJB sessionbean calls the UserEJB entitybean local interface, it just simply lookup, it did not use erviceLocator.
but when shoppingClientFacadeLocalEJB session lookup the Customer entitybean local interface, it uses serviceLocator. I mean why both cases is sessionbean lookup entityBean local interface, but one it uses servicesLocator, but the other not?
 
bor
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear James,
Try to think the following points:
1. the benefit of service locator
2. the applicability of service locator
3. the relationship between service locator and session facade
4. the type and functionality of SignOnEJB and ShoppingClientFacadeLocalEJB
Sincerely,
Hayes Sprint
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic