[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...
Ron Sigal
ron_sigal at yahoo.com
Fri Aug 17 20:57:12 EDT 2007
User: rsigal
Date: 07/08/17 20:57:12
Modified: src/main/org/jboss/remoting Tag:
remoting_2_2_2_experimental LeasePinger.java
Log:
JBREM-783: (1) Connection PING sends just the new lease sessionID; (2) ordinary PING sends null requestPayload; (3) added variable localStopped to disconnectClient().
Revision Changes Path
No revision
No revision
1.8.2.12.2.7.2.1 +56 -16 JBossRemoting/src/main/org/jboss/remoting/LeasePinger.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LeasePinger.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/LeasePinger.java,v
retrieving revision 1.8.2.12.2.7
retrieving revision 1.8.2.12.2.7.2.1
diff -u -b -r1.8.2.12.2.7 -r1.8.2.12.2.7.2.1
--- LeasePinger.java 8 Aug 2007 05:47:22 -0000 1.8.2.12.2.7
+++ LeasePinger.java 18 Aug 2007 00:57:11 -0000 1.8.2.12.2.7.2.1
@@ -128,7 +128,7 @@
clients.put(sessionID, newClient);
}
- public void connectClient(long leasePeriod)
+ public void connectClient(long leasePeriod, String sessionID)
{
if (leasePeriod <= 0)
{
@@ -149,7 +149,35 @@
}
}
- sendClientPing();
+ if(trace) { log.trace(this + " connecting client with session ID " + sessionID); }
+
+ ClientHolder holder = (ClientHolder) clients.get(sessionID);
+
+ if (holder != null)
+ {
+ // send connect for this client
+ Map clientMap = new HashMap();
+ clientMap.put(ClientHolder.CLIENT_HOLDER_KEY, holder);
+
+ if (trace) log.trace(this + " requesting client lease connect: " + invokerSessionID + ": " + holder);
+ InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$PING$",
+ clientMap, null, null);
+ try
+ {
+ invoker.invoke(ir);
+ if(trace) { log.trace(this + " sent out disconnect message to server for lease tied to client with session ID " + sessionID); }
+ }
+ catch (Throwable throwable)
+ {
+ log.error(this + " failed sending connect for client lease for " +
+ "client with session ID " + sessionID, throwable);
+ }
+ }
+ else
+ {
+ log.warn(this + " tried to connect client with session ID "
+ + sessionID + ", but no such lease was found");
+ }
}
public boolean removeClient(String sessionID)
@@ -251,8 +279,8 @@
log.error(this + " failed sending disconnect for client lease for " +
"client with session ID " + sessionID, throwable);
}
- }
-
+ finally
+ {
// closingClients will be empty only after an attempt has been made to
// disconnect all clients.
synchronized (disconnectLock)
@@ -260,6 +288,8 @@
closingClients.remove(sessionID);
}
}
+ }
+ }
else
{
log.warn(this + " tried to disconnect client with session ID "
@@ -273,6 +303,19 @@
// to destroy the Lease. Any other threads that enter the block
// under the same conditions will find stopped == true and will
// return without attempting to contact the server.
+
+ // It's still possible for the following sequence to occur:
+ // 1. thread A enters synchronized block, finds condition
+ // stopping && closingClients.isEmpty() false
+ // 2. thread B enters synchronized block, finds condition
+ // stopping && closingClients.isEmpty() true
+ // 3. thread A sees stopped == true and calls disconnect
+ // 4. thread B sees stopped == true and calls disconect
+ //
+ // Therefore, the variable localStopped is used, so that only the
+ // thread that set stopped to true will call disconnect.
+
+ boolean localStopped = false;
synchronized (disconnectLock)
{
if (stopped)
@@ -281,10 +324,11 @@
if (stopping && closingClients.isEmpty())
{
stopped = true;
+ localStopped = true;
}
}
- if (stopped)
+ if (localStopped)
{
disconnect();
}
@@ -369,12 +413,8 @@
"for following clients:\n" + sb.toString());
}
- Map clientsClone = new ConcurrentHashMap(clients);
- Map requestClients = new ConcurrentHashMap();
- requestClients.put(ClientHolder.CLIENT_HOLDER_KEY, clientsClone);
-
InvocationRequest ir =
- new InvocationRequest(invokerSessionID, null, "$PING$", requestClients, null, null);
+ new InvocationRequest(invokerSessionID, null, "$PING$", null, null, null);
invoker.invoke(ir);
More information about the jboss-cvs-commits
mailing list