[jboss-remoting-commits] JBoss Remoting SVN: r5653 - remoting2/branches/2.2/src/main/org/jboss/remoting.
jboss-remoting-commits at lists.jboss.org
jboss-remoting-commits at lists.jboss.org
Fri Jan 8 17:48:56 EST 2010
Author: ron.sigal at jboss.com
Date: 2010-01-08 17:48:56 -0500 (Fri, 08 Jan 2010)
New Revision: 5653
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1176: Uses a counter to destroy invoker destruction Timer when there are no more Clients using the facility.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2010-01-08 22:46:06 UTC (rev 5652)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2010-01-08 22:48:56 UTC (rev 5653)
@@ -179,6 +179,8 @@
private static Timer invokerDestructionTimer;
private static Object invokerDestructionTimerLock = new Object();
+
+ private static int clientCounter;
// Static ---------------------------------------------------------------------------------------
@@ -678,7 +680,7 @@
{
synchronized (invokerDestructionTimerLock)
{
- InvokerDestructionTimerTask task = new InvokerDestructionTimerTask(invoker);
+ InvokerDestructionTimerTask task = new InvokerDestructionTimerTask(invoker, configuration);
if (invokerDestructionTimer == null)
{
invokerDestructionTimer = new Timer(true);
@@ -1806,6 +1808,14 @@
throw e;
}
log.debug(this + " connected to " + locator);
+ if (invokerDestructionDelay > 0)
+ {
+ synchronized (invokerDestructionTimerLock)
+ {
+ clientCounter++;
+ log.debug(this + " clientCounter: " + clientCounter);
+ }
+ }
}
else
{
@@ -2012,22 +2022,33 @@
// Inner classes --------------------------------------------------------------------------------
- class InvokerDestructionTimerTask extends TimerTask
+ static class InvokerDestructionTimerTask extends TimerTask
{
- private WeakReference ref;
+ private ClientInvoker invoker;
+ private Map config;
- public InvokerDestructionTimerTask(ClientInvoker invoker)
+ public InvokerDestructionTimerTask(ClientInvoker invoker, Map config)
{
- ref = new WeakReference(invoker);
+ this.invoker = invoker;
+ this.config = config;
}
public void run()
{
- ClientInvoker invoker = (ClientInvoker) ref.get();
- log.trace(this + " calling InvokerRegistry.destroyClientInvoker() for " + invoker);
- InvokerRegistry.destroyClientInvoker(invoker.getLocator(), configuration);
- ref.clear();
- ref = null;
+ log.debug(this + " calling InvokerRegistry.destroyClientInvoker() for " + invoker);
+ InvokerRegistry.destroyClientInvoker(invoker.getLocator(), config);
+
+ synchronized (invokerDestructionTimerLock)
+ {
+ if (--clientCounter == 0)
+ {
+ invokerDestructionTimer.cancel();
+ invokerDestructionTimer = null;
+ log.debug(this + " stopped invokerDestructionTimer");
+ }
+ log.debug(this + " clientCounter: " + clientCounter);
+ }
+ log.debug(this + "done");
}
}
More information about the jboss-remoting-commits
mailing list