hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1531674 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client: DefaultClientExchangeHandlerImpl.java MainClientExec.java MinimalClientExchangeHandlerImpl.java
Date Sun, 13 Oct 2013 12:17:47 GMT
Author: olegk
Date: Sun Oct 13 12:17:47 2013
New Revision: 1531674

URL: http://svn.apache.org/r1531674
Log:
HTTPASYNC-56: Moved code requiring synchronization out of #connectionAllocated

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExchangeHandlerImpl.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java?rev=1531674&r1=1531673&r2=1531674&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
Sun Oct 13 12:17:47 2013
@@ -44,7 +44,6 @@ import org.apache.http.concurrent.BasicF
 import org.apache.http.concurrent.Cancellable;
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.routing.RouteTracker;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
@@ -54,7 +53,6 @@ import org.apache.http.nio.protocol.Http
 import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
 import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
 import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
-import org.apache.http.protocol.HttpCoreContext;
 
 /**
  * Default implementation of {@link HttpAsyncClientExchangeHandler}.
@@ -271,28 +269,16 @@ class DefaultClientExchangeHandlerImpl<T
                 this.log.debug("[exchange: " + this.state.getId() + "] Connection allocated:
" + managedConn);
             }
             this.managedConn.set(managedConn);
-            this.state.setValidDuration(0);
-            this.state.setNonReusable();
 
             if (this.closed.get()) {
                 releaseConnection();
                 return;
             }
 
-            this.localContext.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn);
-            this.state.setRouteEstablished(this.connmgr.isRouteComplete(managedConn));
-            if (!this.state.isRouteEstablished()) {
-                this.state.setRouteTracker(new RouteTracker(this.state.getRoute()));
-            }
-
             if (!managedConn.isOpen()) {
                 failed(new ConnectionClosedException("Connection closed"));
             } else {
                 managedConn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER,
this);
-                final RequestConfig config = this.localContext.getRequestConfig();
-                if (config.getSocketTimeout() > 0) {
-                    managedConn.setSocketTimeout(config.getSocketTimeout());
-                }
                 managedConn.requestOutput();
             }
         } catch (final RuntimeException runex) {
@@ -328,6 +314,11 @@ class DefaultClientExchangeHandlerImpl<T
             this.log.debug("[exchange: " + this.state.getId() + "] Request connection for
" +
                 this.state.getRoute());
         }
+        this.state.setValidDuration(0);
+        this.state.setNonReusable();
+        this.state.setRouteEstablished(false);
+        this.state.setRouteTracker(null);
+
         final HttpRoute route = this.state.getRoute();
         final Object userToken = this.localContext.getUserToken();
         final RequestConfig config = this.localContext.getRequestConfig();

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java?rev=1531674&r1=1531673&r2=1531674&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java
Sun Oct 13 12:17:47 2013
@@ -77,6 +77,7 @@ import org.apache.http.nio.NHttpClientCo
 import org.apache.http.nio.conn.NHttpClientConnectionManager;
 import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
 import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
+import org.apache.http.protocol.HttpCoreContext;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.ImmutableHttpProcessor;
 import org.apache.http.protocol.RequestTargetHost;
@@ -159,11 +160,18 @@ class MainClientExec implements Internal
             final InternalState state,
             final InternalConnManager connManager) throws IOException, HttpException {
         final HttpClientContext localContext = state.getLocalContext();
-        final HttpAsyncRequestProducer requestProducer = state.getRequestProducer();
         final HttpRoute route = state.getRoute();
-        final RouteTracker routeTracker = state.getRouteTracker();
         final NHttpClientConnection managedConn = connManager.getConnection();
+        if (!state.isRouteEstablished() && state.getRouteTracker() == null) {
+            this.log.debug("Start connection routing");
+            state.setRouteEstablished(this.connmgr.isRouteComplete(managedConn));
+            if (!state.isRouteEstablished()) {
+                state.setRouteTracker(new RouteTracker(route));
+            }
+        }
+
         if (!state.isRouteEstablished()) {
+            final RouteTracker routeTracker = state.getRouteTracker();
             int step;
             loop:
             do {
@@ -216,6 +224,7 @@ class MainClientExec implements Internal
         if (state.isRouteEstablished()) {
             state.incrementExecCount();
             if (state.getExecCount() > 1) {
+                final HttpAsyncRequestProducer requestProducer = state.getRequestProducer();
                 if (!requestProducer.isRepeatable() && state.isRequestContentProduced())
{
                     throw new NonRepeatableRequestException("Cannot retry request " +
                             "with a non-repeatable request entity.");
@@ -250,6 +259,12 @@ class MainClientExec implements Internal
                 this.authenticator.generateAuthResponse(currentRequest, proxyAuthState, localContext);
             }
         }
+
+        localContext.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn);
+        final RequestConfig config = localContext.getRequestConfig();
+        if (config.getSocketTimeout() > 0) {
+            managedConn.setSocketTimeout(config.getSocketTimeout());
+        }
         return currentRequest;
     }
 

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExchangeHandlerImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExchangeHandlerImpl.java?rev=1531674&r1=1531673&r2=1531674&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExchangeHandlerImpl.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExchangeHandlerImpl.java
Sun Oct 13 12:17:47 2013
@@ -173,6 +173,11 @@ class MinimalClientExchangeHandlerImpl<T
             this.connmgr.startRoute(localConn, this.route, this.localContext);
             this.connmgr.routeComplete(localConn, this.route, this.localContext);
         }
+        this.localContext.setAttribute(HttpCoreContext.HTTP_CONNECTION, localConn);
+        final RequestConfig config = this.localContext.getRequestConfig();
+        if (config.getSocketTimeout() > 0) {
+            localConn.setSocketTimeout(config.getSocketTimeout());
+        }
         return this.request;
     }
 
@@ -312,16 +317,10 @@ class MinimalClientExchangeHandlerImpl<T
                 return;
             }
 
-            this.localContext.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn);
-
             if (!managedConn.isOpen()) {
                 failed(new ConnectionClosedException("Connection closed"));
             } else {
                 managedConn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER,
this);
-                final RequestConfig config = this.localContext.getRequestConfig();
-                if (config.getSocketTimeout() > 0) {
-                    managedConn.setSocketTimeout(config.getSocketTimeout());
-                }
                 managedConn.requestOutput();
             }
         } catch (final RuntimeException runex) {



Mime
View raw message