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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 20 23:59:02 EDT 2009


Author: pferraro
Date: 2009-07-20 23:59:02 -0400 (Mon, 20 Jul 2009)
New Revision: 91480

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
Log:
[JBAS-7110] ClusterPartition.ThreadGate can block shutdown of AS

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2009-07-21 03:40:38 UTC (rev 91479)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2009-07-21 03:59:02 UTC (rev 91480)
@@ -41,6 +41,8 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.AbstractQueuedSynchronizer;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -2407,43 +2409,53 @@
     * @author Brian Goetz and Tim Peierls
     */
 
-   private static class ThreadGate {
-       // CONDITION-PREDICATE: opened-since(n) (isOpen || generation>n)
-       private boolean isOpen;
-
-       private int generation;
-
-       public synchronized void close()
-       {
-           this.isOpen = false;
-       }
-
-       public synchronized void open()
-       {
-           ++this.generation;
-           this.isOpen = true;
-           this.notifyAll();
-       }
-
-       // BLOCKS-UNTIL: opened-since(generation on entry)
-       public synchronized void await() throws InterruptedException
-       {
-           int arrivalGeneration = this.generation;
-           while(!this.isOpen && arrivalGeneration == this.generation)
+   private static class ThreadGate
+   {
+      private static final int OPEN = 1;
+      private static final int CLOSED = -1;
+      
+      private static class Sync extends AbstractQueuedSynchronizer
+      {
+         Sync(int state)
          {
-            this.wait();
+            this.setState(state);
          }
-       }
-       
-       // BLOCKS-UNTIL: opened-since(generation on entry)
-       public synchronized void await(long timeout) throws InterruptedException
-       {
-           int arrivalGeneration = this.generation;
-           while(!this.isOpen && arrivalGeneration == this.generation)
+         
+         @Override
+         protected int tryAcquireShared(int ingored)
          {
-            this.wait(timeout);
+            return this.getState();
          }
-       }
+
+         @Override
+         protected boolean tryReleaseShared(int state)
+         {
+            this.setState(state);
+            return true;
+         }
+      }
+
+      private final Sync sync = new Sync(CLOSED);
+      
+      public void open()
+      {
+         this.sync.releaseShared(OPEN);
+      }
+      
+      public void close()
+      {
+         this.sync.releaseShared(CLOSED);
+      }
+      
+      public void await() throws InterruptedException
+      {
+         this.sync.acquireSharedInterruptibly(0);
+      }
+      
+      public boolean await(long timeout) throws InterruptedException
+      {
+         return this.sync.tryAcquireSharedNanos(0, TimeUnit.MILLISECONDS.toNanos(timeout));
+      }
    }
    
    private void setupLoggers(String partitionName)




More information about the jboss-cvs-commits mailing list