[jboss-cvs] JBossAS SVN: r69426 - trunk/cluster/src/main/org/jboss/ha/singleton.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 28 23:03:41 EST 2008


Author: bstansberry at jboss.com
Date: 2008-01-28 23:03:40 -0500 (Mon, 28 Jan 2008)
New Revision: 69426

Modified:
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
Log:
[JBAS-5183] Provide info as to whether topology changes are due to a merge
[JBAS-4261] Support "restart-on-merge"

Modified: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2008-01-29 04:02:30 UTC (rev 69425)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2008-01-29 04:03:40 UTC (rev 69426)
@@ -1,6 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
@@ -42,6 +42,7 @@
    
    private boolean isMasterNode = false;
    private HASingletonElectionPolicy mElectionPolicyMB = null;
+   private boolean restartOnMerge = true;
 
    // Constructors --------------------------------------------------
    
@@ -81,6 +82,38 @@
       return this.mElectionPolicyMB;
    }
 
+   /**
+    * Gets whether this singleton will stop and restart itself if it is the
+    * master and a cluster merge occurs.
+    * <p/>
+    * A restart allows the service to reset any state that may
+    * have gotten out-of-sync with the rest of the cluster while
+    * the just-merged split was in effect.
+    * 
+    * @return <code>true</code> if a restart will occur, <code>false</code>
+    *         otherwise
+    */
+   public boolean getRestartOnMerge()
+   {
+      return restartOnMerge;
+   }
+
+   /**
+    * Sets whether this singleton will stop and restart itself if it is the
+    * master and a cluster merge occurs?
+    * <p/>
+    * A restart allows the service to reset any state that may
+    * have gotten out-of-sync with the rest of the cluster while
+    * the just-merged split was in effect.
+    * 
+    * @param restartOnMerge <code>true</code> if a restart should occur, 
+    *                       <code>false</code> otherwise
+    */
+   public void setRestartOnMerge(boolean restartOnMerge)
+   {
+      this.restartOnMerge = restartOnMerge;
+   }
+
    // Public --------------------------------------------------------
 
    /**
@@ -127,7 +160,8 @@
     * @see HAServiceMBeanSupport#partitionTopologyChanged(List, int)
     * @see org.jboss.ha.framework.interfaces.DistributedReplicantManager#isMasterReplica(String)
     */
-   public void partitionTopologyChanged(List newReplicants, int newViewID)
+   @Override
+   public void partitionTopologyChanged(List newReplicants, int newViewID, boolean merge)
    {
       boolean isElectedNewMaster;
       if (this.mElectionPolicyMB != null)
@@ -141,7 +175,11 @@
       // if this node is already the master, don't bother electing it again
       if (isElectedNewMaster && isMasterNode)
       {
-         return;
+         // JBAS-4229         
+         if (restartOnMerge && merge)
+         {
+            restartMaster();
+         }
       }
       // just becoming master
       else if (isElectedNewMaster && !isMasterNode)
@@ -204,16 +242,7 @@
          //callMethodOnPartition("_stopOldMaster", new Object[0], new Class[0]);
          callAsyncMethodOnPartition("_stopOldMaster", new Object[0], new Class[0]);
 
-         isMasterNode = true;
-         
-         // notify starting
-         sendLocalNotification(HASINGLETON_STARTING_NOTIFICATION);
-
-         // start new master
-         startSingleton();
-         
-         // notify started
-         sendLocalNotification(HASINGLETON_STARTED_NOTIFICATION);         
+         startNewMaster();  
       }
       catch (Exception ex)
       {
@@ -221,6 +250,28 @@
       }
    }
    
+   protected void startNewMaster()
+   {
+      log.debug("startNewMaster, isMasterNode=" + isMasterNode);
+      
+      isMasterNode = true;
+      
+      // notify starting
+      sendLocalNotification(HASINGLETON_STARTING_NOTIFICATION);
+
+      // start new master
+      startSingleton();
+      
+      // notify started
+      sendLocalNotification(HASINGLETON_STARTED_NOTIFICATION);
+   }
+   
+   protected void restartMaster()
+   {
+      _stopOldMaster();
+      startNewMaster();
+   }
+   
    // Private -------------------------------------------------------
    
    private void sendLocalNotification(String type)




More information about the jboss-cvs-commits mailing list