Monday, October 1, 2012

HA Singleton, Cluster Wide Singleton as MBean in JBoss 5, part 1/3

Document  Version 1.0

   Copyright © 2012-2013

JBoss HA  Service, HA Singleton, JBoss Cluster, load migration, load distribution, HA Service deployment

What is HA Singleton?

We know that singletons are the kind of instances or services that exists only once in an application context. When you write a singleton, deploy it in your server, you will get only one instance of this singleton on the server.

The singleton mentioned above is actually class-loader wide singleton,  i.e. one instance per class-loader. In case of high availabile cluster, when the above singleton is deployed in cluster, there will be one singleton instance in each cluster-node.

But there are cases where we need cluster-wide singleton. For example, in a clustered auction system,
bid orders can come from different node, but the process which deals with the final trading settelment should run only once in the whole cluster. When the node on which the singleton service fails, another node will start  an singleton service automatically. Such singleton is so called cluster-wide singleton, i.e. HA singleton.

We will now take JBoss as example to show how to implement a HA singleton.

JBoss supports deployment of singleton as HA singleton. There are generally 2 ways to deplyoment HA singleton on JBoss

  • option1: just put deployment archive under "../deploy-singleton/ ", and the deployment service bekomes a HA singleton. Disadvantages of this way are, no hot-deployment support, in case of node failure, service startup time takes longer...
  • option 2: deploy service as MBean. MBean support hot deployment. Singleton MBean will be deployment on all nodes,  but provides service only on one node. 

We take the second option, and show how to deploy a MBean as HA singleton:
We will configure and run a 2-nodes JBoss cluster
We will write a simple MBean.
We will deploy the MBean as HA singlleton.

Configure and run a 2-nodes JBoss cluster

Download JBoss  5.1.0_GA from (  Extract the file to some location, we will name it JBOSS_HOME hereafter.

In the extracted JBoss directory goto JBOSS_HOME/server/, create 2 new folders directly here:


Copy all files in JBOSS_HOME/server/all into node1.
Copy all files in JBOSS_HOME/server/all into node2.

Now we have a JBoss cluster with two nodes ready to run.

Start node1:

./ -c node1 -Djboss.service.binding.set=ports-01 -Djboss.messaging.ServerPeerID=1

When you have followed the above steps, you will see in the console like these:

09:57:56,551 INFO  [GroupMember] I am (
09:57:56,551 INFO  [GroupMember] New Members : 1 ([])
09:57:56,551 INFO  [GroupMember] All Members : 1 ([])
09:57:56,556 INFO  [STDOUT] 

09:58:03,364 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-
09:58:03,377 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-
09:58:03,382 INFO  [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221634)] Started in 25s:474ms

The node1 is now started.

Start node2:

./ -c node2 -Djboss.service.binding.set=ports-02 -Djboss.messaging.ServerPeerID=2

You will see in the console lines like these:

|1] [,], old view is null
10:01:57,587 INFO  [GroupMember] I am (
10:01:57,587 INFO  [GroupMember] New Members : 2 ([,])
10:01:57,587 INFO  [GroupMember] All Members : 2 ([,])
10:01:57,629 INFO  [STDOUT] 

10:01:59,745 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-
10:01:59,756 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-
10:01:59,762 INFO  [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221634)] Started in 17s:400ms

The second node is started, and it joined the cluster.



  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.