Service Locator Pattern - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Service Locator Pattern

Description:

Use Service Locator object to abstract all JNDI usage and to hide the ... Multiple clients can reuse the Service Locator object. Structure ... – PowerPoint PPT presentation

Number of Views:85
Avg rating:3.0/5.0
Slides: 20
Provided by: thesim
Category:
Tags: locator | pattern | service | the

less

Transcript and Presenter's Notes

Title: Service Locator Pattern


1
Service Locator Pattern
  • Hanh Nguyen

2
Overview
  • Context
  • Problem
  • Forces
  • Solution
  • Strategy
  • Consequences
  • Demo

3
Context
  • Service lookup and creation involves complex
    interfaces and network operations

4
Problem
  • J2EE clients interact with EJB and JMS.
  • Clients must either locate these components or
    create a new ones
  • Clients use the common JNDI to locate those
    components

5
Forces
  • The context factories are difference from vendor
    to vendor
  • Lookup and creation of service components could
    be complex and may be used repeatedly and
    resource-intensive

6
Solution
  • Use Service Locator object to abstract all JNDI
    usage and to hide the complexities of initial
    context creation
  • Multiple clients can reuse the Service Locator
    object.

7
Structure
8
Participants and Responsibilities
9
Sample code - Service Locator
  • public class ServiceLocator
  • private ServiceLocator() context new
    InitialContext()
  • public static ServiceLocator getInstance()
  • if (me null) me new ServiceLocator()
  • return me
  • public EJBHome getHome(String name, Class clazz)
  • Object objref context.lookup(name)
  • EJBHome home PortableRemoteObject.narrow(objre
    f,clazz)
  • return home

10
Sample code - Client
  • public class ServiceLocatorTester
  • public static void main( String args )
    ServiceLocator serviceLocator
    ServiceLocator.getInstance()

11
Strategy - EJB Service Locator
12
Strategy - EJB Service Locator
13
Strategy - JMS Queue Service Locator
14
Strategy - JMS Queue Service Locator
15
Strategy - JMS Topic Service Locator Strategy
16
Strategy - JMS Topic Service Locator Strategy
17
Consequences
  • Abstracts Complexity
  • Provides Uniform Service Access to Clients
  • Facilitates Adding New Business Components
  • Improves Network Performance
  • Improves Client Performance by Caching

18
Demo
  • Encryption Decryption Service
  • Using Service Locator pattern to implement load
    balancing and fail over.

19
Crypto Service Diagram
Write a Comment
User Comments (0)
About PowerShow.com