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

Ron Sigal ron_sigal at yahoo.com
Wed Feb 21 04:44:37 EST 2007


  User: rsigal  
  Date: 07/02/21 04:44:37

  Modified:    src/main/org/jboss/remoting/transport/socket  Tag:
                        remoting_2_x MicroSocketClientInvoker.java
  Log:
  JBREM-598, JBREM-657: Extended per invocation timeout to account for time getting connection and retrying invocation.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.16.2.24 +44 -11    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.23
  retrieving revision 1.16.2.24
  diff -u -b -r1.16.2.23 -r1.16.2.24
  --- MicroSocketClientInvoker.java	16 Feb 2007 05:04:02 -0000	1.16.2.23
  +++ MicroSocketClientInvoker.java	21 Feb 2007 09:44:37 -0000	1.16.2.24
  @@ -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.23 $
  + * @version $Revision: 1.16.2.24 $
    */
   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;
  @@ -696,7 +709,7 @@
   
      protected SocketWrapper getConnection(Marshaller marshaller,
                                            UnMarshaller unmarshaller,
  -                                         int tempTimeout)
  +                                         int timeAllowed)
         throws Exception
      {
         SocketWrapper pooled = null;
  @@ -706,6 +719,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 +732,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
  @@ -754,7 +780,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 +788,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 +820,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 +836,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 +866,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