Name

Service Locator

Goal

Simplify and centralize connections to remote services (Figure B-10).

Classes in the Service Locater pattern
Figure B-10. Classes in the Service Locater pattern

Participants

Client

Locates business services using a service locator.

Service locator

Looks up and maintains connections to remote service factories.

Service factory

Instantiates business services.

Business services

Control access to business data (Figure B-11).

Interactions in the Service Locator pattern
Figure B-11. Interactions in the Service Locator pattern

Interactions

The client instantiates and configures the service locator. The client requests a remote service factory from the locator. The locator looks up and optionally caches the service factory. The client uses the factory to generate an instance of the business service. The client uses the business service to manipulate business data.

Notes

In J2EE, service locators can be used to encapsulate interactions with the JNDI directory. The service factories are EJB home objects, or JMS connection factories. EJB service locators frequently cache results of JNDI lookups such as EJB home objects.

Get J2EE Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.