[jboss-cvs] JBossAS SVN: r73941 - trunk/cluster/src/main/org/jboss/ha/framework/server.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 2 13:08:16 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-06-02 13:08:16 -0400 (Mon, 02 Jun 2008)
New Revision: 73941

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
Log:
[JBAS-5500] Prevent race condition in channel connect

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2008-06-02 17:06:40 UTC (rev 73940)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2008-06-02 17:08:16 UTC (rev 73941)
@@ -37,6 +37,7 @@
 import java.util.Map;
 import java.util.Vector;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -142,6 +143,13 @@
    
    private class ChannelConnectTask implements Runnable
    {
+      private final CountDownLatch latch;
+      
+      private ChannelConnectTask(CountDownLatch latch)
+      {
+         this.latch = latch;
+      }
+      
       public void run()
       {
          try
@@ -155,6 +163,10 @@
                connectException = e;
             }
          }
+         finally
+         {
+            latch.countDown();
+         }
       }
    }
 
@@ -326,24 +338,34 @@
       dispatcher.setRequestMarshaller(new RequestMarshallerImpl());
       dispatcher.setResponseMarshaller(new ResponseMarshallerImpl());
       
+      // Clear any old connectException
+      connectException = null;
+      CountDownLatch connectLatch = new CountDownLatch(1);
+      
       if (threadPool == null)
       {
          channel.connect(getPartitionName());
+         connectLatch.countDown();
       }
       else
       {
          // Do the channel connect in another thread while this
          // thread starts the cache and does that channel connect
-         ChannelConnectTask task = new ChannelConnectTask();
+         ChannelConnectTask task = new ChannelConnectTask(connectLatch);
          threadPool.run(task);
       }
       
       cache.start();
       
       try
-      {
+      {         
+         // This will block waiting for any async channel connect above
+         connectLatch.await();
+         
+         if (connectException != null)
+            throw connectException;
+         
          log.debug("Get current members");
-         // This will block waiting for any async channel connect above
          waitForView();     
          
          // get current JG group properties         




More information about the jboss-cvs-commits mailing list