‘HASingleton’ Cluster Deployment Service with ‘PreferredMasterElectionPolicy’ Configuration

A cluster deployment service can be of various types. Today we are going to discuss  on one of its type, HASingleton cluster deployment service.

An HASingleton is a service which is deployed on multiple nodes on a cluster, but provides its service only on one of the nodes. The node which is running the singleton service is called the Master NodeWhen the master fails or is terminates, another node is elected to be a Master Node from the remaining nodes in the cluster, and the service is restarted on the new master. The remaining nodes are generally called Stand by Nodes or Slave Nodes.


JBoss provides mainly 2 election policies:

1. HASingletonElectionPolicySimple

The Simple election policy selects a master node based the relative age. The required age is configured in the position property, which is the index in the list of available nodes where,

position = 0 – refers to the oldest node (the default)

position = 1 – refers to the 2nd oldest etc.

Position can also be negative to indicate the youngness. Imagine the list of available nodes as a circular linked list.

position = -1 – refers to the youngest node

position = -2 – refers to the 2nd youngest node etc.

  <property name="position">-1</property>

2. PreferredMasterElectionPolicy

Sometimes you need a specific node to be the master node whenever available. The Preferred Master election policy does this job. This ppolicy extends HASingletonElectionPolicySimple, allowing the configuration of a preferred node. The preferredMaster property, specified as host:port or address:port, identifies a specific node that should become master, if available. If the preferred node is not available, the election policy will behave as described above.

  <property name="preferredMaster">server1:12345</property>

We will dig more on PreferredMasterElectionPolicy configuration with JBoss 5.x. Configuration steps are as below,

Step-1: Open the file ‘deploy-hasingleton-jboss-beans.xml‘ available in $JBOSS_HOME/server/$Profile/deploy/cluster folder and add the following bean,

<bean class="org.jboss.ha.singleton.PreferredMasterElectionPolicy" name="HSPreferredMasterElectionPolicy">
  <property name="preferredMaster"></property>

Where. is the IP Address and 1299 is the JNP Port. Replace IP and Port respective to your environment.

And, add the following property to HASingletonDeployer bean,

<property name="electionPolicy"><inject bean="HSPreferredMasterElectionPolicy"/></property>

For example,

<bean name="HASingletonDeployer"


exposedInterface=org.jboss.ha.singleton.HASingletonControllerMBean.class, registerDirectly=true)</annotation>

<!-- Have the BarrierController that listens for our JMX
notifications start first. -->

<property name="HAPartition"><inject bean="HAPartition"/></property>
<property name="target"><inject bean="HASingletonProfileManager"/></property>
<property name="electionPolicy"><inject bean="HSPreferredMasterElectionPolicy"/></property>
<property name="targetStartMethod">activateProfile</property>
<property name="targetStopMethod">releaseProfile</property>

<!-- whether to register thread context classloader for the RPC handler, default is false -->
<!--<property name="registerThreadContextClassLoader">false</property>-->

<!-- Whether the singleton should be restarted (i.e. invoke the TargetStopMethod and then the
TargetStartMethod) if a cluster merge occurs while this node is the singleton master.
A cluster merge means there may have been more than one singleton master during the period
when communication between some or all of the nodes in the cluster was disrupted; hence the
surviving master may not be aware of state changes made by another master. Restarting the
singleton gives it a signal that it should refresh its internal state from any external
By default this is set to true.
<property name="restartOnMerge">true</property>


Step-2: Deploy an HA Singleton service in the deploy-hasingleton folder.

Step-3: Start two or more nodes in the cluster partition.

Now, you would see that the HASingleton service would be deployed on the preferredmaster node!