[jboss-remoting-commits] JBoss Remoting SVN: r5310 - remoting2/branches/2.2/src/main/org/jboss/remoting.
jboss-remoting-commits at lists.jboss.org
jboss-remoting-commits at lists.jboss.org
Tue Jul 28 16:35:28 EDT 2009
Author: ron.sigal at jboss.com
Date: 2009-07-28 16:35:27 -0400 (Tue, 28 Jul 2009)
New Revision: 5310
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1139: Adjusts PortUtil range in constructor; JBREM-1143: implements "invoker destruction delay" feature.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2009-07-28 02:19:48 UTC (rev 5309)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2009-07-28 20:35:27 UTC (rev 5310)
@@ -60,6 +60,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
/**
* Client is a convience class for invoking remote methods for a given subsystem. It is intended to
@@ -152,6 +154,11 @@
*/
public static final int DEFAULT_DISCONNECT_TIMEOUT = -1;
+ /**
+ * Key for setting delay before client invoker is destroyed by disconnect().
+ */
+ public static final String INVOKER_DESTRUCTION_DELAY = "invokerDestructionDelay";
+
public static final String THROW_CALLBACK_EXCEPTION = "throwCallbackException";
/** The key to use to specify that parameters for objects created by Client should be taken,
@@ -169,6 +176,9 @@
private static boolean trace = log.isTraceEnabled();
private static final long serialVersionUID = 5679279425009837934L;
+
+ private static Timer invokerDestructionTimer;
+ private static Object invokerDestructionTimerLock = new Object();
// Static ---------------------------------------------------------------------------------------
@@ -202,6 +212,8 @@
private boolean connected = false;
+ private int invokerDestructionDelay = 0;
+
private Set connectionListeners = new HashSet();
private boolean useClientConnectionIdentity;
@@ -282,9 +294,27 @@
if (configuration != null)
{
this.configuration = new HashMap(configuration);
- Object o = configuration.get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+ Object o = configuration.get(INVOKER_DESTRUCTION_DELAY);
if (o instanceof String)
{
+ try
+ {
+ invokerDestructionDelay = Integer.parseInt((String) o);
+ log.debug(this + " setting invokerDestructionDelay to " + invokerDestructionDelay);
+ }
+ catch (NumberFormatException e)
+ {
+ log.error("invokerDestructionDelay parameter has invalid format: " + o);
+ }
+ }
+ else if (o != null)
+ {
+ log.error("invokerDestructionDelay parameter must be a string in integer format: " + o);
+ }
+
+ o = configuration.get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+ if (o instanceof String)
+ {
useClientConnectionIdentity = Boolean.valueOf((String) o).booleanValue();
}
else if (o != null)
@@ -304,6 +334,15 @@
}
}
}
+
+ Map tempMap = new HashMap();
+ if (this.configuration != null)
+ {
+ tempMap.putAll(this.configuration);
+ }
+ tempMap.putAll(locator.getParameters());
+ PortUtil.updateRange(tempMap);
+
this.sessionId = new GUID().toString();
}
@@ -634,7 +673,36 @@
// Need to remove myself from registry so will not keep reference to me since I am of no
// use now. Will have to create a new one.
- InvokerRegistry.destroyClientInvoker(invoker.getLocator(), configuration);
+
+ if (invokerDestructionDelay > 0)
+ {
+ synchronized (invokerDestructionTimerLock)
+ {
+ InvokerDestructionTimerTask task = new InvokerDestructionTimerTask(invoker);
+ if (invokerDestructionTimer == null)
+ {
+ invokerDestructionTimer = new Timer(true);
+ }
+
+ try
+ {
+ invokerDestructionTimer.schedule(task, invokerDestructionDelay);
+ }
+ catch (IllegalStateException e)
+ {
+ log.debug("Unable to schedule InvokerDestructionTimerTask on existing Timer", e);
+ invokerDestructionTimer = new Timer(true);
+ invokerDestructionTimer.schedule(task, invokerDestructionDelay);
+ }
+
+ if (trace) log.trace(this + " scheduled destruction of " + invoker);
+ }
+ }
+ else
+ {
+ InvokerRegistry.destroyClientInvoker(invoker.getLocator(), configuration);
+ }
+
invoker = null;
}
@@ -1944,6 +2012,25 @@
// Inner classes --------------------------------------------------------------------------------
+
+ class InvokerDestructionTimerTask extends TimerTask
+ {
+ private WeakReference ref;
+
+ public InvokerDestructionTimerTask(ClientInvoker invoker)
+ {
+ ref = new WeakReference(invoker);
+ }
+
+ 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;
+ }
+ }
static class ConnectionValidatorKey
{
More information about the jboss-remoting-commits
mailing list