[jboss-remoting-commits] JBoss Remoting SVN: r5217 - remoting2/branches/2.x/src/main/org/jboss/remoting.
jboss-remoting-commits at lists.jboss.org
jboss-remoting-commits at lists.jboss.org
Thu May 14 22:06:55 EDT 2009
Author: ron.sigal at jboss.com
Date: 2009-05-14 22:06:55 -0400 (Thu, 14 May 2009)
New Revision: 5217
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Lease.java
Log:
(1) JBREM-1132: Adopted use of leasePingerId; (2) JBREM-1133: adopted use of time stamp.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Lease.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Lease.java 2009-05-15 01:58:55 UTC (rev 5216)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Lease.java 2009-05-15 02:06:55 UTC (rev 5217)
@@ -25,6 +25,7 @@
import org.jboss.remoting.util.TimerUtil;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TimerTask;
@@ -48,8 +49,13 @@
private long leaseWindow = -1;
private long pingStart = -1;
private Map clientLeases = null;
+ private Object lock = new Object();
+ private String leasePingerId;
+ private boolean stopped;
private boolean leaseUpdated = false;
+ private long lastUpdate;
+ private boolean useClientConnectionIdentity;
private static final Logger log = Logger.getLogger(Lease.class);
private static final boolean isTraceEnabled = log.isTraceEnabled();
@@ -64,6 +70,16 @@
if(requestPayload != null)
{
this.requestPayload = (Map)requestPayload.get(ClientHolder.CLIENT_HOLDER_KEY);
+ this.leasePingerId = (String) requestPayload.get(LeasePinger.LEASE_PINGER_ID);
+ String s = (String) requestPayload.get(LeasePinger.TIME_STAMP);
+ if (s != null)
+ {
+ this.lastUpdate = Long.valueOf(s).longValue();
+ this.useClientConnectionIdentity = true;
+ if (isTraceEnabled) log.trace(this + " initialized with lastUpdate: " + lastUpdate);
+ }
+ if (isTraceEnabled) log.trace(this + " initialized with requestPayload: " + this.requestPayload);
+ if (isTraceEnabled) log.trace("leasePingerId: " + leasePingerId);
}
this.leaseWindow = leasePeriod * 2;
this.clientLeases = clientLeases;
@@ -84,9 +100,36 @@
{
if(requestMap != null)
{
- this.requestPayload = (Map)requestMap.get(ClientHolder.CLIENT_HOLDER_KEY);
+ synchronized (lock)
+ {
+ if (useClientConnectionIdentity)
+ {
+ if (isTraceEnabled) log.trace(this + " requestMap: " + requestMap);
+ long time = 0;
+ String timeString = (String) requestMap.get(LeasePinger.TIME_STAMP);
+ time = Long.valueOf(timeString).longValue();
+ if (isTraceEnabled) log.trace(this + " last update: " + lastUpdate + ", this update: " + time);
+ if (time > lastUpdate)
+ {
+ lastUpdate = time;
+ doUpdate(requestMap);
+ }
+ else
+ {
+ if (isTraceEnabled) log.trace(this + " updating lease but not client list");
+ leaseUpdated = true;
+ }
+ }
+ else
+ {
+ doUpdate(requestMap);
+ }
+ }
}
- updateLease(leasePeriod);
+ else
+ {
+ if (isTraceEnabled) log.trace(this + " requestPayload == null");
+ }
}
public void updateLease(long leasePeriod)
@@ -124,13 +167,14 @@
public void terminateLease(String sessionId)
{
- if(isTraceEnabled)
- {
- log.trace("Terminating lease for session id " + sessionId);
- }
// is this terminate for all clients
if (clientSessionId.equals(sessionId))
{
+ if(isTraceEnabled)
+ {
+ log.trace(this + " Terminating lease group for session id " + sessionId);
+ }
+
stopLease();
// should be ok to call this will null as all the client should have
// already been disconnected and there been a notification for each
@@ -140,33 +184,101 @@
}
else
{
+ if(isTraceEnabled)
+ {
+ log.trace(this + " Terminating individual lease for session id " + sessionId);
+ }
notifyClientTermination(sessionId);
}
}
-
+
+ public void terminateLeaseUponFailure(String sessionId)
+ {
+ // is this terminate for all clients
+ if (clientSessionId.equals(sessionId))
+ {
+ if(isTraceEnabled)
+ {
+ log.trace(this + " Terminating lease group for session id " + sessionId);
+ }
+
+ stopLease();
+ // should be ok to call this will null as all the client should have
+ // already been disconnected and there been a notification for each
+ // of these client disconnections (which would remove the client from
+ // the lease, thus leaving the collection empty
+ notifyClientLost();
+ }
+ else
+ {
+ if(true)
+ {
+ log.warn(this + " Expected invoker session id: " + sessionId);
+ }
+ notifyClientLost();
+ }
+ }
+
+ public String toString()
+ {
+ String hash = Integer.toHexString(System.identityHashCode(this));
+ return "Lease[" + hash + ":" + clientSessionId + ":" + leasePingerId + "]";
+ }
+
private void notifyClientTermination(String sessionId)
{
- // is for a particular client, so need to inspect request payload for client
- if (requestPayload != null)
+ Map localRequestPayload = null;
+ synchronized (lock)
{
+ if (requestPayload != null)
+ {
+ localRequestPayload = new HashMap(requestPayload);
+ if (sessionId != null)
+ {
+ requestPayload.remove(sessionId);
+ }
+ }
+ }
+
+ if (localRequestPayload != null)
+ {
// should notify for one client or all?
if (sessionId != null)
{
- Object clientHolderObj = requestPayload.remove(sessionId);
+ synchronized (lock)
+ {
+ if (stopped)
+ {
+ if (isTraceEnabled) log.trace(this + " already stopped");
+ return;
+ }
+ }
+
+ Object clientHolderObj = localRequestPayload.get(sessionId);
if (clientHolderObj != null && clientHolderObj instanceof ClientHolder)
{
ClientHolder clientHolder = (ClientHolder) clientHolderObj;
notifier.connectionTerminated(locatorURL, clientHolder.getSessionId(), clientHolder.getConfig());
if(isTraceEnabled)
{
- log.trace("Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
+ log.trace(this + " Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
}
}
}
else
{
+ synchronized (lock)
+ {
+ if (stopped)
+ {
+ if (isTraceEnabled) log.trace(this + " already stopped");
+ return;
+ }
+ stopped = true;
+ }
+
// loop through and notify for all clients
- Collection clientHoldersCol = requestPayload.values();
+ Collection clientHoldersCol = localRequestPayload.values();
if (clientHoldersCol != null && clientHoldersCol.size() > 0)
{
Iterator itr = clientHoldersCol.iterator();
@@ -179,7 +291,7 @@
notifier.connectionTerminated(locatorURL, clientHolder.getSessionId(), clientHolder.getConfig());
if(isTraceEnabled)
{
- log.trace("Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
+ log.trace(this + " Notified connection lif (isTraceEnabled) log.tracef lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
}
}
}
@@ -188,17 +300,32 @@
}
else
{
- log.warn("Tried to terminate lease for session id " + sessionId + ", but no collection of clients have been set.");
+ log.warn(this + " Tried to terminate lease for session id " + sessionId + ", but no collection of clients have been set.");
}
}
private void notifyClientLost()
{
- // is not for a particular client (but all clients associated with client invoker), so need to inspect request payload for client
- if (requestPayload != null)
+ Map localRequestPayload = null;
+ synchronized (lock)
{
+ if (stopped)
+ {
+ if (isTraceEnabled) log.trace(this + " already stopped");
+ return;
+ }
+ stopped = true;
+ if (requestPayload != null)
+ {
+ localRequestPayload = new HashMap(requestPayload);
+ }
+ }
+
+ if (localRequestPayload != null)
+ {
// loop through and notify for all clients
- Collection clientHoldersCol = requestPayload.values();
+ Collection clientHoldersCol = localRequestPayload.values();
+ if (isTraceEnabled) log.trace(this + " notifying listeners about " + clientHoldersCol.size() + " expired client(s)");
if (clientHoldersCol != null && clientHoldersCol.size() > 0)
{
Iterator itr = clientHoldersCol.iterator();
@@ -211,7 +338,7 @@
notifier.connectionLost(locatorURL, clientHolder.getSessionId(), clientHolder.getConfig());
if(isTraceEnabled)
{
- log.trace("Notified connection listener of lease expired due to lost connection from client (client session id = " + clientHolder.getSessionId());
+ log.trace(this + " Notified connection listener of lease expired due to lost connection from client (client session id = " + clientHolder.getSessionId());
}
}
}
@@ -219,16 +346,43 @@
}
else
{
- log.debug("requestPayload == null, calling ConnectionNotifier.connectionTerminated()");
- notifier.connectionTerminated(locatorURL, clientSessionId, null);
+ if (isTraceEnabled) log.trace(this + " requestPayload == null, calling ConnectionNotifier.connectionLost()");
+ notifier.connectionLost(locatorURL, clientSessionId, null);
}
}
+ protected String getLeasePingerId()
+ {
+ return leasePingerId;
+ }
+
private void stopLease()
{
leaseTimerTask.cancel();
}
+ private void doUpdate(Map requestMap)
+ {
+ this.requestPayload = (Map)requestMap.get(ClientHolder.CLIENT_HOLDER_KEY);
+ if (isTraceEnabled)
+ {
+ log.trace(this + " updating: new Client list:");
+ Collection clientHoldersCol = requestPayload.values();
+ Iterator itr = clientHoldersCol.iterator();
+ while (itr.hasNext())
+ {
+ Object val = itr.next();
+ if (val != null && val instanceof ClientHolder)
+ {
+ ClientHolder clientHolder = (ClientHolder) val;
+ log.trace(leasePingerId + ": " + clientHolder.getSessionId());
+ }
+ }
+ }
+ updateLease(leasePeriod);
+ }
+
+
private class LeaseTimerTask extends TimerTask
{
@@ -245,14 +399,14 @@
{
try
{
- if (log.isTraceEnabled()) log.trace("did not receive ping: " + clientSessionId);
+ if (isTraceEnabled) log.trace(Lease.this + " did not receive ping: " + clientSessionId);
stopLease();
notifyClientLost();
if (clientLeases != null)
{
clientLeases.remove(clientSessionId);
}
- if (log.isTraceEnabled()) log.trace("removed lease:" + clientSessionId);
+ if (isTraceEnabled) log.trace(Lease.this + " removed lease:" + clientSessionId);
}
catch (Throwable thr)
{
More information about the jboss-remoting-commits
mailing list