Tuesday, October 2, 2012

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

Document  Version 1.0
  Copyright © 2012-2013 beijing.beijing.012@gmail.com

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

In "HA Singleton, Cluster Wide Singleton as MBean in JBoss 5", part1-2, we have successfully configured a 2-nodes JBoss cluster, and have reated a "TestHASingleton" MBean. This bean is ready to be deployed as a JBoss HA singleton. If you have followed the part2, you should now have a "TestHASingleton.sar" file. In this part 3 of the serial, we will deploy the  "TestHASingleton" Mbean in JBoss cluster. We will also do some experiments to make sure it is really a HA singleton, i.e. it runs ONLY once in the cluster.

Deployment of "TestHASingleton" MBean

Put the "TestHASingleton.sar in "JBOSS_HOME/server/node1/farm/".
You will see following information in the console of node1 :

10:28:09,752 INFO  [STDOUT] ### Starting JbHaSingletonSvcSample Singleton Service..

From the above text we can see that the "startSingletonService" method of "JbHaSingletonSvcSample" is called, i.e. the singleton is started on node1.

We check the console output of node2, nothing about the singleton is shown. This is correct.

Shutdown node1

Now, we will shut down node1. Now we will see following info in the console of node2:

10:40:05,383 INFO  [STDOUT] ### Starting JbHaSingletonSvcSample Singleton Service..

Find out service on which node will the singleton be active?

step1. shutdown node1 and node2
step2.  remove the "TestHASingleton.sar" from farms of both nodes
step3.  start node1
step4.  start node2
step5. deploy "TestHASingleton.sar" in farm of node2.

The console of node2 shows:

10:48:34,880 INFO  [STDOUT] ### Starting JbHaSingletonSvcSample Singleton Service..
10:48:37,657 INFO  [STDOUT] ### Stopping JbHaSingletonSvcSample Singleton Service..

The console of node1 shows:

10:48:37,658 INFO  [STDOUT] ### Starting JbHaSingletonSvcSample Singleton Service..

This is because, via default, a HA singleton will only active on the "master" node of a cluster (JBoss mainains a sorted list of all active nodes, sorted by the time it joins the cluster. The first node in the list will be choosen as master... ). A HA singleton is active only on the MASTER node.

We could also customize the HA singleton behavior when deciding service on which node should be made active. In such case customized "HA selection policy" is needed... 


  1. Troubleshooting:
    1.javax.management.NotCompliantMBeanException: Class does not expose a management interface: java.lang.Object

    When you see above exceptions in JBoss console, you might have a problem with the MBean naming convention:

    "If the source class is named Serious, then the interface must be named SeriousMBean"