05 March 2012

WebLogic Server Singleton Services

WebLogic Server has supported the notion of a Singleton Service for a number of releases, in which WebLogic Server will maintain a single instance of a configured singleton service on one managed server within a cluster. The singleton can be migrated to another server in the cluster, either automatically if it's current hosting server becomes available, or manually at an operators request. The singleton can be optionally be configured with a preferred server to run on, as well as a set of named servers to which it can be migrated. A singleton can be deployed as a standalone service or as part of an application deployment.

With this capability, a question arises from time-to-time whether the Singleton Service feature in WebLogic Server can be used to provide a cluster wide singleton service for applications to use

The answer to this is yes, but it requires you to do a few things to expose the singleton instance to applications running in the cluster so that it can be looked up and used.

Since a singleton service is basically a POJO that implements the weblogic.cluster.singleton.SingletonService interface, which gets instantiated and managed by WebLogic Server, it doesn't have a surface area that allows it to be seen by applications running in the cluster.

To allow the singleton service to be used by applications, in addition to implementing the basic logic that is required, it also needs to perform the following tasks:

Provide an RMI Remote interface that the singleton service additionally implements, which then allows it to be accessed and invoked from any server in the cluster

When the singleton service is activated, it binds itself into the cluster-wide JNDI tree

When the singleton service is deactivated, unbinds itself from the cluster-wide JNDI tree

Deploying and Configuring the Singleton
To deploy the singleton in standalone mode, compile and package the classes into a JAR file and put the JAR file into the WebLogic Server classpath. Note this needs to be done on each physical machine where the managed servers in the cluster run.

You configure a singleton service instance for cluster using the WebLogic Server console.

1 comment:

spooker
said...

nice one.Careful. Your ear file should not be versioned (i.e. MANIFEST.MF file etc).If the ear is versioned then the Singleton Service will be registered on the cluster servers but it will not be Activated Automatically!!!!