Sunday, August 7, 2016

Registry Pattern - A Java Enterprise Design Pattern

Registry Pattern also called as the Name Service pattern.

Requirement : An object needs to contact other objects for which it knows only the object's name or the service it provides but not how to contact the object.

Case Study : A telephone company acquires other telephone companies and the company wants to expose the newly acquired companies' services using the companies existing interfaces. 

The existing company exposes interfaces and creates adapter objects by implementing these interfaces for each of the acquired systems and the implementations interact with the acquired systems in a way that makes the acquired systems to behave in the same way as the companies existing systems.

To make the new services available for client applications , mention the names of the new applications in a shared registry accessed by the client applications. The implementations of the acquired systems register their names with a registry object and when a client asks the registry to lookup a service , it returns a proxy object that can be used to communicate to the named object, since the proxy will encapsulate the knowledge of how to contact the named object.

Solution : Register service-providing objects with a registry object that is widely known to other objects. The registration associates a name to the remote proxy that encapsulates the knowledge of how to call the methods of the named object. When given a name , the registry object produces the proxy.

Following are the participating components of this solution -
  • ServiceInterface: Interface that is implemented by both the ServiceObject and the RemoteProxy.
  • ServiceObject: The ServiceObject is the service provider that the clients wants to invoke methods on remotely, but does not know how to communicate with it.
  • RemoteProxy: This class is a proxy for ServiceObject , it implements ServiceInterface by remotely calling the corresponding methods of the ServiceObject.
  • Registry: The ServiceObject objects register themselves with the Registry object. The registration process involves sending the object's name along with a proxy object of the ServiceObject to the Registry's bind method. The registration remains in effect till the object's name is sent to Registry's unbind method and while registration is in effect , the Registry's lookup method returns the proxy when it is passed with the object's name.
  • Client: Client objects want to access the shared objects of the ServiceObject , but do not have any way to refer to it.What they know is the role|service name of the ServiceObject and a way to contact the Registry.

-> Following the above pattern :
1. Client objects are able to access service objects without having any prior knowledge of where the service objects are . It means it's possible to change the location of serviceObjects without having to make any change in the client classes.

2.Client and Service objects are required to have prior knowledge of where the Registry object lies.

Usage:

-> The registry pattern is used in computer networks The DNS application implements the Registry pattern , DNS binds names to ipAddresses than proxies.

-> Java's RMI protocol is an implementation of the Registry pattern, which we will be seeing in the next blog. 

Happy Learning 
Feel free to improve this writeup for better understanding.

No comments:

Post a Comment