[jboss-remoting-commits] JBoss Remoting SVN: r4212 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Wed May 21 23:35:00 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-05-21 23:35:00 -0400 (Wed, 21 May 2008)
New Revision: 4212

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
Log:
JBREM-982: (1) Introduced variable useOnewayConnectionTimeout; (2) removed some calls to System.currentTimeMillis().

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java	2008-05-22 03:30:08 UTC (rev 4211)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java	2008-05-22 03:35:00 UTC (rev 4212)
@@ -77,6 +77,11 @@
    
    /** Key for setting timeout used by OnewayConnectionTask */
    public static final String ONEWAY_CONNECTION_TIMEOUT = "onewayConnectionTimeout";
+   
+   /** Key to determine if client side oneway invocations should wait to read version.
+    *  See JBREM-706.
+    */
+   public static final String USE_ONEWAY_CONNECTION_TIMEOUT = "useOnewayConnectionTimeout";
 
    /**
     * Default value for enable TCP nodelay. Value is false.
@@ -102,7 +107,7 @@
    public static final int MAX_POOL_SIZE = 50;
 
    /** Default timeout value used by OnewayConnectionTask.  Value is 2 seconds. */
-   public static final int ONEWAY_CONNECTION_TIMEOUT_DEFAULT = 2000;
+   public static final int ONEWAY_CONNECTION_TIMEOUT_DEFAULT = 5000;
 
    // Static ---------------------------------------------------------------------------------------
 
@@ -188,7 +193,7 @@
    // flag being set on true by a disconnect request. If trying to create a connection goes on in a
    // loop and a disconnect request arrives, this flag will be used to sent this information into
    // the connect loop
-   private volatile boolean bailOut;
+   // private volatile boolean bailOut;
 
    /**
     * Indicates if will check the socket connection when getting from pool by sending byte over the
@@ -207,6 +212,7 @@
    protected int numberOfCallRetries;
    protected int maxPoolSize;
    protected int onewayConnectionTimeout;
+   protected boolean useOnewayConnectionTimeout = false;
 
    /**
     * Pool for this invoker. This is shared between all instances of proxies attached to a specific
@@ -378,7 +384,7 @@
    public synchronized void disconnect()
    {
       log.debug(this + " disconnecting ...");
-      bailOut = true;
+//      bailOut = true;
       super.disconnect();
    }
 
@@ -583,6 +589,22 @@
                      val + " to an int value");
          }
       }
+      
+      // look for useOnewayConnectionTimeout param
+      val = params.get(USE_ONEWAY_CONNECTION_TIMEOUT);
+      if (val != null)
+      {
+         try
+         {
+            useOnewayConnectionTimeout = Boolean.valueOf((String)val).booleanValue();
+            log.debug(this + " setting useOnewayConnectionTimeout to " + useOnewayConnectionTimeout);
+         }
+         catch (Exception e)
+         {
+            log.warn(this + " could not convert " + USE_ONEWAY_CONNECTION_TIMEOUT + " value of " +
+                     val + " to a boolean value");
+         }
+      }
    }
 
    protected ServerAddress createServerAddress(InetAddress addr, int port)
@@ -660,7 +682,6 @@
                               Marshaller marshaller, UnMarshaller unmarshaller)
          throws IOException, ConnectionFailedException, ClassNotFoundException
    {
-      long start = System.currentTimeMillis();
       SocketWrapper socketWrapper = null;
       Object response = null;
       boolean oneway = false;
@@ -669,6 +690,7 @@
       int tempTimeout = -1;
       int timeLeft = -1;
       int savedTimeout = -1;
+      long start = -1;
 
       if(metadata != null)
       {
@@ -697,6 +719,11 @@
             }
          }
       }
+      
+      if (tempTimeout >= 0)
+      {
+         start = System.currentTimeMillis();
+      }
 
       boolean serverSideOneway = false;
       if (oneway && invocation instanceof InvocationRequest)
@@ -725,10 +752,7 @@
             boolean tryPool = retryCount < (numberOfCallRetries - 1)
                                  || maxPoolSize == 1
                                  || numberOfCallRetries == 1;
-            long l = System.currentTimeMillis();
             socketWrapper = getConnection(marshaller, unmarshaller, tryPool, timeLeft);
-            long d = System.currentTimeMillis() - l;
-            if (trace) log.trace("took " + d + " ms to get socket " + socketWrapper);
          }
          catch (InterruptedException e)
          {
@@ -757,9 +781,6 @@
             socketWrapper.setTimeout(timeLeft);
          }
 
-         long end = System.currentTimeMillis() - start;
-         getSocketTime += end;
-
          try
          {
             int version = getVersion();
@@ -775,23 +796,35 @@
             //TODO: -TME so this is messed up as now ties remoting versioning to using a marshaller type
             versionedWrite(outputStream, marshaller, invocation, version);
 
-            end = System.currentTimeMillis() - start;
-            writeTime += end;
-            start = System.currentTimeMillis();
-
             if (serverSideOneway)
             {
                if(trace) { log.trace(this + " sent oneway invocation, so not waiting for response, returning null"); }
             }
-            else
+            else if (oneway)
             {
-               int onewaySavedTimeout = -1;
-               if (oneway)
+               if (performVersioning && useOnewayConnectionTimeout)
                {
-                  onewaySavedTimeout = socketWrapper.getTimeout();
+                  int onewaySavedTimeout = socketWrapper.getTimeout();
                   socketWrapper.setTimeout(onewayConnectionTimeout);
+                  InputStream inputStream = socketWrapper.getInputStream();
+                  version = readVersion(inputStream);
+                  if (version == -1)
+                  {
+                     throw new EOFException("end of file");
+                  }
+                  if (version == SocketWrapper.CLOSING)
+                  {
+                     log.trace(this + " received version 254: treating as end of file");
+                     throw new EOFException("end of file");
+                  }
+
+                  // Note that if an exception is thrown, the socket is thrown away,
+                  // so there's no need to reset the timeout value.
+                  socketWrapper.setTimeout(onewaySavedTimeout);
                }
-               
+            }
+            else
+            {
                InputStream inputStream = socketWrapper.getInputStream();
                if (performVersioning)
                {
@@ -808,18 +841,8 @@
                }
 
                response = versionedRead(inputStream, unmarshaller, version);
-               
-               // Note that if an exception is thrown, the socket is thrown away,
-               // so there's no need to reset the timeout value.
-               if (oneway)
-               {
-                  socketWrapper.setTimeout(onewaySavedTimeout);
                }
-            }
 
-            end = System.currentTimeMillis() - start;
-            readTime += end;
-
             // Note that resetting the timeout value after closing the socket results
             // in an exception, so the reset is not done in a finally clause.  However,
             // if a catch clause is ever added that does not close the socket, care




More information about the jboss-remoting-commits mailing list