[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...
Ron Sigal
ron_sigal at yahoo.com
Thu Aug 2 02:36:12 EDT 2007
User: rsigal
Date: 07/08/02 02:36:12
Modified: src/main/org/jboss/remoting Tag: remoting_2_x
LeasePinger.java
Log:
JBREM-783: Moved network i/o from removeClient() to new method disconnectClient().
Revision Changes Path
No revision
No revision
1.8.2.14 +85 -37 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.13
retrieving revision 1.8.2.14
diff -u -b -r1.8.2.13 -r1.8.2.14
--- LeasePinger.java 11 Jul 2007 00:48:43 -0000 1.8.2.13
+++ LeasePinger.java 2 Aug 2007 06:36:12 -0000 1.8.2.14
@@ -44,9 +44,15 @@
private long pingPeriod = -1;
private int disconnectTimeout = DEFAULT_DISCONNECT_TIMEOUT;
+ private boolean started;
// Constructors ---------------------------------------------------------------------------------
+ public LeasePinger(ClientInvoker invoker, String invokerSessionID)
+ {
+ this(invoker, invokerSessionID, DEFAULT_LEASE_PERIOD);
+ }
+
public LeasePinger(ClientInvoker invoker, String invokerSessionID, long defaultLeasePeriod)
{
this.invoker = invoker;
@@ -57,12 +63,25 @@
// Public ---------------------------------------------------------------------------------------
+ public void setDefaultLeasePeriod(long defaultLeasePeriod)
+ {
+ this.defaultPingPeriod = defaultLeasePeriod;
+ if (defaultLeasePeriod < this.pingPeriod)
+ this.pingPeriod = defaultLeasePeriod;
+ }
+
public void startPing()
{
if(trace) { log.trace(this + " starting lease timer with ping period of " + pingPeriod); }
timerTask = new LeaseTimerTask(this);
timer.schedule(timerTask, pingPeriod, pingPeriod);
+ started = true;
+ }
+
+ public boolean isStarted()
+ {
+ return started;
}
public void stopPing()
@@ -133,44 +152,15 @@
public boolean removeClient(String sessionID)
{
- boolean isLastClientLease = false;
+ // removeClient() has been reorganized to support more nimble use of
+ // synchronization blocks - see JBREM-783.
- if(trace) { log.trace(this + " removing client with session ID " + sessionID); }
-
- ClientHolder holder = (ClientHolder)clients.remove(sessionID);
-
- if (holder != null)
- {
- // send disconnect for this client
- try
- {
- Map clientMap = new HashMap();
- clientMap.put(ClientHolder.CLIENT_HOLDER_KEY, holder);
+ // In particular, the network i/o formerly found in removeClient() has been
+ // moved to the new method disconnectClient().
- // If disconnectTimeout == 0, skip network i/o.
- if (disconnectTimeout != 0)
- {
- if (disconnectTimeout > 0)
- clientMap.put(ServerInvoker.TIMEOUT, Integer.toString(disconnectTimeout));
-
- InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$DISCONNECT$",
- clientMap, null, null);
- invoker.invoke(ir);
+ boolean isLastClientLease = false;
- if(trace) { log.trace(this + " sent out disconnect message to server for lease tied to client with session ID " + sessionID); }
- }
- }
- catch (Throwable throwable)
- {
- log.warn(this + " failed sending disconnect for client lease for " +
- "client with session ID " + sessionID);
- }
- }
- else
- {
- log.warn(this + " tried to remove lease for client with session ID " + sessionID +
- ", but no such lease was found");
- }
+ if(trace) { log.trace(this + " removing client with session ID " + sessionID); }
if (clients.isEmpty())
{
@@ -212,6 +202,52 @@
return isLastClientLease;
}
+ public void disconnectClient(String sessionID)
+ {
+ if(trace) { log.trace(this + " disconnection client with session ID " + sessionID); }
+
+ ClientHolder holder = (ClientHolder)clients.remove(sessionID);
+
+ if (holder != null)
+ {
+ // send disconnect for this client
+ Map clientMap = new HashMap();
+ clientMap.put(ClientHolder.CLIENT_HOLDER_KEY, holder);
+
+ // If disconnectTimeout == 0, skip network i/o.
+ if (disconnectTimeout != 0)
+ {
+ if (disconnectTimeout > 0)
+ clientMap.put(ServerInvoker.TIMEOUT, Integer.toString(disconnectTimeout));
+
+ InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$DISCONNECT$",
+ clientMap, null, null);
+ try
+ {
+ invoker.invoke(ir);
+ }
+ catch (Throwable throwable)
+ {
+ log.error(this + " failed sending disconnect for client lease for " +
+ "client with session ID " + sessionID, throwable);
+ return;
+ }
+
+ if(trace) { log.trace(this + " sent out disconnect message to server for lease tied to client with session ID " + sessionID); }
+ }
+ }
+ else
+ {
+ log.warn(this + " tried to remove lease for client with session ID " + sessionID +
+ ", but no such lease was found");
+ }
+ }
+
+ public Map getClients()
+ {
+ return clients;
+ }
+
public long getLeasePeriod(String sessionID)
{
if (timerTask == null)
@@ -237,6 +273,18 @@
// Package protected ----------------------------------------------------------------------------
+ /**
+ * Simply removes references to all clients. Should only be called on a LeasePinger
+ * which was never started.
+ */
+ protected void purgeClients()
+ {
+ if (!started)
+ {
+ clients.clear();
+ }
+ }
+
// Protected ------------------------------------------------------------------------------------
More information about the jboss-cvs-commits
mailing list