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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 17 15:34:08 EDT 2008


Author: pferraro
Date: 2008-06-17 15:34:08 -0400 (Tue, 17 Jun 2008)
New Revision: 74717

Modified:
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
Log:
[JBAS-5438] Ensure HASingletonSupport can handle concurrent JGroups requests
Enabled concurrent access to master flag.
Made other mbean attributes volatile as necessary.

Modified: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2008-06-17 19:21:49 UTC (rev 74716)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java	2008-06-17 19:34:08 UTC (rev 74717)
@@ -22,6 +22,7 @@
 package org.jboss.ha.singleton;
 
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.management.Notification;
 
@@ -35,6 +36,7 @@
  * @author <a href="mailto:scott.stark at jboss.org">Scott Stark</a>
  * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ * @author <a href="mailto:pferraro at redhat.com">Paul Ferraro</a>
  * @version $Revision$
  */
 public class HASingletonSupport extends HAServiceMBeanSupport
@@ -42,9 +44,10 @@
 {
    // Private Data --------------------------------------------------
    
-   private boolean isMasterNode = false;
-   private HASingletonElectionPolicy mElectionPolicyMB = null;
-   private boolean restartOnMerge = true;
+   private final AtomicBoolean master = new AtomicBoolean(false);
+   
+   private volatile HASingletonElectionPolicy mElectionPolicyMB = null;
+   private volatile boolean restartOnMerge = true;
 
    // Constructors --------------------------------------------------
    
@@ -65,7 +68,7 @@
     */
    public boolean isMasterNode()
    {
-      return this.isMasterNode;
+      return this.master.get();
    }
 
    /**
@@ -177,10 +180,12 @@
       }
       
       this.log.debug("partitionTopologyChanged, isElectedNewMaster=" + isElectedNewMaster
-            + ", isMasterNode=" + this.isMasterNode + ", viewID=" + newViewID);
+            + ", isMasterNode=" + this.master + ", viewID=" + newViewID);
 
+      boolean isMaster = this.master.get();
+      
       // if this node is already the master, don't bother electing it again
-      if (isElectedNewMaster && this.isMasterNode)
+      if (isElectedNewMaster && isMaster)
       {
          // JBAS-4229
          if (this.restartOnMerge && merge)
@@ -189,12 +194,12 @@
          }
       }
       // just becoming master
-      else if (isElectedNewMaster && !this.isMasterNode)
+      else if (isElectedNewMaster && !isMaster)
       {
          this.makeThisNodeMaster();
       }
       // transition from master to slave
-      else if (this.isMasterNode == true)
+      else if (isMaster)
       {
          this._stopOldMaster();
       }
@@ -206,16 +211,14 @@
     */
    public void _stopOldMaster()
    {
-      this.log.debug("_stopOldMaster, isMasterNode=" + this.isMasterNode);
+      this.log.debug("_stopOldMaster, isMasterNode=" + this.master);
       
       try
       {
          // since this is a cluster call, all nodes will hear it
          // so if the node is not the master, then ignore
-         if (this.isMasterNode == true)
+         if (this.master.compareAndSet(true, false))
          {
-            this.isMasterNode = false;
-            
             // notify stopping
             this.sendLocalNotification(HASINGLETON_STOPPING_NOTIFICATION);
             
@@ -259,9 +262,9 @@
    
    protected void startNewMaster()
    {
-      this.log.debug("startNewMaster, isMasterNode=" + this.isMasterNode);
+      this.log.debug("startNewMaster, isMasterNode=" + this.master);
       
-      this.isMasterNode = true;
+      this.master.set(true);
       
       // notify starting
       this.sendLocalNotification(HASINGLETON_STARTING_NOTIFICATION);




More information about the jboss-cvs-commits mailing list