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

Ron Sigal ron_sigal at yahoo.com
Wed Aug 29 02:12:11 EDT 2007


  User: rsigal  
  Date: 07/08/29 02:12:11

  Modified:    src/main/org/jboss/remoting  Tag: remoting_2_x
                        MicroRemoteClientInvoker.java
  Log:
  JBREM-783:  Synchronized with branch remoting_2_2_0_GA: reverted to version before changes made for JBREM-783.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.16  +23 -141   JBossRemoting/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MicroRemoteClientInvoker.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java,v
  retrieving revision 1.7.2.15
  retrieving revision 1.7.2.16
  diff -u -b -r1.7.2.15 -r1.7.2.16
  --- MicroRemoteClientInvoker.java	2 Aug 2007 06:36:38 -0000	1.7.2.15
  +++ MicroRemoteClientInvoker.java	29 Aug 2007 06:12:11 -0000	1.7.2.16
  @@ -27,7 +27,7 @@
    *
    * @author <a href="mailto:jhaynie at vocalocity.net">Jeff Haynie</a>
    * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
  - * @version $Revision: 1.7.2.15 $
  + * @version $Revision: 1.7.2.16 $
    */
   public abstract class MicroRemoteClientInvoker extends AbstractInvoker implements ClientInvoker
   {
  @@ -41,7 +41,6 @@
      private final Object clientLeaseLock = new Object();
      private LeasePinger leasePinger = null;
      private String invokerSessionID = new GUID().toString();
  -   private Exception leasePingerException;
   
      public MicroRemoteClientInvoker(InvokerLocator locator)
      {
  @@ -312,53 +311,24 @@
   
      public void terminateLease(String sessionId, int disconnectTimeout)
      {
  -      // The synchronization of establishLease() and terminateLease() has been
  -      // reorganized - see JBREM-783.
  -      
  -      // The process of removing an org.jboss.remoting.Client from a LeasePinger
  -      // is now divided into two steps: (1) LeasePinger.removeClient(), which
  -      // just removes a reference to the Client in a LeasePinger map, and
  -      // (2) leasePinger.disconnectClient(), which sends a message to the server.
  -      // Only step (1) takes place inside the synchronization block.  If it is
  -      // determined in step (1) that the last Client has been removed from the
  -      // LeasePinger, then the instance variable leasePinger is set to null.  
  -      // Once leasePinger is set to null, the next Client that calls 
  -      // establishLease() will have to create a new LeasePinger, which it will
  -      // be able to do without waiting for the completion of the network i/o
  -      // performed in terminateLease().
  -      
  -      LeasePinger localPinger = null;
  -      boolean isLastClientLease = false;
  -      
         synchronized(clientLeaseLock)
         {
  -         localPinger = leasePinger;
  -         
            if(leasePinger != null)
            {
  -            isLastClientLease = leasePinger.removeClient(sessionId);
  +            leasePinger.setDisconnectTimeout(disconnectTimeout);
  +            boolean isLastClientLease = leasePinger.removeClient(sessionId);
               if(isLastClientLease)
               {
  -               leasePinger = null;
  -            }
  -         }
  -      }
  -
  -      if (localPinger != null)
  -      {
  -         localPinger.setDisconnectTimeout(disconnectTimeout);
  -         localPinger.disconnectClient(sessionId);
  -
  -         if (isLastClientLease)
  -         {
               try
               {
  -               localPinger.stopPing();
  +                  leasePinger.stopPing();
               }
               catch (Exception e)
               {
                  log.error("error shutting down lease pinger");
               }
  +               leasePinger = null;
  +            }
            }
         }
      }
  @@ -379,18 +349,6 @@
      public void establishLease(String clientSessionID, Map configuration, long leasePeriod)
         throws Throwable
      {  
  -      // The synchronization in establishLease() and terminateLease() has been 
  -      // reorganized - see JBREM-783.
  -      
  -      // The set of org.jboss.remoting.Client's entering
  -      // establishLease() partitioned as follows: (1) the first Client to enter
  -      // the synchronization block and find leasePinger == null, and (2) all other
  -      // Client's.  The first client is responsible for creating the LeasePinger,
  -      // including all necessary network i/o, and the other Client's wait until the
  -      // LeasePinger has been started.  However, the network i/o does not take place 
  -      // inside the synchronization block.  The advantage is that other Client's
  -      // can call terminateLease() without being blocked.
  -      
         synchronized (clientLeaseLock)
         {
            // if already have a lease pinger, then already have a client with an established
  @@ -399,64 +357,7 @@
            {
               leasePinger.addClient(clientSessionID, configuration, leasePeriod);
               log.debug(this + " added client with session ID " + clientSessionID + " to the lease pinger");
  -            
  -            if (leasePinger.isStarted())
  -               return;
  -            
  -            if (leasePingerException != null)
  -               throw leasePingerException;
  -            
  -            while (true)
  -            {
  -               try
  -               {
  -                  clientLeaseLock.wait();
  -               }
  -               catch (InterruptedException ignored) {}
  -               
  -               if (leasePinger == null || leasePinger.isStarted())
                     return;
  -               
  -               if (leasePingerException != null)
  -                  throw leasePingerException;
  -            }
  -         }
  -         else
  -         {
  -            leasePingerException = null;
  -            leasePinger = new LeasePinger(this, invokerSessionID);
  -         }
  -      }
  -      
  -      InvocationRequest ir =
  -         new InvocationRequest(invokerSessionID, null, "$PING$", null, new HashMap(), null);
  -      
  -      int clientCount;
  -      int attemptCount = 0;
  -      
  -      while (true)
  -      {  
  -         Exception tempException = null;
  -         
  -         synchronized (clientLeaseLock)
  -         {
  -            clientCount = leasePinger.getClients().size();
  -            if (attemptCount++ > clientCount)
  -            {
  -               if (tempException == null)
  -               {
  -                  leasePingerException = new Exception("Error setting up client lease");
  -               }
  -               else
  -               {
  -                  leasePingerException = tempException;
  -               }
  -               
  -               leasePinger.purgeClients();
  -               leasePinger = null;
  -               clientLeaseLock.notifyAll();
  -               throw leasePingerException;
  -            }
            }
            
            try
  @@ -466,6 +367,9 @@
               // configuration should NOT be passed as want ping to be specific to client invoker
               // and NOT to the client.
   
  +            InvocationRequest ir =
  +               new InvocationRequest(invokerSessionID, null, "$PING$", null, new HashMap(), null);
  +
               Object ret = invoke(ir);
   
               if (ret instanceof InvocationResponse)
  @@ -488,41 +392,19 @@
                        }
                     }
   
  -                  leasePinger.setDefaultLeasePeriod(defaultLeasePeriod);
  -                  
  -                  if(trace) { log.trace("server does have leasing enabled (with default lease period of " +
  -                        defaultLeasePeriod + ") and will start a new lease pinger."); }
  +                  if(trace) { log.trace("server does have leasing enabled (with default lease period of " + defaultLeasePeriod + ") and will start a new lease pinger."); }
   
  +                  leasePinger = new LeasePinger(this, invokerSessionID, defaultLeasePeriod);
                     leasePinger.addClient(clientSessionID, configuration, leasePeriod);
  -                  
  -                  synchronized (clientLeaseLock)
  -                  {
                        leasePinger.startPing();
  -                     clientLeaseLock.notifyAll();
  -                     return;
                     }
                  }
  -               else
  -               {
  -                  synchronized (clientLeaseLock)
  -                  {
  -                     leasePinger.purgeClients();
  -                     leasePinger = null;
  -                     clientLeaseLock.notifyAll();
  -                     return;
  -                  }
  -               }
  -            }
  -            else
  -            {
  -               String message = "Error setting up client lease: invalid response from server: " + ret;
  -               tempException = new Exception(message);
  -            }
            }
            catch (Throwable throwable)
            {
  -            tempException = new Exception("Error setting up client lease");
  -            tempException.initCause(throwable);
  +            Exception e = new Exception("Error setting up client lease");
  +            e.initCause(throwable);
  +            throw e;
            }
         }
      }
  
  
  



More information about the jboss-cvs-commits mailing list