Author: ron.sigal(a)jboss.com
Date: 2009-05-14 22:46:42 -0400 (Thu, 14 May 2009)
New Revision: 5219
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
Log:
JBREM-1132: (1) Adopted use of leasePingerId; (2) establishLease() can call
Client.addConnectionListener(); JBREM-1133: sends time stamp with first PING.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-15
02:13:24 UTC (rev 5218)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-15
02:46:42 UTC (rev 5219)
@@ -385,14 +385,26 @@
public void terminateLease(String sessionId, int disconnectTimeout)
{
+ terminateLease(sessionId, disconnectTimeout, null);
+ }
+
+ public void terminateLease(String sessionId, int disconnectTimeout, LeasePinger
passedLeasePinger)
+ {
synchronized(clientLeaseLock)
{
+ if (passedLeasePinger != null && passedLeasePinger != leasePinger)
+ {
+ if (trace) log.trace(this + ": " + passedLeasePinger + " !=
" + leasePinger);
+ return;
+ }
+ if (trace) log.trace(this + " entering terminateLease() for " +
leasePinger);
if(leasePinger != null)
{
leasePinger.setDisconnectTimeout(disconnectTimeout);
if (sessionId == null)
{
+ if (trace) log.trace(this + " shutting down LeasePinger: " +
leasePinger);
// Independent of any particular Client - force LeasePinger shutdown.
// Should be called only if there is a reasonable belief that the lease
// has already stopped on the server side.
@@ -402,16 +414,19 @@
}
catch (Exception e)
{
- log.debug("error shutting down lease pinger");
+ log.debug("error shutting down lease pinger" +
e.getMessage());
+ log.trace("error shutting down lease pinger", e);
}
leasePinger = null;
}
else
{
// Remove a particular Client.
+ if (trace) log.trace(this + " removing client " + sessionId +
" from LeasePinger: " + leasePinger);
boolean isLastClientLease = leasePinger.removeClient(sessionId);
if(isLastClientLease)
{
+ if (trace) log.trace(this + " shutting down LeasePinger, " +
sessionId + " was last client lease: " + leasePinger);
try
{
leasePinger.stopPing();
@@ -424,6 +439,11 @@
}
}
}
+ else
+ {
+ if (trace) log.trace(this + " leasePinger is null: must have been shut
down already");
+ }
+ if (trace) log.trace(this + " leaving terminateLease() for " +
leasePinger);
}
}
@@ -443,6 +463,22 @@
public void establishLease(String clientSessionID, Map configuration, long
leasePeriod)
throws Throwable
{
+ Client client = (Client) configuration.get(Client.CLIENT);
+ ConnectionListener listener = (ConnectionListener)
configuration.remove(Client.CONNECTION_LISTENER);
+ boolean useClientConnectionIdentity = false;
+ if (configuration != null)
+ {
+ Object o = configuration.get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+ if (o instanceof String)
+ {
+ useClientConnectionIdentity = Boolean.valueOf((String) o).booleanValue();
+ }
+ else if (o != null)
+ {
+ log.warn("value of " + Remoting.USE_CLIENT_CONNECTION_IDENTITY +
" must be a String: " + o);
+ }
+ }
+
synchronized (clientLeaseLock)
{
// if already have a lease pinger, then already have a client with an
established
@@ -450,55 +486,68 @@
if (leasePinger != null)
{
leasePinger.addClient(clientSessionID, configuration, leasePeriod);
- log.debug(this + " added client with session ID " + clientSessionID
+ " to the lease pinger");
- return;
+ if (trace) log.trace(this + " added client with session ID " +
clientSessionID + " to " + leasePinger);
}
-
- try
+ else
{
- if(trace) { log.trace(this + " sending initial lease ping to server to
determine if server has leasing enabled."); }
+ try
+ {
+ if(trace) { log.trace(this + " sending initial lease ping to server
to determine if server has leasing enabled."); }
- // configuration should NOT be passed as want ping to be specific to client
invoker
- // and NOT to the client.
+ // configuration should NOT be passed as want ping to be specific to
client invoker
+ // and NOT to the client.
- InvocationRequest ir =
- new InvocationRequest(invokerSessionID, null, "$PING$", null,
new HashMap(), null);
+ String leasePingerId = new GUID().toString();
+ Map requestMap = new HashMap();
+ requestMap.put(LeasePinger.LEASE_PINGER_ID, leasePingerId);
+ requestMap.put(LeasePinger.TIME_STAMP,
Long.toString(System.currentTimeMillis()));
+ if (trace) log.trace(this + " initiating lease for leasePingerId
" + leasePingerId);
+ InvocationRequest ir = new InvocationRequest(invokerSessionID, null,
"$PING$", requestMap, new HashMap(), null);
- Object ret = invoke(ir);
+ Object ret = invoke(ir);
- if (ret instanceof InvocationResponse)
- {
- InvocationResponse resp = (InvocationResponse) ret;
- Boolean shouldLease = (Boolean)resp.getResult();
-
- if (shouldLease.booleanValue())
+ if (ret instanceof InvocationResponse)
{
- long defaultLeasePeriod = LeasePinger.DEFAULT_LEASE_PERIOD;
- Map respMap = resp.getPayload();
+ InvocationResponse resp = (InvocationResponse) ret;
+ Boolean shouldLease = (Boolean)resp.getResult();
- if (respMap != null)
+ if (shouldLease.booleanValue())
{
- Long leaseTimeoutValue =
(Long)respMap.get("clientLeasePeriod");
- long serverDefaultLeasePeriod = leaseTimeoutValue.longValue();
- if(serverDefaultLeasePeriod > 0)
+ long defaultLeasePeriod = LeasePinger.DEFAULT_LEASE_PERIOD;
+ Map respMap = resp.getPayload();
+
+ if (respMap != null)
{
- defaultLeasePeriod = serverDefaultLeasePeriod;
+ Long leaseTimeoutValue =
(Long)respMap.get("clientLeasePeriod");
+ long serverDefaultLeasePeriod = leaseTimeoutValue.longValue();
+ if(serverDefaultLeasePeriod > 0)
+ {
+ defaultLeasePeriod = serverDefaultLeasePeriod;
+ }
}
- }
- if(trace) { log.trace("server does have leasing enabled (with
default lease period of " + defaultLeasePeriod + ") and will start a new lease
pinger."); }
+ if(trace) { log.trace("server does have leasing enabled (with
default lease period of " + defaultLeasePeriod + ") and will start a new lease
pinger."); }
- leasePinger = new LeasePinger(this, invokerSessionID,
defaultLeasePeriod, configuration);
- leasePinger.addClient(clientSessionID, configuration, leasePeriod);
- leasePinger.startPing();
+ leasePinger = new LeasePinger(this, invokerSessionID,
defaultLeasePeriod);
+ leasePinger.setLeasePingerId(leasePingerId);
+
leasePinger.setUseClientConnectionIdentity(useClientConnectionIdentity);
+ leasePinger.addClient(clientSessionID, configuration, leasePeriod);
+ leasePinger.startPing();
+ }
}
}
+ catch (Throwable throwable)
+ {
+ Exception e = new Exception("Error setting up client lease");
+ e.initCause(throwable);
+ throw e;
+ }
}
- catch (Throwable throwable)
+
+ if (trace) log.trace(this + ": client = " + client + ", listener
= " + listener);
+ if (client != null && listener != null)
{
- Exception e = new Exception("Error setting up client lease");
- e.initCause(throwable);
- throw e;
+ client.addConnectionListener(listener, configuration);
}
}
}
@@ -633,6 +682,14 @@
super.finalize();
}
+ protected LeasePinger getLeasePinger()
+ {
+ synchronized(clientLeaseLock)
+ {
+ return leasePinger;
+ }
+ }
+
static private String getSystemProperty(final String name)
{
if (SecurityUtility.skipAccessControl())