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

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Wed Jan 19 23:59:22 EST 2011


Author: ron.sigal at jboss.com
Date: 2011-01-19 23:59:22 -0500 (Wed, 19 Jan 2011)
New Revision: 6210

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
Log:
JBREM-1267: Added disconnectAfterUse option.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java	2011-01-20 04:27:54 UTC (rev 6209)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java	2011-01-20 04:59:22 UTC (rev 6210)
@@ -116,6 +116,11 @@
     */
    public static final String IGNORE_ERROR_RESPONSE_MESSAGE = "ignoreErrorResponseMessage";
    
+   /**
+    * Specifies whether the HttpURLConnection should be disconnected after the invocation.
+    */
+   public static final String DISCONNECT_AFTER_USE = "disconnectAfterUse";
+   
    protected static final Logger log = Logger.getLogger(HTTPClientInvoker.class);
    
    protected boolean noThrowOnError;
@@ -123,6 +128,7 @@
    protected boolean unmarshalNullStream = true;
    protected boolean useRemotingContentType = false;
    protected boolean ignoreErrorResponseMessage = false;
+   protected boolean disconnectAfterUse = false;
    
    private Object timeoutThreadPoolLock = new Object();
    private ThreadPool timeoutThreadPool;
@@ -162,66 +168,74 @@
 
       final HttpURLConnection conn = createURLConnection(validatedUrl, metadata);
       
-      int simulatedTimeout = getSimulatedTimeout(configuration, metadata, conn);
-      
-      if (simulatedTimeout <= 0)
-      {
-         return makeInvocation(conn, validatedUrl, invocation, metadata, marshaller, unmarshaller, true);
-      }
-      else
-      {
-         if (log.isTraceEnabled()) log.trace("using simulated timeout: " + simulatedTimeout);
-         class Holder {public Object value;}
-         final Holder resultHolder = new Holder();
-         final Map finalMetadata = metadata;
-         
-         Runnable r = new Runnable()
+      try {
+         int simulatedTimeout = getSimulatedTimeout(configuration, metadata, conn);
+
+         if (simulatedTimeout <= 0)
          {
-            public void run()
+            return makeInvocation(conn, validatedUrl, invocation, metadata, marshaller, unmarshaller, true);
+         }
+         else
+         {
+            if (log.isTraceEnabled()) log.trace("using simulated timeout: " + simulatedTimeout);
+            class Holder {public Object value;}
+            final Holder resultHolder = new Holder();
+            final Map finalMetadata = metadata;
+
+            Runnable r = new Runnable()
             {
-               try
+               public void run()
                {
-                  resultHolder.value = useHttpURLConnection(conn, invocation, finalMetadata, marshaller, unmarshaller);
-                  if (log.isTraceEnabled()) log.trace("result: " + resultHolder.value);
+                  try
+                  {
+                     resultHolder.value = useHttpURLConnection(conn, invocation, finalMetadata, marshaller, unmarshaller);
+                     if (log.isTraceEnabled()) log.trace("result: " + resultHolder.value);
+                  }
+                  catch (Exception e)
+                  {
+                     resultHolder.value = e;
+                     if (log.isTraceEnabled()) log.trace("exception: " + e); 
+                  }
                }
-               catch (Exception e)
-               {
-                  resultHolder.value = e;
-                  if (log.isTraceEnabled()) log.trace("exception: " + e); 
-               }
+            };
+
+            // BasicThreadPool timeout mechanism depends on the interrupted status of
+            // the running thread.
+            Thread.interrupted();
+
+            ThreadPool pool = getTimeoutThreadPool();
+            WaitingTaskWrapper wrapper = new WaitingTaskWrapper(r, simulatedTimeout);
+            if (log.isTraceEnabled()) log.trace("starting task in thread pool");
+            pool.runTaskWrapper(wrapper);
+            if (log.isTraceEnabled()) log.trace("task finished in thread pool");
+
+            Object result = resultHolder.value;
+            if (result == null)
+            {
+               if (log.isDebugEnabled()) log.debug("invocation timed out");
+               Exception cause = new SocketTimeoutException("timed out");
+               throw new CannotConnectException("Can not connect http client invoker.", cause);
             }
-         };
-         
-         // BasicThreadPool timeout mechanism depends on the interrupted status of
-         // the running thread.
-         Thread.interrupted();
-         
-         ThreadPool pool = getTimeoutThreadPool();
-         WaitingTaskWrapper wrapper = new WaitingTaskWrapper(r, simulatedTimeout);
-         if (log.isTraceEnabled()) log.trace("starting task in thread pool");
-         pool.runTaskWrapper(wrapper);
-         if (log.isTraceEnabled()) log.trace("task finished in thread pool");
-         
-         Object result = resultHolder.value;
-         if (result == null)
-         {
-            if (log.isDebugEnabled()) log.debug("invocation timed out");
-            Exception cause = new SocketTimeoutException("timed out");
-            throw new CannotConnectException("Can not connect http client invoker.", cause);
+            else if (result instanceof IOException)
+            {
+               throw (IOException) result;
+            }
+            else if (result instanceof RuntimeException)
+            {
+               throw (RuntimeException) result;
+            }
+            else
+            {
+               if (log.isTraceEnabled()) log.trace("returning result: " + result);
+               return result;
+            }
          }
-         else if (result instanceof IOException)
+      }
+      finally {
+         if (disconnectAfterUse)
          {
-            throw (IOException) result;
+            conn.disconnect();
          }
-         else if (result instanceof RuntimeException)
-         {
-            throw (RuntimeException) result;
-         }
-         else
-         {
-            if (log.isTraceEnabled()) log.trace("returning result: " + result);
-            return result;
-         }
       }
    }
 
@@ -1100,6 +1114,22 @@
                      val + " to a boolean value.");
          }
       }
+      
+      val = configuration.get(DISCONNECT_AFTER_USE);
+      if (val != null)
+      {
+         try
+         {
+            disconnectAfterUse = Boolean.valueOf((String)val).booleanValue();
+            log.debug(this + " setting disconnectAfterUse to " + disconnectAfterUse);
+         }
+         catch (Exception e)
+         {
+            log.warn(this + " could not convert " + 
+                     DISCONNECT_AFTER_USE + " value of " +
+                     val + " to a boolean value.");
+         }
+      }
    }
    
    /**



More information about the jboss-remoting-commits mailing list