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

Ron Sigal ron_sigal at yahoo.com
Fri Feb 16 00:04:02 EST 2007


  User: rsigal  
  Date: 07/02/16 00:04:02

  Modified:    src/main/org/jboss/remoting/transport/socket  Tag:
                        remoting_2_x MicroSocketClientInvoker.java
  Log:
  JBREM-657:  (1) Changed getConnection() so that there is no i/o in synchronized block.  (2) Synchronized access to usedPool. (3) In clearpools() remove pools from list.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.16.2.23 +72 -47    JBossRemoting/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MicroSocketClientInvoker.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java,v
  retrieving revision 1.16.2.22
  retrieving revision 1.16.2.23
  diff -u -b -r1.16.2.22 -r1.16.2.23
  --- MicroSocketClientInvoker.java	14 Feb 2007 21:17:41 -0000	1.16.2.22
  +++ MicroSocketClientInvoker.java	16 Feb 2007 05:04:02 -0000	1.16.2.23
  @@ -36,7 +36,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.16.2.22 $
  + * @version $Revision: 1.16.2.23 $
    */
   public class MicroSocketClientInvoker extends RemoteClientInvoker
   {
  @@ -156,6 +156,7 @@
   
               if (trace) { log.trace("clearing pool for " + sa); }
               clearPool(sa);
  +            i.remove();
            }
         }
      }
  @@ -579,8 +580,11 @@
               try
               {
                  socketWrapper.close();
  +               synchronized (usedPoolLock)
  +               {
                  usedPooled--;
               }
  +            }
               catch (Exception ex)
               {
                  if (trace) { log.trace(this + " couldn't successfully close its socketWrapper", ex); }
  @@ -606,8 +610,11 @@
               try
               {
                  socketWrapper.close();
  +               synchronized (usedPoolLock)
  +               {
                  usedPooled--;
               }
  +            }
               catch (Exception ignored)
               {
               }
  @@ -714,18 +721,38 @@
               if (pool.size() > 0)
               {
                  pooled = getPooledConnection();
  +               if (trace) log.trace(this + " reusing pooled connection: " + pooled);
               }
            }
   
  +         boolean retry = false;
            synchronized(usedPoolLock)
            {
               if (pooled != null)
               {
                  usedPooled++;
  +               if (trace) log.trace(this + " got a socket, usedPooled: " + usedPooled);
                  break;
               }
  -            else if (usedPooled < maxPoolSize)
  +            if (usedPooled < maxPoolSize)
               {
  +               // Try to get a socket.
  +               usedPooled++;
  +               if (trace) log.trace(this + " getting a socket, usedPooled: " + usedPooled);
  +            }
  +            else
  +            {
  +               retry = true; 
  +               if (trace) log.trace(this + " will try again to get a socket");
  +            }
  +         }
  +         
  +         if (retry)
  +         {
  +            Thread.sleep(1000);
  +            continue;
  +         }
  +
                  // If no connection in pool and all pooled connections not in use, then need create
                  // a new connection which will be latered returned to the pool (thus filling out the
                  // pool, since starts out empty).
  @@ -736,12 +763,17 @@
                  {
                     if (trace) { log.trace(this + " creating socket " + (counter++) + ", attempt " + (i + 1)); }
                     socket = createSocket(address.address, address.port);
  +            if (trace) log.trace(this + " created socket: " + socket);
                  }
                  catch (Exception ex)
                  {
                     log.debug(this + " got Exception " + ex + ", creation attempt took " +
                        (System.currentTimeMillis() - timestamp) + " ms");
   
  +            synchronized(usedPoolLock)
  +            {
  +               usedPooled--;
  +            }
                     if (i + 1 < numberOfRetries)
                     {
                        Thread.sleep(1);
  @@ -765,15 +797,8 @@
                  metadata.put(SocketWrapper.TEMP_TIMEOUT, new Integer(tempTimeout));
   
                  pooled = createClientSocket(socket, address.timeout, metadata);
  -               usedPooled++;
                  break;
               }
  -         }
  -
  -         // Waiting 1 second (numberOfRetries along with 1 second wait determines timeout on getting
  -         // pooled connection)
  -         Thread.sleep(1000);
  -      }
   
         if (pooled == null)
         {
  
  
  



More information about the jboss-cvs-commits mailing list