|
Awaken the Service Locator
Avoid critical client application start-up delays by enhancing the service locator pattern with an exception-awareness mechanism
by Paulo Caroli
Posted April 21, 2004
What can you do in a typical J2EE application in which a server-side, service-initialization error detains the client application, yet it's critical that the client application remain available? Let's look at a service locator-based solution for avoiding this kind of undesirable client application start-up problem. The client application, which does not execute in an Enterprise JavaBeans (EJB) container, is composed of several clients that locate the EJB through the service locator as part of the client application initialization process.
Availability of the client application is critical. It must execute even if the server-side service does not. One very important feature is the capability for the client to operate in safe mode. The client safe mode operation keeps the client application executing while the server is facing problems. With the server side facing problems (for example, a database crash), the critical availability solution with client safe mode works properly when the client application keeps its execution in the client safe-mode operation, during which it logs execution information for later data processing recovery. Once the problems are solved, the data-recovery process takes care of the information logged during the downtime period.
During the application test phase, we simulated a very critical crash where both the client and server machines were turned off abruptly. As part of the critical client application infrastructure solution, monitoring tools caught the client problem within seconds and the client servers were restarted. However, the client start-up delay was not acceptable. The client could not come up fast enough unless the server was up, and its safe-mode operation couldn't start before the delayed startup was over.
The client application makes use of the service locator pattern, which abstracts the complexity of network operation for service lookups as EJB Home and Java Message Service (JMS) component factories. Figure 1 shows the client application using the service locator.
The service locator is invoked for each client initialization process. For example, to acquire an EJB Home object for the first time, the service locator first creates a Java Naming and Directory Interface (JNDI) initial context object and performs a lookup on the EJB Home object. Because this operation utilizes significant resources and because multiple clients repeatedly require the same EJB Home object, the service locator caches the object, and consecutive calls use the cached service.
To improve application performance, the service locator caches service objects to eliminate unnecessary JNDI activity that occurs in a lookup operation. When the second client requires a previously requested service, the service locator responds faster because a reference to the service is already available on the client side. Figure 2 shows the client application using the service locator but catching exceptions because of a service-initialization problem.
Back to top
|