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

Ron Sigal ron_sigal at yahoo.com
Sun Mar 11 16:16:40 EDT 2007


  User: rsigal  
  Date: 07/03/11 16:16:40

  Modified:    src/main/org/jboss/remoting/transport/socket 
                        MicroSocketClientInvoker.java
  Log:
  JBREM-598, JBREM-657:  Synched with 2_x branch, including per invocation timeouts.
  
  Revision  Changes    Path
  1.23      +50 -12    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.22
  retrieving revision 1.23
  diff -u -b -r1.22 -r1.23
  --- MicroSocketClientInvoker.java	16 Feb 2007 05:25:29 -0000	1.22
  +++ MicroSocketClientInvoker.java	11 Mar 2007 20:16:40 -0000	1.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.22 $
  + * @version $Revision: 1.23 $
    */
   public class MicroSocketClientInvoker extends RemoteClientInvoker
   {
  @@ -467,6 +467,8 @@
         SocketWrapper socketWrapper = null;
         Object response = null;
         boolean oneway = false;
  +      
  +      // tempTimeout < 0 will indicate there is no per invocation timeout.
         int tempTimeout = -1;
         int savedTimeout = -1;
   
  @@ -503,9 +505,20 @@
   
         for (; retryCount < numberOfCallRetries; retryCount++)
         {
  +         // timeLeft < 0 will indicate that there is no per invocation timeout.
  +         int timeLeft = -1;
  +         if (0 < tempTimeout)
  +         {
  +            // If a per invocation timeout has been set, the time spent retrying
  +            // should count toward the elapsed time.
  +            timeLeft = (int) (tempTimeout - (System.currentTimeMillis() - start));
  +            if (timeLeft <= 0)
  +               break;
  +         }
  +         
            try
            {
  -            socketWrapper = getConnection(marshaller, unmarshaller, tempTimeout);
  +            socketWrapper = getConnection(marshaller, unmarshaller, timeLeft);
            }
            catch (Exception e)
            {
  @@ -517,7 +530,7 @@
            if (tempTimeout >= 0)
            {
               savedTimeout = socketWrapper.getTimeout();
  -            socketWrapper.setTimeout(tempTimeout);
  +            socketWrapper.setTimeout((int) (tempTimeout - (System.currentTimeMillis() - start)));
            }
   
            long end = System.currentTimeMillis() - start;
  @@ -556,6 +569,11 @@
                     {
                        throw new SocketException("end of file");
                     }
  +                  if (version == SocketWrapper.CLOSING)
  +                  {
  +                     log.info("Received version 254: treating as end of file");
  +                     throw new SocketException("end of file");
  +                  }
                  }
   
                  response = versionedRead(inputStream, unmarshaller, version);
  @@ -696,7 +714,7 @@
   
      protected SocketWrapper getConnection(Marshaller marshaller,
                                            UnMarshaller unmarshaller,
  -                                         int tempTimeout)
  +                                         int timeAllowed)
         throws Exception
      {
         SocketWrapper pooled = null;
  @@ -706,6 +724,10 @@
         // to be the most performant. This problem always happens with RMI and seems to have nothing
         // to do with backlog or number of threads waiting in accept() on the server.
   
  +      // If a per socket invocation has been set, the time spent looking for a connection
  +      // should count toward the elapsed time.
  +      long start = System.currentTimeMillis();
  +      
         for (int i = 0; i < numberOfRetries; i++)
         {
            if (bailOut)
  @@ -715,6 +737,15 @@
               break;
            }
   
  +         // timeAllowed < 0 indicates no per invocation timeout has been set.
  +         int timeRemaining = -1;
  +         if (0 <= timeAllowed)
  +         {
  +            timeRemaining = (int) (timeAllowed - (System.currentTimeMillis() - start));
  +            if (timeRemaining <= 0)
  +               break;
  +         }
  +         
            synchronized (pool)
            {
               // if connection within pool, use it
  @@ -737,8 +768,8 @@
               if (usedPooled < maxPoolSize)
               {
                  // Try to get a socket.
  -               usedPooled++;
                  if (trace) log.trace(this + " getting a socket, usedPooled: " + usedPooled);
  +               usedPooled++;
               }
               else
               {
  @@ -754,7 +785,7 @@
            }
   
            // 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
  +         // a new connection which will be later returned to the pool (thus filling out the
            // pool, since starts out empty).
            
            Socket socket = null;
  @@ -762,7 +793,7 @@
            try
            {
               if (trace) { log.trace(this + " creating socket " + (counter++) + ", attempt " + (i + 1)); }
  -            socket = createSocket(address.address, address.port);
  +            socket = createSocket(address.address, address.port, timeRemaining);
               if (trace) log.trace(this + " created socket: " + socket);
            }
            catch (Exception ex)
  @@ -794,7 +825,14 @@
            }
            metadata.put(SocketWrapper.MARSHALLER, marshaller);
            metadata.put(SocketWrapper.UNMARSHALLER, unmarshaller);
  -         metadata.put(SocketWrapper.TEMP_TIMEOUT, new Integer(tempTimeout));
  +         
  +         if (timeAllowed > 0)
  +         {
  +            timeRemaining = (int) (timeAllowed - (System.currentTimeMillis() - start));
  +            if (timeRemaining <= 0)
  +               break;
  +            metadata.put(SocketWrapper.TEMP_TIMEOUT, new Integer(timeRemaining));
  +         }
            
            pooled = createClientSocket(socket, address.timeout, metadata);
            break;
  @@ -803,8 +841,8 @@
         if (pooled == null)
         {
            throw new SocketException("Can not obtain client socket connection from pool. " +
  -            "Have waited " + numberOfRetries + " seconds for available connection (" + usedPooled +
  -            " in use)");
  +            "Have waited " + (System.currentTimeMillis() - start) + 
  +            " milliseconds for available connection (" + usedPooled + "in use)");
         }
         else
         {
  @@ -833,7 +871,7 @@
         return clientSocketWrapper;
      }
   
  -   protected Socket createSocket(String address, int port) throws IOException
  +   protected Socket createSocket(String address, int port, int timeout) throws IOException
      {
         Socket s = new Socket();
         s.setReuseAddress(getReuseAddress());
  
  
  



More information about the jboss-cvs-commits mailing list