JBoss Remoting SVN: r3735 - remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-23 05:00:39 -0400 (Sun, 23 Mar 2008)
New Revision: 3735
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
Log:
BREM-937: ControlConnectionThread.run() calls SocketServerInvoker.processInvocation().
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2008-03-23 08:59:30 UTC (rev 3734)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2008-03-23 09:00:39 UTC (rev 3735)
@@ -832,33 +832,15 @@
return;
}
- synchronized (clientpool)
- {
- if(clientpool.size() < maxPoolSize)
- {
- Thread thread = null;
- try
- {
- thread = new ServerThread(socket, BisocketServerInvoker.this,
- clientpool, threadpool,
- getTimeout(), serverSocketClass);
- thread.start();
- if (log.isDebugEnabled())
- log.debug("created: " + thread);
- }
- catch (Exception e)
- {
- log.error("Unable to create new ServerThread: " + e.getMessage());
- e.printStackTrace();
- }
-
- synchronized (threadpool)
- {
- threadpool.add(thread);
- }
- }
+ try
+ {
+ processInvocation(socket);
}
+ catch (Exception e)
+ {
+ log.error("Unable to create new ServerThread: " + e.getMessage(), e);
+ }
}
}
}
17 years, 7 months
JBoss Remoting SVN: r3734 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-03-23 04:59:30 -0400 (Sun, 23 Mar 2008)
New Revision: 3734
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerLocator.java
Log:
JBREM-915: resolveHost() checks for host == null.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerLocator.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerLocator.java 2008-03-22 06:50:06 UTC (rev 3733)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerLocator.java 2008-03-23 08:59:30 UTC (rev 3734)
@@ -330,8 +330,12 @@
private static final String resolveHost(String host)
{
- if(host.indexOf("0.0.0.0") != -1)
+ if (host == null)
{
+ host = fixRemoteAddress(host);
+ }
+ else if(host.indexOf("0.0.0.0") != -1)
+ {
if(System.getProperty(SERVER_BIND_ADDRESS, "0.0.0.0").equals("0.0.0.0"))
{
host = fixRemoteAddress(host);
@@ -341,7 +345,7 @@
host = host.replaceAll("0\\.0\\.0\\.0", System.getProperty(SERVER_BIND_ADDRESS));
}
}
- return host;
+ return host;
}
private static String fixRemoteAddress(String address)
17 years, 7 months
JBoss Remoting SVN: r3733 - remoting2/branches/2.x.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-03-22 02:50:06 -0400 (Sat, 22 Mar 2008)
New Revision: 3733
Modified:
remoting2/branches/2.x/test.policy
Log:
One more permission
Modified: remoting2/branches/2.x/test.policy
===================================================================
--- remoting2/branches/2.x/test.policy 2008-03-21 22:19:53 UTC (rev 3732)
+++ remoting2/branches/2.x/test.policy 2008-03-22 06:50:06 UTC (rev 3733)
@@ -120,6 +120,7 @@
permission javax.management.MBeanPermission "org.jboss.remoting.detection.multicast.MulticastDetector#-[remoting:type=JNDIDetector]", "registerMBean, queryMBeans, isInstanceOf";
permission javax.management.MBeanPermission "org.jboss.remoting.detection.multicast.MulticastDetector#-[remoting:type=MulticastDetector]", "registerMBean, queryMBeans, isInstanceOf";
permission javax.management.MBeanPermission "org.jboss.remoting.detection.multicast.MulticastDetector#-[remoting:type=MulticastDetector]", "registerMBean, queryMBeans, isInstanceOf";
+ permission javax.management.MBeanPermission "org.jboss.remoting.security.SSLServerSocketFactoryService#-[jboss:type=serversocketfactory]", "registerMBean, queryMBeans, isInstanceOf";
permission javax.management.MBeanPermission "org.jboss.test.remoting.transport.config.FactoryConfigTestCaseParent$SelfIdentifyingServerSocketFactory#-[jboss:type=serversocketfactory]", "registerMBean, queryMBeans, isInstanceOf";
permission java.lang.RuntimePermission "enableContextClassLoaderOverride";
permission java.lang.RuntimePermission "createClassLoader";
17 years, 7 months
JBoss Remoting SVN: r3732 - remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-03-21 18:19:53 -0400 (Fri, 21 Mar 2008)
New Revision: 3732
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
Log:
Sanity check before returning a user session
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-03-21 22:19:28 UTC (rev 3731)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-03-21 22:19:53 UTC (rev 3732)
@@ -98,7 +98,12 @@
}
UserSession getUserSession() {
- return userSession;
+ state.requireHold(State.UP);
+ try {
+ return userSession;
+ } finally {
+ state.release();
+ }
}
// Initializers
17 years, 7 months
JBoss Remoting SVN: r3731 - remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-03-21 18:19:28 -0400 (Fri, 21 Mar 2008)
New Revision: 3731
Modified:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java
Log:
allow proper downgrading
Modified: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java 2008-03-21 22:13:09 UTC (rev 3730)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java 2008-03-21 22:19:28 UTC (rev 3731)
@@ -143,6 +143,11 @@
incLocalShrdCount();
return;
}
+ if (getLocalExclCount() > 0) {
+ sharedHolderCount++;
+ incLocalShrdCount();
+ return;
+ }
synchronized (lock) {
boolean intr = false;
try {
17 years, 7 months
JBoss Remoting SVN: r3730 - in remoting3/trunk: jrpp/src/main/java/org/jboss/cx/remoting/jrpp and 2 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-03-21 18:13:09 -0400 (Fri, 21 Mar 2008)
New Revision: 3730
Added:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/State.java
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundContext.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundContext.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AtomicStateMachine.java
Log:
Enhance atomic state machine to use new lock, and detect invalid transitions
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreEndpoint.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -5,6 +5,7 @@
import java.util.List;
import java.util.Set;
import java.util.Iterator;
+import java.util.EnumSet;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
import org.jboss.cx.remoting.Endpoint;
@@ -49,10 +50,21 @@
Logger.getLogger("org.jboss.cx.remoting").info("JBoss Remoting version %s", Version.VERSION);
}
- private enum State {
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
INITIAL,
UP,
- DOWN,
+ DOWN;
+
+ public boolean isReachable(final State dest) {
+ switch (this) {
+ case INITIAL:
+ return dest != INITIAL;
+ case UP:
+ return dest == DOWN;
+ default:
+ return false;
+ }
+ }
}
public CoreEndpoint(final String name, final RequestListener<?, ?> rootListener) {
@@ -158,6 +170,12 @@
}
public Session openSession(final URI uri, final AttributeMap attributeMap) throws RemotingException {
+ if (uri == null) {
+ throw new NullPointerException("uri is null");
+ }
+ if (attributeMap == null) {
+ throw new NullPointerException("attributeMap is null");
+ }
final String scheme = uri.getScheme();
if (scheme == null) {
throw new RemotingException("No scheme on remote endpoint URI");
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundContext.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundContext.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundContext.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -6,6 +6,7 @@
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.log.Logger;
import org.jboss.cx.remoting.util.AtomicStateMachine;
+import org.jboss.cx.remoting.util.State;
import static org.jboss.cx.remoting.util.CollectionUtil.synchronizedHashSet;
import static org.jboss.cx.remoting.util.AtomicStateMachine.start;
@@ -23,11 +24,15 @@
private ContextClient contextClient;
- private enum State {
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
NEW,
UP,
STOPPING,
- DOWN,
+ DOWN;
+
+ public boolean isReachable(final State dest) {
+ return compareTo(dest) < 0;
+ }
}
public CoreInboundContext(final RequestListener<I, O> requestListener, final Executor executor) {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundRequest.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -6,6 +6,7 @@
import org.jboss.cx.remoting.RequestContext;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.util.AtomicStateMachine;
+import org.jboss.cx.remoting.util.State;
import org.jboss.cx.remoting.log.Logger;
import java.util.concurrent.Executor;
import java.util.Set;
@@ -51,11 +52,15 @@
this.executor = executor;
}
- private enum State {
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
INITIAL,
UNSENT,
SENT,
- TERMINATED,
+ TERMINATED;
+
+ public boolean isReachable(final State dest) {
+ return compareTo(dest) < 0;
+ }
}
public void initialize(final RequestClient<O> requestClient) {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreInboundService.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -4,6 +4,7 @@
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.util.AtomicStateMachine;
+import org.jboss.cx.remoting.util.State;
import java.util.concurrent.Executor;
/**
@@ -16,9 +17,13 @@
private final AtomicStateMachine<State> state = start(State.INITIAL);
- private enum State {
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
INITIAL,
- UP,
+ UP;
+
+ public boolean isReachable(final State dest) {
+ return compareTo(dest) < 0;
+ }
}
public CoreInboundService(final RequestListener<I, O> requestListener, final Executor executor) {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundContext.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundContext.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundContext.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -12,6 +12,7 @@
import org.jboss.cx.remoting.core.util.QueueExecutor;
import org.jboss.cx.remoting.util.AtomicStateMachine;
import org.jboss.cx.remoting.util.CollectionUtil;
+import org.jboss.cx.remoting.util.State;
import org.jboss.cx.remoting.log.Logger;
/**
@@ -39,11 +40,15 @@
state.releaseExclusive();
}
- private enum State {
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
INITIAL,
UP,
STOPPING,
- DOWN,
+ DOWN,;
+
+ public boolean isReachable(final State dest) {
+ return compareTo(dest) < 0;
+ }
}
// Getters
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundRequest.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -12,6 +12,7 @@
import org.jboss.cx.remoting.RequestCompletionHandler;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.util.AtomicStateMachine;
+import org.jboss.cx.remoting.util.State;
import org.jboss.cx.remoting.log.Logger;
/**
@@ -53,12 +54,22 @@
return requestClient;
}
- private enum State {
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
WAITING,
DONE,
EXCEPTION,
CANCELLED,
- TERMINATED,
+ TERMINATED,;
+
+ public boolean isReachable(final State dest) {
+ switch (this) {
+ case WAITING:
+ case DONE:
+ return compareTo(dest) < 0;
+ default:
+ return false;
+ }
+ }
}
/**
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreOutboundService.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -5,6 +5,7 @@
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.util.AtomicStateMachine;
+import org.jboss.cx.remoting.util.State;
import org.jboss.cx.remoting.log.Logger;
import java.util.concurrent.Executor;
import java.io.Serializable;
@@ -26,11 +27,15 @@
this.executor = executor;
}
- private enum State {
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
INITIAL,
UP,
CLOSING,
- DOWN
+ DOWN;
+
+ public boolean isReachable(final State dest) {
+ return compareTo(dest) < 0;
+ }
}
// Getters
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/CoreSession.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -28,6 +28,7 @@
import org.jboss.cx.remoting.spi.ByteMessageOutput;
import org.jboss.cx.remoting.spi.ObjectMessageInput;
import org.jboss.cx.remoting.util.CollectionUtil;
+import org.jboss.cx.remoting.util.State;
import org.jboss.cx.remoting.spi.ObjectMessageOutput;
import org.jboss.cx.remoting.log.Logger;
import org.jboss.cx.remoting.spi.protocol.ContextIdentifier;
@@ -135,11 +136,16 @@
if (protocolHandler == null) {
throw new NullPointerException("protocolHandler is null");
}
+ boolean ok = false;
state.requireTransitionExclusive(State.NEW, State.CONNECTING);
try {
doInitialize(protocolHandler, rootContext);
+ ok = true;
} finally {
state.releaseExclusive();
+ if (! ok) {
+ state.transition(State.DOWN);
+ }
}
}
@@ -147,11 +153,16 @@
if (protocolHandlerFactory == null) {
throw new NullPointerException("protocolHandlerFactory is null");
}
+ boolean ok = false;
state.requireTransitionExclusive(State.NEW, State.CONNECTING);
try {
doInitialize(protocolHandlerFactory.createHandler(protocolContext, remoteUri, attributeMap), rootContext);
+ ok = true;
} finally {
state.releaseExclusive();
+ if (! ok) {
+ state.transition(State.DOWN);
+ }
}
}
@@ -165,12 +176,16 @@
// State mgmt
- private enum State {
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
NEW,
CONNECTING,
UP,
STOPPING,
- DOWN,
+ DOWN;
+
+ public boolean isReachable(final State dest) {
+ return compareTo(dest) < 0;
+ }
}
// Context mgmt
Modified: remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java
===================================================================
--- remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/jrpp/src/main/java/org/jboss/cx/remoting/jrpp/JrppConnection.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -9,6 +9,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.EnumMap;
+import java.util.EnumSet;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.mina.common.AttributeKey;
@@ -26,6 +28,7 @@
import org.jboss.cx.remoting.spi.ObjectMessageInput;
import org.jboss.cx.remoting.util.CollectionUtil;
import org.jboss.cx.remoting.util.WeakHashSet;
+import org.jboss.cx.remoting.util.State;
import org.jboss.cx.remoting.jrpp.id.JrppContextIdentifier;
import org.jboss.cx.remoting.jrpp.id.JrppRequestIdentifier;
import org.jboss.cx.remoting.jrpp.id.JrppServiceIdentifier;
@@ -100,7 +103,7 @@
return connection.getIoHandler();
}
- private enum State {
+ private enum State implements org.jboss.cx.remoting.util.State<State> {
/** Initial state - unconnected */
NEW,
/** Client side, waiting to receive protocol version info */
@@ -118,7 +121,12 @@
/** Session is shutting down or closed */
CLOSED,
/** Session failed to connect */
- FAILED,
+ FAILED;
+
+ public boolean isReachable(final State dest) {
+ // not perfect but close enough for now
+ return compareTo(dest) < 0;
+ }
}
private final AtomicStateMachine<State> state = AtomicStateMachine.start(State.NEW);
@@ -351,8 +359,9 @@
}
public void waitForUp() throws IOException {
+
while (! state.in(State.UP, State.FAILED)) {
- state.waitForAny();
+// state.waitForAny(); todo
}
if (state.in(State.FAILED)) {
throw failureReason;
Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
--- remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -6,6 +6,7 @@
import org.jboss.cx.remoting.log.Logger;
import org.jboss.cx.remoting.core.CoreEndpoint;
import org.jboss.cx.remoting.core.protocol.LocalProtocolHandlerFactory;
+import org.jboss.cx.remoting.jrpp.JrppProtocolSupport;
/**
*
@@ -22,6 +23,11 @@
try {
final Endpoint userEndpoint = coreEndpoint.getUserEndpoint();
LocalProtocolHandlerFactory.addTo(userEndpoint);
+ final JrppProtocolSupport jrppProtocolSupport = new JrppProtocolSupport();
+ jrppProtocolSupport.setEndpoint(userEndpoint);
+ jrppProtocolSupport.setExecutor(executorService);
+ jrppProtocolSupport.create();
+ jrppProtocolSupport.start();
userEndpoint.addCloseHandler(new CloseHandler<Endpoint>() {
public void handleClose(final Endpoint closed) {
executorService.shutdown();
Modified: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AtomicStateMachine.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AtomicStateMachine.java 2008-03-21 22:12:18 UTC (rev 3729)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AtomicStateMachine.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -10,16 +10,13 @@
/**
*
*/
-public final class AtomicStateMachine<T extends Enum<T>> {
+public final class AtomicStateMachine<T extends Enum<T> & State<T>> {
// protected by {@code lock}
private T state;
- private final ReadWriteLock lock = new ReentrantReadWriteLock();
- private final Lock readLock = lock.readLock();
- private final Lock writeLock = lock.writeLock();
- private final Condition cond = writeLock.newCondition();
+ private final StateLock stateLock = new StateLock();
- public static <T extends Enum<T>> AtomicStateMachine<T> start(final T initialState) {
+ public static <T extends Enum<T> & State<T>> AtomicStateMachine<T> start(final T initialState) {
return new AtomicStateMachine<T>(initialState);
}
@@ -31,19 +28,18 @@
}
public boolean transition(final T state) {
- writeLock.lock();
+ if (state == null) {
+ throw new NullPointerException("state is null");
+ }
+ stateLock.lockExclusive();
try {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
if (this.state == state) {
return false;
}
this.state = state;
- cond.signalAll();
return true;
} finally {
- writeLock.unlock();
+ stateLock.unlockExclusive();
}
}
@@ -67,17 +63,16 @@
if (state == null) {
throw new NullPointerException("state is null");
}
- writeLock.lock();
+ stateLock.lockExclusive();
try {
if (this.state == state) {
return false;
}
this.state = state;
- cond.signalAll();
- readLock.lock();
+ stateLock.lockShared();
return true;
} finally {
- writeLock.unlock();
+ stateLock.unlockExclusive();
}
}
@@ -85,12 +80,11 @@
if (state == null) {
throw new NullPointerException("state is null");
}
- writeLock.lock();
+ stateLock.lockExclusive();
if (this.state == state) {
return false;
}
this.state = state;
- cond.signalAll();
return true;
}
@@ -98,16 +92,16 @@
* Release a held state. Must be called from the same thread that is holding the state.
*/
public void release() {
- readLock.unlock();
+ stateLock.unlockShared();
}
public void releaseExclusive() {
- writeLock.unlock();
+ stateLock.unlockExclusive();
}
public void releaseDowngrade() {
- readLock.lock();
- writeLock.unlock();
+ stateLock.lockShared();
+ stateLock.unlockExclusive();
}
public boolean transition(final T fromState, final T toState) {
@@ -117,16 +111,15 @@
if (toState == null) {
throw new NullPointerException("toState is null");
}
- writeLock.lock();
+ stateLock.lockExclusive();
try {
if (state != fromState) {
return false;
}
state = toState;
- cond.signalAll();
return true;
} finally {
- writeLock.unlock();
+ stateLock.unlockExclusive();
}
}
@@ -137,17 +130,16 @@
if (toState == null) {
throw new NullPointerException("toState is null");
}
- writeLock.lock();
+ stateLock.lockExclusive();
try {
if (state != fromState) {
return false;
}
state = toState;
- cond.signalAll();
- readLock.lock();
+ stateLock.lockShared();
return true;
} finally {
- writeLock.unlock();
+ stateLock.unlockExclusive();
}
}
@@ -158,19 +150,18 @@
if (toState == null) {
throw new NullPointerException("toState is null");
}
- writeLock.lock();
+ stateLock.lockExclusive();
boolean ok = false;
try {
if (state != fromState) {
return false;
}
state = toState;
- cond.signalAll();
ok = true;
return true;
} finally {
if (! ok) {
- writeLock.unlock();
+ stateLock.unlockExclusive();
}
}
}
@@ -205,348 +196,151 @@
}
}
-
public void waitInterruptiblyFor(final T state) throws InterruptedException {
- if (in(state)) {
- return;
- }
- writeLock.lockInterruptibly();
- try {
- while (this.state != state) {
- cond.await();
+ stateLock.lockShared();
+ while (this.state != state) {
+ if (this.state.isReachable(state)) {
+ stateLock.yieldShared();
+ } else try {
+ throw new IllegalStateException("Destination state " + state + " is unreachable from " + this.state);
+ } finally {
+ stateLock.unlockShared();
}
- } finally {
- writeLock.unlock();
}
+ stateLock.unlockShared();
+ return;
}
public void waitFor(final T state) {
- if (in(state)) {
- return;
+ if (state == null) {
+ throw new NullPointerException("state is null");
}
- writeLock.lock();
- try {
- while (this.state != state) {
- cond.awaitUninterruptibly();
+ stateLock.lockShared();
+ while (this.state != state) {
+ if (this.state.isReachable(state)) {
+ stateLock.yieldShared();
+ } else try {
+ throw new IllegalStateException("Destination state " + state + " is unreachable from " + this.state);
+ } finally {
+ stateLock.unlockShared();
}
- } finally {
- writeLock.unlock();
}
+ stateLock.unlockShared();
+ return;
}
public void waitForHold(final T state) {
- if (inHold(state)) {
- return;
+ if (state == null) {
+ throw new NullPointerException("state is null");
}
- writeLock.lock();
- try {
- while (this.state != state) {
- cond.awaitUninterruptibly();
+ stateLock.lockShared();
+ while (this.state != state) {
+ if (this.state.isReachable(state)) {
+ stateLock.yieldShared();
+ } else try {
+ throw new IllegalStateException("Destination state " + state + " is unreachable from " + this.state);
+ } finally {
+ stateLock.unlockShared();
}
- readLock.lock();
- } finally {
- writeLock.unlock();
}
+ return;
}
- public void waitForAny() {
- writeLock.lock();
- try {
- waitForNot(state);
- } finally {
- writeLock.unlock();
- }
- }
-
- public boolean waitInterruptiblyFor(final T state, final long timeout, final TimeUnit timeUnit) throws InterruptedException {
- if (in(state)) {
- return true;
- }
- final long timeoutMillis = timeUnit.toMillis(timeout);
- final long startTime = System.currentTimeMillis();
- final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
- final Date deadline = new Date(endTime);
- writeLock.lockInterruptibly();
- try {
- while (this.state != state) {
- if (! cond.awaitUntil(deadline)) {
- return false;
- }
- }
- return true;
- } finally {
- writeLock.unlock();
- }
- }
-
- public T waitInterruptiblyForNot(final T state) throws InterruptedException {
- final T current = getState();
- if (current != state) {
- return current;
- }
- writeLock.lockInterruptibly();
- try {
- while (this.state == state) {
- cond.await();
- }
- return this.state;
- } finally {
- writeLock.unlock();
- }
- }
-
public T waitInterruptiblyForNotHold(final T state) throws InterruptedException {
- final T current = getStateHold();
- if (current != state) {
- return current;
+ if (state == null) {
+ throw new NullPointerException("state is null");
}
- release();
- writeLock.lockInterruptibly();
- try {
- while (this.state == state) {
- cond.await();
- }
- readLock.lockInterruptibly();
- return this.state;
- } finally {
- writeLock.unlock();
+ stateLock.lockShared();
+ while (this.state == state) {
+ stateLock.yieldShared();
}
+ return this.state;
}
public T waitForNot(final T state) {
- final T current = getState();
- if (current != state) {
- return current;
+ if (state == null) {
+ throw new NullPointerException("state is null");
}
- writeLock.lock();
+ stateLock.lockShared();
+ while (this.state == state) {
+ stateLock.yieldShared();
+ }
try {
- while (this.state == state) {
- cond.awaitUninterruptibly();
- }
return this.state;
} finally {
- writeLock.unlock();
+ stateLock.unlockShared();
}
}
public T waitForNotHold(final T state) {
- final T current = getStateHold();
- if (current != state) {
- return current;
+ if (state == null) {
+ throw new NullPointerException("state is null");
}
- release();
- writeLock.lock();
- try {
- while (this.state == state) {
- cond.awaitUninterruptibly();
- }
- readLock.lock();
- return this.state;
- } finally {
- writeLock.unlock();
+ stateLock.lockShared();
+ while (this.state == state) {
+ stateLock.yieldShared();
}
+ return this.state;
}
+ @Deprecated
public T waitForNotExclusive(final T state) {
- writeLock.lock();
+ if (state == null) {
+ throw new NullPointerException("state is null");
+ }
+ stateLock.lockExclusive();
while (this.state == state) {
- cond.awaitUninterruptibly();
+ stateLock.awaitExclusive();
}
return this.state;
}
- public T waitInterruptiblyForNot(final T state, final long timeout, final TimeUnit timeUnit) throws InterruptedException {
- final T current = getState();
- if (current != state) {
- return current;
- }
- final long timeoutMillis = timeUnit.toMillis(timeout);
- final long startTime = System.currentTimeMillis();
- final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
- final Date deadLine = new Date(endTime);
- writeLock.lockInterruptibly();
- try {
- while (this.state == state) {
- cond.awaitUntil(deadLine);
- }
- return this.state;
- } finally {
- writeLock.unlock();
- }
- }
-
-
public T waitInterruptiblyForNotHold(final T state, final long timeout, final TimeUnit timeUnit) throws InterruptedException {
- final T current = getStateHold();
- if (current != state) {
- return current;
- }
- release();
- final long timeoutMillis = timeUnit.toMillis(timeout);
- final long startTime = System.currentTimeMillis();
- final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
- final Date deadLine = new Date(endTime);
- boolean waiting = true;
- writeLock.lockInterruptibly();
- try {
- while (this.state == state) {
- if (waiting) {
- waiting = cond.awaitUntil(deadLine);
- } else {
- break;
- }
- }
- readLock.lockInterruptibly();
- return this.state;
- } finally {
- writeLock.unlock();
- }
+ throw new RuntimeException("TODO - Implement");
}
public T waitForNotHold(final T state, final long timeout, final TimeUnit timeUnit) {
- final T current = getStateHold();
- if (current != state) {
- return current;
- }
- release();
- final long timeoutMillis = timeUnit.toMillis(timeout);
- final long startTime = System.currentTimeMillis();
- final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
- final Date deadLine = new Date(endTime);
- boolean intr = false;
- try {
- boolean waiting = true;
- writeLock.lock();
- try {
- while (this.state == state) {
- if (waiting) {
- try {
- waiting = cond.awaitUntil(deadLine);
- } catch (InterruptedException e) {
- intr = Thread.currentThread().isInterrupted();
- }
- } else {
- break;
- }
- }
- readLock.lock();
- return this.state;
- } finally {
- writeLock.unlock();
- }
- } finally {
- if (intr) Thread.currentThread().interrupt();
- }
+ throw new RuntimeException("TODO - Implement");
}
- public T waitForNot(final T state, final long timeout, final TimeUnit timeUnit) {
- final T current = getState();
- if (current != state) {
- return current;
- }
- final long timeoutMillis = timeUnit.toMillis(timeout);
- final long startTime = System.currentTimeMillis();
- final long endTime = startTime + timeoutMillis < 0 ? Long.MAX_VALUE : startTime + timeoutMillis;
- final Date deadLine = new Date(endTime);
- boolean intr = false;
- writeLock.lock();
- try {
- while (this.state == state) {
- try {
- if (! cond.awaitUntil(deadLine)) {
- break;
- }
- } catch (InterruptedException e) {
- intr = true;
- }
- }
- return this.state;
- } finally {
- if (intr) {
- Thread.currentThread().interrupt();
- }
- }
- }
-
public T getState() {
- readLock.lock();
+ stateLock.lockShared();
try {
return state;
} finally {
- readLock.unlock();
+ stateLock.unlockShared();
}
}
public T getStateHold() {
- readLock.lock();
+ stateLock.lockShared();
return state;
}
public T getStateExclusive() {
- writeLock.lock();
+ stateLock.lockExclusive();
return state;
}
- public boolean inHoldExclusive(T state) {
- writeLock.lock();
- boolean ok = false;
- try {
- ok = this.state == state;
- return ok;
- } finally {
- if (! ok) {
- writeLock.unlock();
- }
- }
- }
-
- public boolean inHoldExclusive(T... states) {
- if (states == null) {
- throw new NullPointerException("states is null");
- }
- writeLock.lock();
- for (T state : states) {
- if (this.state == state) {
- return true;
- }
- }
- writeLock.unlock();
- return false;
- }
-
public boolean inHold(T state) {
- readLock.lock();
+ stateLock.lockShared();
boolean ok = false;
try {
ok = this.state == state;
return ok;
} finally {
if (! ok) {
- readLock.unlock();
+ stateLock.unlockShared();
}
}
}
- public boolean inHold(T... states) {
- if (states == null) {
- throw new NullPointerException("states is null");
- }
- readLock.lock();
- for (T state : states) {
- if (this.state == state) {
- return true;
- }
- }
- readLock.unlock();
- return false;
- }
-
public boolean in(T state) {
- readLock.lock();
+ stateLock.lockShared();
try {
return this.state == state;
} finally {
- readLock.unlock();
+ stateLock.unlockShared();
}
}
@@ -554,7 +348,7 @@
if (states == null) {
throw new NullPointerException("states is null");
}
- readLock.lock();
+ stateLock.lockShared();
try {
for (T state : states) {
if (this.state == state) {
@@ -563,62 +357,32 @@
}
return false;
} finally {
- readLock.unlock();
+ stateLock.unlockShared();
}
}
- public void require(T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- readLock.lock();
- try {
- if (this.state != state) {
- throw new IllegalStateException("Invalid state (expected " + state + ", but current state is " + this.state + ")");
- }
- } finally {
- readLock.unlock();
- }
- }
-
public void requireHold(T state) {
if (state == null) {
throw new NullPointerException("state is null");
}
boolean ok = false;
- readLock.lock();
+ stateLock.lockShared();
try {
if (this.state != state) {
throw new IllegalStateException("Invalid state (expected " + state + ", but current state is " + this.state + ")");
}
ok = true;
} finally {
- if (! ok) readLock.unlock();
+ if (! ok) stateLock.unlockShared();
}
}
- public void requireExclusive(T state) {
- if (state == null) {
- throw new NullPointerException("state is null");
- }
- boolean ok = false;
- writeLock.lock();
- try {
- if (this.state != state) {
- throw new IllegalStateException("Invalid state (expected " + state + ", but current state is " + this.state + ")");
- }
- ok = true;
- } finally {
- if (! ok) writeLock.unlock();
- }
- }
-
public String toString() {
- readLock.lock();
+ stateLock.lockShared();
try {
return "State = " + state;
} finally {
- readLock.unlock();
+ stateLock.unlockShared();
}
}
}
Added: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/State.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/State.java (rev 0)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/State.java 2008-03-21 22:13:09 UTC (rev 3730)
@@ -0,0 +1,8 @@
+package org.jboss.cx.remoting.util;
+
+/**
+ *
+ */
+public interface State<T extends Enum<T> & State<T>> {
+ boolean isReachable(T dest);
+}
17 years, 7 months
JBoss Remoting SVN: r3729 - remoting2/branches/2.x.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-03-21 18:12:18 -0400 (Fri, 21 Mar 2008)
New Revision: 3729
Modified:
remoting2/branches/2.x/test.policy
Log:
A few more permissions for the test suite
Modified: remoting2/branches/2.x/test.policy
===================================================================
--- remoting2/branches/2.x/test.policy 2008-03-21 22:09:53 UTC (rev 3728)
+++ remoting2/branches/2.x/test.policy 2008-03-21 22:12:18 UTC (rev 3729)
@@ -112,13 +112,15 @@
// Used by the test suite itself
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
permission javax.management.MBeanServerPermission "createMBeanServer, findMBeanServer";
- permission javax.management.MBeanPermission "org.jboss.remoting.transport.Connector#-[jboss.remoting:id=1,transport=socket,type=Connector]", "registerMBean, unregisterMBean, queryMBeans, isInstanceOf";
+ permission javax.management.MBeanTrustPermission "register";
+ permission javax.management.MBeanPermission "org.jboss.remoting.transport.Connector#-[jboss.remoting:*,transport=socket,type=Connector]", "registerMBean, unregisterMBean, queryMBeans, isInstanceOf";
permission javax.management.MBeanPermission "org.jboss.remoting.transport.Connector#-[jboss.remoting:transport=socket,type=Connector]", "registerMBean, unregisterMBean, queryMBeans, isInstanceOf";
permission javax.management.MBeanPermission "org.jboss.test.remoting.detection.metadata.MetadataTestCase$TestNetworkRegistry#-[remoting:type=NetworkRegistry]", "registerMBean, unregisterMBean, queryMBeans, isInstanceOf";
permission javax.management.MBeanPermission "org.jboss.remoting.network.NetworkRegistry#-[remoting:type=NetworkRegistry]", "registerMBean, unregisterMBean, queryMBeans, isInstanceOf";
- permission javax.management.MBeanPermission "org.jboss.remoting.detection.multicast.MulticastDetector#-[remoting:type=JNDIDetector]", "queryMBeans, isInstanceOf";
- permission javax.management.MBeanPermission "org.jboss.remoting.detection.multicast.MulticastDetector#-[remoting:type=MulticastDetector]", "queryMBeans, isInstanceOf";
- permission javax.management.MBeanPermission "org.jboss.remoting.detection.multicast.MulticastDetector#-[remoting:type=MultiplexDetector]", "queryMBeans, isInstanceOf";
+ permission javax.management.MBeanPermission "org.jboss.remoting.detection.multicast.MulticastDetector#-[remoting:type=JNDIDetector]", "registerMBean, queryMBeans, isInstanceOf";
+ permission javax.management.MBeanPermission "org.jboss.remoting.detection.multicast.MulticastDetector#-[remoting:type=MulticastDetector]", "registerMBean, queryMBeans, isInstanceOf";
+ permission javax.management.MBeanPermission "org.jboss.remoting.detection.multicast.MulticastDetector#-[remoting:type=MulticastDetector]", "registerMBean, queryMBeans, isInstanceOf";
+ permission javax.management.MBeanPermission "org.jboss.test.remoting.transport.config.FactoryConfigTestCaseParent$SelfIdentifyingServerSocketFactory#-[jboss:type=serversocketfactory]", "registerMBean, queryMBeans, isInstanceOf";
permission java.lang.RuntimePermission "enableContextClassLoaderOverride";
permission java.lang.RuntimePermission "createClassLoader";
permission java.lang.RuntimePermission "getClassLoader";
17 years, 7 months
JBoss Remoting SVN: r3728 - remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-03-21 18:09:53 -0400 (Fri, 21 Mar 2008)
New Revision: 3728
Modified:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java
Log:
Add enumMap method
Modified: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java 2008-03-21 22:06:51 UTC (rev 3727)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java 2008-03-21 22:09:53 UTC (rev 3728)
@@ -14,6 +14,7 @@
import java.util.Collections;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.EnumMap;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
@@ -26,6 +27,10 @@
private CollectionUtil() {
}
+ public static <K extends Enum<K>, V> EnumMap<K, V> enumMap(Class<K> keyType) {
+ return new EnumMap<K, V>(keyType);
+ }
+
/**
* Create a concurrent map instance.
*
17 years, 7 months
JBoss Remoting SVN: r3727 - remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-03-21 18:06:51 -0400 (Fri, 21 Mar 2008)
New Revision: 3727
Added:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java
Log:
New type of lock
Added: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java (rev 0)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/StateLock.java 2008-03-21 22:06:51 UTC (rev 3727)
@@ -0,0 +1,257 @@
+package org.jboss.cx.remoting.util;
+
+/**
+ * Lock rules:
+ *
+ * Shared acquire:
+ * - Unlocked
+ * or
+ * - Shared-locked
+ *
+ * Exclusive acquire:
+ * - Unlocked
+ * or
+ * - All previously waiting readers have had a chance to lock
+ */
+public final class StateLock {
+ private static final class ReaderToken {
+ private int count;
+
+ private ReaderToken(final int count) {
+ this.count = count;
+ }
+ }
+
+ private static final String LOCK_NOT_HELD = "Unlock when lock isn't held";
+
+ private final Object lock = new Object();
+ /**
+ * A counter for the readers that will be granted after the next exclusive lock is released.
+ *
+ * @protectedby {@code lock}
+ */
+ private ReaderToken nextReaderToken = new ReaderToken(0);
+ /**
+ * A counter for the readers that must be granted before an exclusive lock can be granted.
+ *
+ * @protectedby {@code lock}
+ */
+ private ReaderToken currentReaderToken = new ReaderToken(0);
+
+ // @protectedby {@code lock} (writes only)
+ private volatile int sharedHolderCount = 0;
+ // @protectedby {@code lock} (writes only)
+ private volatile boolean exclusive = false;
+
+ private final ThreadLocal<LockState> localLockState = new ThreadLocal<LockState>();
+
+ private void incLocalExclCount() {
+ final LockState lockState = localLockState.get();
+ if (lockState == null) {
+ localLockState.set(new LockState(1, 0));
+ } else {
+ lockState.exclLevel++;
+ }
+ }
+
+ private boolean decLocalExclCount() {
+ final LockState lockState = localLockState.get();
+ if (lockState == null || lockState.exclLevel == 0) {
+ throw new IllegalMonitorStateException(LOCK_NOT_HELD);
+ }
+ return --lockState.exclLevel == 0;
+ }
+
+ private int getLocalExclCount() {
+ final LockState lockState = localLockState.get();
+ if (lockState == null) {
+ return 0;
+ } else {
+ return lockState.exclLevel;
+ }
+ }
+
+ private void incLocalShrdCount() {
+ final LockState lockState = localLockState.get();
+ if (lockState == null) {
+ localLockState.set(new LockState(0, 1));
+ } else {
+ lockState.shrdLevel++;
+ }
+ }
+
+ private boolean decLocalShrdCount() {
+ final LockState lockState = localLockState.get();
+ if (lockState == null || lockState.shrdLevel == 0) {
+ throw new IllegalMonitorStateException(LOCK_NOT_HELD);
+ }
+ return --lockState.shrdLevel == 0;
+ }
+
+ private int getLocalShrdCount() {
+ final LockState lockState = localLockState.get();
+ if (lockState == null) {
+ return 0;
+ } else {
+ return lockState.shrdLevel;
+ }
+ }
+
+ public void lockExclusive() {
+ if (getLocalExclCount() > 0) {
+ incLocalExclCount();
+ return;
+ }
+ if (getLocalShrdCount() > 0) {
+ throw new IllegalMonitorStateException("Lock exclusive while shared lock is held");
+ }
+ synchronized (lock) {
+ boolean intr = false;
+ try {
+ while (exclusive || currentReaderToken.count > 0 || sharedHolderCount > 0) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ }
+ exclusive = true;
+ incLocalExclCount();
+ return;
+ } finally {
+ if (intr) Thread.currentThread().interrupt();
+ }
+ }
+ }
+
+ public void unlockExclusive() {
+ if (! exclusive) {
+ throw new IllegalMonitorStateException(LOCK_NOT_HELD);
+ }
+ if (decLocalExclCount()) {
+ synchronized (lock) {
+ exclusive = false;
+ currentReaderToken = nextReaderToken;
+ nextReaderToken = new ReaderToken(0);
+ lock.notifyAll();
+ }
+ }
+ }
+
+ public void lockShared() {
+ if (getLocalShrdCount() > 0) {
+ incLocalShrdCount();
+ return;
+ }
+ synchronized (lock) {
+ boolean intr = false;
+ try {
+ final ReaderToken token = currentReaderToken;
+ if (exclusive) {
+ token.count++;
+ while (exclusive) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ }
+ token.count--;
+ }
+ sharedHolderCount++;
+ incLocalShrdCount();
+ return;
+ } finally {
+ if (intr) Thread.currentThread().interrupt();
+ }
+ }
+ }
+
+ public void unlockShared() {
+ if (decLocalShrdCount()) {
+ synchronized (lock) {
+ if (--sharedHolderCount == 0) {
+ lock.notifyAll();
+ }
+ }
+ }
+ }
+
+ public void yieldShared() {
+ if (getLocalShrdCount() == 1 && getLocalExclCount() == 0) {
+ synchronized (lock) {
+ boolean intr = false;
+ try {
+ final ReaderToken token = nextReaderToken;
+ token.count++;
+ sharedHolderCount--;
+ while (! exclusive) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ }
+ while (exclusive) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ }
+ token.count--;
+ sharedHolderCount++;
+ } finally {
+ if (intr) Thread.currentThread().interrupt();
+ }
+ }
+ } else {
+ throw new IllegalMonitorStateException("May only hold one shared lock to invoke yieldShared()");
+ }
+ }
+
+ public void awaitExclusive() {
+ if (getLocalExclCount() == 0) {
+ throw new IllegalMonitorStateException("await() called when lock not held");
+ }
+ synchronized (lock) {
+ boolean intr = false;
+ try {
+ exclusive = false;
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ while (exclusive || currentReaderToken.count > 0 || sharedHolderCount > 0) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ intr = true;
+ }
+ }
+ exclusive = true;
+ incLocalExclCount();
+ return;
+ } finally {
+ if (intr) Thread.currentThread().interrupt();
+ }
+ }
+ }
+
+ public void signal() {
+ synchronized (lock) {
+ lock.notifyAll();
+ }
+ }
+
+ private static final class LockState {
+ private int exclLevel;
+ private int shrdLevel;
+
+ private LockState(final int exclLevel, final int shrdLevel) {
+ this.exclLevel = exclLevel;
+ this.shrdLevel = shrdLevel;
+ }
+ }
+}
17 years, 7 months
JBoss Remoting SVN: r3726 - remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-03-21 13:10:13 -0400 (Fri, 21 Mar 2008)
New Revision: 3726
Modified:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AttributeMap.java
Log:
Add an EMPTY attribute map that is conveniently stored within that interface
Modified: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AttributeMap.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AttributeMap.java 2008-03-21 17:09:43 UTC (rev 3725)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AttributeMap.java 2008-03-21 17:10:13 UTC (rev 3726)
@@ -9,6 +9,11 @@
public interface AttributeMap {
/**
+ * The empty attribute map.
+ */
+ AttributeMap EMPTY = CollectionUtil.emptyAttributeMap();
+
+ /**
* Get a value from the map.
*
* @param key the key
17 years, 7 months