[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...
Ron Sigal
ron_sigal at yahoo.com
Thu Feb 15 23:11:18 EST 2007
User: rsigal
Date: 07/02/15 23:11:18
Modified: src/main/org/jboss/remoting Tag: remoting_2_x Client.java
Log:
JBREM-657: Removed disconnectLocal() and removeListenerLocal().
Revision Changes Path
No revision
No revision
1.53.2.21 +139 -185 JBossRemoting/src/main/org/jboss/remoting/Client.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Client.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/Client.java,v
retrieving revision 1.53.2.20
retrieving revision 1.53.2.21
diff -u -b -r1.53.2.20 -r1.53.2.21
--- Client.java 15 Feb 2007 08:48:17 -0000 1.53.2.20
+++ Client.java 16 Feb 2007 04:11:18 -0000 1.53.2.21
@@ -64,7 +64,7 @@
* @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
* @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
*
- * @version $Revision: 1.53.2.20 $
+ * @version $Revision: 1.53.2.21 $
*/
public class Client implements Externalizable
{
@@ -440,21 +440,23 @@
*/
public void disconnect()
{
- disconnectInternal(false);
- }
+ if (invoker != null)
+ {
+ // this is a noop if no lease is active
+ invoker.terminateLease(sessionId);
- /**
- * Disconnects the underlying transport from the target server. Is important that this method
- * is called when no longer using the remoting client. Otherwise resource will not be cleaned up
- * and if the target server requires a lease, it will be maintained in the background.
- *
- * disconnectLocal() differs from disconnect() by not attempting to communicate with the server.
- * It is recommended that disconnectLocal() be used only when the connection to the server is
- * known to have failed.
- */
- public void disconnectLocal()
+ if (connectionValidator != null)
{
- disconnectInternal(true);
+ connectionValidator.stop();
+ connectionValidator = null;
+ }
+
+ // 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);
+ invoker = null;
+ }
}
/**
@@ -615,7 +617,7 @@
if (onewayThreadPool == null)
{
BasicThreadPool pool = new BasicThreadPool("JBossRemoting Client Oneway");
- log.info("created new thread pool: " + pool);
+ log.debug("created new thread pool: " + pool);
Object param = configuration.get(MAX_NUM_ONEWAY_THREADS);
if (param instanceof String)
{
@@ -628,9 +630,9 @@
log.error("maxNumberThreads parameter has invalid format: " + param);
}
}
- else
+ else if (param != null)
{
- log.error("maxNumberThreads parameter must be in integer format: " + param);
+ log.error("maxNumberThreads parameter must be a string in integer format: " + param);
}
param = configuration.get(MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE);
@@ -646,9 +648,9 @@
log.error("maxOnewayThreadPoolQueueSize parameter has invalid format: " + param);
}
}
- else
+ else if (param != null)
{
- log.error("maxOnewayThreadPoolQueueSize parameter must be in integer format: " + param);
+ log.error("maxOnewayThreadPoolQueueSize parameter must be a string in integer format: " + param);
}
pool.setMaximumPoolSize(maxNumberThreads);
@@ -931,20 +933,124 @@
*/
public void removeListener(InvokerCallbackHandler callbackHandler) throws Throwable
{
- removeListenerInternal(callbackHandler, false);
+ if (isConnected())
+ {
+ if (callbackHandler != null)
+ {
+ // first need to see if is push or pull callback (i.e. does have locator associated
+ // with it)
+ String listenerId = (String)listeners.get(callbackHandler);
+ if(listenerId != null)
+ {
+ // have a pull callback handler
+ Map metadata = new HashMap();
+ metadata.put(LISTENER_ID_KEY, listenerId);
+ invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata);
+
+ // clean up callback poller if one exists
+ CallbackPoller callbackPoller = (CallbackPoller) callbackPollers.remove(callbackHandler);
+ if (callbackPoller != null)
+ {
+ callbackPoller.stop();
}
- /**
- * Removes callback handler as a callback listener from the server (and client in the case that
- * it was setup to receive async callbacks). See addListener().
- *
- * removeListenerLocal() differs from removeListener() in that it does not attempt to communicate
- * with the server. It is recommended that removeListenerLocal() be used only when the
- * connection to the server is known to have failed.
- */
- public void removeListenerLocal(InvokerCallbackHandler callbackHandler) throws Throwable
+ listeners.remove(callbackHandler);
+
+// // have a pull callback handler
+// Map metadata = new HashMap();
+// metadata.put(LISTENER_ID_KEY, listenerId);
+// invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata);
+ }
+ else
+ {
+ // have a push callback handler
+ List holderList = invoker.getClientLocators(sessionId, callbackHandler);
+ if(holderList != null && holderList.size() > 0)
{
- removeListenerInternal(callbackHandler, true);
+ for(int x = 0; x < holderList.size(); x++)
+ {
+ AbstractInvoker.CallbackLocatorHolder holder =
+ (AbstractInvoker.CallbackLocatorHolder)holderList.get(x);
+ listenerId = holder.getListenerId();
+ InvokerLocator locator = holder.getLocator();
+ Map metadata = new HashMap();
+ metadata.put(LISTENER_ID_KEY, listenerId);
+
+ try
+ {
+ // now call target server to remove listener
+ InternalInvocation ii =
+ new InternalInvocation(InternalInvocation.REMOVELISTENER, null);
+
+ invoke(ii, metadata);
+ }
+ catch (Exception e)
+ {
+ log.warn("unable to remove remote callback handler: " + e.getMessage());
+ }
+
+ // call to callback server to remove listener
+ Client client = new Client(locator, subsystem);
+ client.setSessionId(getSessionId());
+ client.connect();
+ InternalInvocation ii =
+ new InternalInvocation(InternalInvocation.REMOVECLIENTLISTENER,
+ new Object[]{callbackHandler});
+
+ client.invoke(ii, metadata);
+ client.disconnect();
+//
+// // now call target server to remove listener
+// invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata);
+
+ }
+ }
+ }
+
+// Map metadata = createListenerMetadata(callbackHandler);
+// String listenerId = (String) metadata.get(LISTENER_ID_KEY);
+// // connect to the given client locator and remove handler as listener
+// InvokerLocator locator = invoker.getClientLocator(listenerId);
+// if (locator != null) // async callback
+// {
+// Client client = new Client(locator, subsystem);
+// client.setSessionId(getSessionId());
+// client.connect();
+// client.invoke(new InternalInvocation(InternalInvocation.REMOVECLIENTLISTENER,
+// new Object[]{callbackHandler}),
+// metadata);
+// client.disconnect();
+// }
+// // now call server to remove listener
+// invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata);
+
+ // clean up callback server connector if one exists
+
+ Connector callbackConnector = (Connector) callbackConnectors.remove(callbackHandler);
+
+ if (callbackConnector != null)
+ {
+ callbackConnector.stop();
+ callbackConnector.destroy();
+ }
+
+// // clean up callback poller if one exists
+// CallbackPoller callbackPoller = (CallbackPoller) callbackPollers.remove(callbackHandler);
+// if (callbackPoller != null)
+// {
+// callbackPoller.stop();
+// }
+ }
+ else
+ {
+ throw new NullPointerException("Can not remove null InvokerCallbackHandler listener.");
+ }
+ }
+ else
+ {
+ throw new Exception("Can not remove callback listener as " +
+ "remoting client is not connected to server.");
+ }
}
/**
@@ -1305,27 +1411,6 @@
}
}
- private void disconnectInternal(boolean local)
- {
- if (invoker != null)
- {
- // this is a noop if no lease is active
- invoker.terminateLease(sessionId, local);
-
- if (connectionValidator != null)
- {
- connectionValidator.stop();
- connectionValidator = null;
- }
-
- // 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);
- invoker = null;
- }
- }
-
private void setupClientLease(ClientInvoker invoker) throws Throwable
{
long leasePeriod = -1;
@@ -1505,137 +1590,6 @@
return listenerId;
}
- private void removeListenerInternal(InvokerCallbackHandler callbackHandler, boolean local)
- throws Throwable
- {
- if (isConnected())
- {
- if (callbackHandler != null)
- {
- // first need to see if is push or pull callback (i.e. does have locator associated
- // with it)
- String listenerId = (String)listeners.get(callbackHandler);
- if(listenerId != null)
- {
- // have a pull callback handler
- if (!local)
- {
- Map metadata = new HashMap();
- metadata.put(LISTENER_ID_KEY, listenerId);
- invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata);
- }
-
- // clean up callback poller if one exists
- CallbackPoller callbackPoller =
- (CallbackPoller) callbackPollers.remove(callbackHandler);
- if (callbackPoller != null)
- {
- callbackPoller.stop(local);
- }
-
- listeners.remove(callbackHandler);
-
-// // have a pull callback handler
-// Map metadata = new HashMap();
-// metadata.put(LISTENER_ID_KEY, listenerId);
-// invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata);
- }
- else
- {
- // have a push callback handler
- List holderList = invoker.getClientLocators(sessionId, callbackHandler);
- if(holderList != null && holderList.size() > 0)
- {
- for(int x = 0; x < holderList.size(); x++)
- {
- AbstractInvoker.CallbackLocatorHolder holder =
- (AbstractInvoker.CallbackLocatorHolder)holderList.get(x);
- listenerId = holder.getListenerId();
- InvokerLocator locator = holder.getLocator();
- Map metadata = new HashMap();
- metadata.put(LISTENER_ID_KEY, listenerId);
-
- if (!local)
- {
- try
- {
- // now call target server to remove listener
- InternalInvocation ii =
- new InternalInvocation(InternalInvocation.REMOVELISTENER, null);
-
- invoke(ii, metadata);
- }
- catch (Exception e)
- {
- log.warn("unable to remove remote callback handler: " + e.getMessage());
- }
- }
-
- // call to callback server to remove listener
- Client client = new Client(locator, subsystem);
- client.setSessionId(getSessionId());
- client.connect();
- InternalInvocation ii =
- new InternalInvocation(InternalInvocation.REMOVECLIENTLISTENER,
- new Object[]{callbackHandler});
-
- client.invoke(ii, metadata);
- client.disconnect();
-//
-// // now call target server to remove listener
-// invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata);
-
- }
- }
- }
-
-// Map metadata = createListenerMetadata(callbackHandler);
-// String listenerId = (String) metadata.get(LISTENER_ID_KEY);
-// // connect to the given client locator and remove handler as listener
-// InvokerLocator locator = invoker.getClientLocator(listenerId);
-// if (locator != null) // async callback
-// {
-// Client client = new Client(locator, subsystem);
-// client.setSessionId(getSessionId());
-// client.connect();
-// client.invoke(new InternalInvocation(InternalInvocation.REMOVECLIENTLISTENER,
-// new Object[]{callbackHandler}),
-// metadata);
-// client.disconnect();
-// }
-// // now call server to remove listener
-// invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata);
-
- // clean up callback server connector if one exists
-
- Connector callbackConnector = (Connector) callbackConnectors.remove(callbackHandler);
-
- if (callbackConnector != null)
- {
- callbackConnector.stop();
- callbackConnector.destroy();
- }
-
-// // clean up callback poller if one exists
-// CallbackPoller callbackPoller = (CallbackPoller) callbackPollers.remove(callbackHandler);
-// if (callbackPoller != null)
-// {
-// callbackPoller.stop();
-// }
- }
- else
- {
- throw new NullPointerException("Can not remove null InvokerCallbackHandler listener.");
- }
- }
- else
- {
- throw new Exception("Can not remove callback listener as " +
- "remoting client is not connected to server.");
- }
- }
-
-
// Inner classes --------------------------------------------------------------------------------
}
More information about the jboss-cvs-commits
mailing list