Author: ron.sigal(a)jboss.com
Date: 2010-01-08 13:28:32 -0500 (Fri, 08 Jan 2010)
New Revision: 5649
Modified:
remoting2/branches/2.x/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.x/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2009-12-27 18:26:25 UTC
(rev 5648)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2010-01-08 18:28:32 UTC
(rev 5649)
@@ -186,6 +186,8 @@
private static Timer invokerDestructionTimer;
private static Object invokerDestructionTimerLock = new Object();
+
+ private static int clientCounter;
// Static
---------------------------------------------------------------------------------------
@@ -660,7 +662,7 @@
{
synchronized (invokerDestructionTimerLock)
{
- InvokerDestructionTimerTask task = new
InvokerDestructionTimerTask(invoker);
+ InvokerDestructionTimerTask task = new
InvokerDestructionTimerTask(invoker, configuration);
if (invokerDestructionTimer == null)
{
invokerDestructionTimer = new Timer(true);
@@ -1798,6 +1800,14 @@
throw e;
}
log.debug(this + " connected to " + locator);
+ if (invokerDestructionDelay > 0)
+ {
+ synchronized (invokerDestructionTimerLock)
+ {
+ clientCounter++;
+ log.debug(this + " clientCounter: " + clientCounter);
+ }
+ }
}
else
{
@@ -2062,22 +2072,34 @@
}
// 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");
}
}
Show replies by date