[jboss-user] [Clustering/JBoss] - Controlling cluster services

krithi do-not-reply at jboss.com
Mon Oct 15 06:46:33 EDT 2007


I Have setup 2 nodes in a cluster using Jboss 4.0.5 GA
My requirement is:
1. When the first node starts, it becomes the master and starts all my services
2. When the second node starts, it becomes the slave. This node must join the cluster, but my services should not be started. This Slave node must wait to start the services until it becomes the master

I am facing these problems:
1. In the slave node the log correctly shows "MyClusterService - Waiting to acquire Master Status" message but MyClusterService gets started.
2. In order to control MyClusterService from getting started, I am depending upon 
if ( isMasterNode()) check in startService() method. It only controls my JMS messges from getting published and MyClusterService gets started (which I am able to view in JMX-console)

Tried to get Sample Applications with similar requirements, but unable to find. Posting this after few days without help
1. Is using isMasterNode variable the only means to know whether MyClusterService should be started or not,     if so, what is the correct design to control the service using the isMasterNode variable
2. Is there any other means through which I could control the service from not getting started in the slave node, and start them in the master node.

 Is my understanding and approach totally wrong on this? Please help

I have made the following code to implement this.:


  |     public class MyClusterService extends HAServiceMBeanSupport {
  |           private boolean isMasterNode = false;
  |           protected void startService()  throws Exception {
  |               if (isMasterNode()) {
  |                    log.info("MyClusterService Started Successfully");
  |                    //Send JMS messages to indicate Service Started
  |              }else {
  |                    log.info("MyClusterService - Waiting to acquire Master Status");
  |              }
  |          }
  |           protected void stopService() {
  |              log.info("Stopping MyClusterService - If Slave is waiting it will become master ");
  |          }
  |          public boolean isMasterNode() {
  |               return isMasterNode;
  |          }
  |          public void startSingleton() {
  |              isMasterNode = true;
  |             if (isMasterNode) {
  |                startService();
  |            }
  |         }
  |          public void stopSingleton() {
  |               stopService();
  |              isMasterNode=false;
  |          } 
  |     }
  | 
jboss-service.xml

  |  <mbean code="org.jboss.ha.singleton.HASingletonController"
  |           name="my.com:service=MyService-HASingletonController">
  |       
  | <depends>jboss:service=${jboss.partition.name:DefaultPartition}</depends>  
  |       <depends>my.com:service=MyClusterService</depends>
  |       <attribute 
  | name="PartitionName">${jboss.partition.name:DefaultPartition}</attribute>
  |       <attribute 
  | name="TargetName">my.com:service=MyClusterService</attribute>
  |       <attribute name="TargetStartMethod">startSingleton</attribute>
  |       <attribute name="TargetStopMethod">stopSingleton</attribute>
  |       <!-- <attribute name="TargetStopMethodArgument">true</attribute> -->
  |    </mbean>
  |    <mbean code="com.my.cluster.MyClusterService"
  |         name="my.com:service=MyClusterService">
  |         <depends>my.com:service=OtherServices</depends>
  |     </mbean>
  | 

Thanks
Krithi

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095179#4095179

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095179



More information about the jboss-user mailing list