[jboss-cvs] JBossAS SVN: r91481 - branches/JBPAPP_5_0/cluster/src/main/org/jboss/ha/framework/server.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 21 00:14:09 EDT 2009
Author: pferraro
Date: 2009-07-21 00:14:08 -0400 (Tue, 21 Jul 2009)
New Revision: 91481
Modified:
branches/JBPAPP_5_0/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
Log:
[JBAS-7110] ClusterPartition.ThreadGate can block shutdown of AS
Modified: branches/JBPAPP_5_0/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
===================================================================
--- branches/JBPAPP_5_0/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java 2009-07-21 03:59:02 UTC (rev 91480)
+++ branches/JBPAPP_5_0/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java 2009-07-21 04:14:08 UTC (rev 91481)
@@ -40,6 +40,8 @@
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.AbstractQueuedSynchronizer;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -2333,54 +2335,58 @@
}
}
+
/**
- * Copyright (c) 2005 Brian Goetz and Tim Peierls
- * Released under the Creative Commons Attribution License
- * (http://creativecommons.org/licenses/by/2.5)
- * Official home: http://www.jcip.net
- *
- * ThreadGate <p/> Recloseable gate using wait and notifyAll
- *
- * @author Brian Goetz and Tim Peierls
+ * Adapted from org.jboss.cache.util.concurrent.ReclosableLatch.
+ * @author Manik Surtani
*/
-
- 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