[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...
Ovidiu Feodorov
ovidiu.feodorov at jboss.com
Sun Jan 21 05:21:23 EST 2007
User: ovidiu
Date: 07/01/21 05:21:23
Modified: src/main/org/jboss/remoting Tag: remoting_2_x Client.java
LeasePinger.java
Log:
Minor refactoring and validation of http://jira.jboss.com/jira/browse/JBREM-657.
Revision Changes Path
No revision
No revision
1.53.2.19 +169 -164 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.18
retrieving revision 1.53.2.19
diff -u -b -r1.53.2.18 -r1.53.2.19
--- Client.java 21 Jan 2007 08:38:32 -0000 1.53.2.18
+++ Client.java 21 Jan 2007 10:21:23 -0000 1.53.2.19
@@ -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.18 $
+ * @version $Revision: 1.53.2.19 $
*/
public class Client implements Externalizable
{
@@ -439,44 +439,21 @@
*/
public void disconnect()
{
- doDisconnect(false);
+ disconnectInternal(false);
}
/**
- * 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.
+ * 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.
+ * 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()
{
- doDisconnect(true);
- }
-
- protected void doDisconnect(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;
- }
+ disconnectInternal(true);
}
/**
@@ -947,145 +924,20 @@
*/
public void removeListener(InvokerCallbackHandler callbackHandler) throws Throwable
{
- doRemoveListener(callbackHandler, false);
+ removeListenerInternal(callbackHandler, false);
}
/**
- * 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.
+ * 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().
*
- * @param callbackHandler
- * @throws Throwable
+ * 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
{
- doRemoveListener(callbackHandler, true);
- }
-
- protected void doRemoveListener(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
- invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), 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();
- client.invoke(new InternalInvocation(InternalInvocation.REMOVECLIENTLISTENER,
- new Object[]{callbackHandler}),
- 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.");
- }
+ removeListenerInternal(callbackHandler, true);
}
/**
@@ -1446,6 +1298,27 @@
}
}
+ 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;
@@ -1625,5 +1498,137 @@
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 --------------------------------------------------------------------------------
}
1.8.2.7 +28 -26 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.6
retrieving revision 1.8.2.7
diff -u -b -r1.8.2.6 -r1.8.2.7
--- LeasePinger.java 21 Jan 2007 08:38:32 -0000 1.8.2.6
+++ LeasePinger.java 21 Jan 2007 10:21:23 -0000 1.8.2.7
@@ -139,8 +139,8 @@
Map clientMap = new HashMap();
clientMap.put(ClientHolder.CLIENT_HOLDER_KEY, holder);
- InvocationRequest ir =
- new InvocationRequest(this.invokerSessionID, null, "$DISCONNECT$", clientMap, null, null);
+ InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$DISCONNECT$",
+ clientMap, null, null);
invoker.invoke(ir);
if(trace) { log.trace(this + " sent out disconnect message to server for lease tied to client with session ID " + sessionID); }
@@ -148,7 +148,8 @@
catch (Throwable throwable)
{
log.warn(this + " failed sending disconnect for client lease for " +
- "client with session ID " + sessionID); }
+ "client with session ID " + sessionID);
+ }
}
else
{
@@ -228,37 +229,38 @@
private synchronized void sendClientPing()
{
- if (invoker != null)
- {
try
{
if(trace)
{
- String clientSessionIds = "";
+ StringBuffer sb = new StringBuffer();
if(clients != null)
{
for(Iterator i = clients.values().iterator(); i.hasNext(); )
{
ClientHolder h = (ClientHolder)i.next();
- clientSessionIds = clientSessionIds + h.getSessionId() + "\n";
+ sb.append(" ").append(h.getSessionId()).append('\n');
}
}
log.trace(this + " sending ping to server. Currently managing lease " +
- "for following clients:\n" + clientSessionIds);
+ "for following clients:\n" + sb.toString());
}
Map clientsClone = new ConcurrentHashMap(clients);
Map requestClients = new ConcurrentHashMap();
requestClients.put(ClientHolder.CLIENT_HOLDER_KEY, clientsClone);
+
InvocationRequest ir =
new InvocationRequest(invokerSessionID, null, "$PING$", requestClients, null, null);
+
invoker.invoke(ir);
+
+ if(trace) { log.trace(this + " successfully pinged the server"); }
}
- catch (Throwable throwable)
+ catch (Throwable t)
{
- log.warn(this + " failed to send lease ping to server");
- }
+ log.warn(this + " failed to ping to server", t);
}
}
More information about the jboss-cvs-commits
mailing list