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.
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
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?
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
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop