[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...

Ron Sigal ron_sigal at yahoo.com
Sat Jan 20 20:13:03 EST 2007


  User: rsigal  
  Date: 07/01/20 20:13:03

  Modified:    src/main/org/jboss/remoting  Tag: remoting_2_x Client.java
  Log:
  JBREM-657: Added disconnectLocal() and removeListenerLocal().
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.53.2.16 +67 -30    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.15
  retrieving revision 1.53.2.16
  diff -u -b -r1.53.2.15 -r1.53.2.16
  --- Client.java	21 Jan 2007 00:35:27 -0000	1.53.2.15
  +++ Client.java	21 Jan 2007 01:13:03 -0000	1.53.2.16
  @@ -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.15 $
  + * @version $Revision: 1.53.2.16 $
    */
   public class Client implements Externalizable
   {
  @@ -451,11 +451,31 @@
       */
      public void disconnect()
      {
  +      doDisconnect(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.
  +    * 
  +    * 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)
         {
            if(enableLease)
            {
  -            invoker.terminateLease(sessionId);
  +            invoker.terminateLease(sessionId, local);
               enableLease = false;
            }
   
  @@ -942,29 +962,49 @@
       */
      public void removeListener(InvokerCallbackHandler callbackHandler) throws Throwable
      {
  +      doRemoveListener(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.
  +    *
  +    * @param callbackHandler
  +    * @throws Throwable
  +    */
  +   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)
  -
  +            // 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);
  -
  +               CallbackPoller callbackPoller = (CallbackPoller) callbackPollers.remove(callbackHandler);
                  if (callbackPoller != null)
                  {
  -                  callbackPoller.stop();
  +                  callbackPoller.stop(local);
                  }
   
                  listeners.remove(callbackHandler);
  @@ -978,33 +1018,30 @@
               {
                  // 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);
  -
  +                     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);
  +                           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();
  
  
  



More information about the jboss-cvs-commits mailing list