hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1793320 [5/5] - in /httpcomponents/httpclient/trunk: httpclient5-testing/src/main/java/org/apache/hc/client5/testing/async/ httpclient5-testing/src/main/java/org/apache/hc/client5/testing/classic/ httpclient5-testing/src/test/java/org/apac...
Date Mon, 01 May 2017 12:39:18 GMT
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java?rev=1793320&r1=1793319&r2=1793320&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/AsyncClientConnectionOperator.java
Mon May  1 12:39:16 2017
@@ -74,6 +74,7 @@ final class AsyncClientConnectionOperato
             final HttpHost host,
             final SocketAddress localAddress,
             final TimeValue connectTimeout,
+            final Object attachment,
             final FutureCallback<ManagedAsyncClientConnection> callback) {
         Args.notNull(connectionInitiator, "Connection initiator");
         Args.notNull(host, "Host");
@@ -104,7 +105,8 @@ final class AsyncClientConnectionOperato
                         host,
                         remoteAddress,
                         localAddress,
-                        null, new SessionRequestCallback() {
+                        attachment,
+                        new SessionRequestCallback() {
 
                             @Override
                             public void completed(final SessionRequest request) {
@@ -116,7 +118,7 @@ final class AsyncClientConnectionOperato
                                             host,
                                             session.getLocalAddress(),
                                             session.getRemoteAddress(),
-                                            null);
+                                            request.getAttachment());
                                 }
                                 future.completed(connection);
                             }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/ManagedAsyncClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/ManagedAsyncClientConnection.java?rev=1793320&r1=1793319&r2=1793320&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/ManagedAsyncClientConnection.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/ManagedAsyncClientConnection.java
Mon May  1 12:39:16 2017
@@ -39,6 +39,7 @@ import org.apache.hc.core5.http.Endpoint
 import org.apache.hc.core5.http.HttpConnection;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.nio.command.ShutdownCommand;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.reactor.IOEventHandler;
@@ -85,7 +86,7 @@ final class ManagedAsyncClientConnection
             if (log.isDebugEnabled()) {
                 log.debug(getId() + ": Close connection");
             }
-            ioSession.close();
+            ioSession.addFirst(new ShutdownCommand(ShutdownType.GRACEFUL));
         }
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java?rev=1793320&r1=1793319&r2=1793320&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
Mon May  1 12:39:16 2017
@@ -31,6 +31,7 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.hc.client5.http.DnsResolver;
@@ -151,10 +152,14 @@ public class PoolingAsyncClientConnectio
                 route, state, timeout, new FutureCallback<PoolEntry<HttpRoute, ManagedAsyncClientConnection>>()
{
 
                     void leaseCompleted(final PoolEntry<HttpRoute, ManagedAsyncClientConnection>
poolEntry) {
-                        resultFuture.completed(new InternalConnectionEndpoint(poolEntry));
                         if (log.isDebugEnabled()) {
                             log.debug("Connection leased: " + ConnPoolSupport.formatStats(poolEntry.getConnection(),
route, state, pool));
                         }
+                        final AsyncConnectionEndpoint endpoint = new InternalConnectionEndpoint(poolEntry);
+                        if (log.isDebugEnabled()) {
+                            log.debug(ConnPoolSupport.getId(endpoint) + ": acquired " + ConnPoolSupport.getId(poolEntry.getConnection()));
+                        }
+                        resultFuture.completed(endpoint);
                     }
 
                     @Override
@@ -209,6 +214,9 @@ public class PoolingAsyncClientConnectio
         if (entry == null) {
             return;
         }
+        if (log.isDebugEnabled()) {
+            log.debug(ConnPoolSupport.getId(endpoint) + ": endpoint discarded");
+        }
         final ManagedAsyncClientConnection connection = entry.getConnection();
         boolean reusable = connection != null && connection.isOpen();
         try {
@@ -242,6 +250,7 @@ public class PoolingAsyncClientConnectio
             final AsyncConnectionEndpoint endpoint,
             final ConnectionInitiator connectionInitiator,
             final TimeValue timeout,
+            final Object attachment,
             final HttpContext context,
             final FutureCallback<AsyncConnectionEndpoint> callback) {
         Args.notNull(endpoint, "Endpoint");
@@ -263,12 +272,19 @@ public class PoolingAsyncClientConnectio
         }
         final InetSocketAddress localAddress = route.getLocalSocketAddress();
         final Future<ManagedAsyncClientConnection> connectFuture = connectionOperator.connect(
-                connectionInitiator, host, localAddress, timeout, new FutureCallback<ManagedAsyncClientConnection>()
{
+                connectionInitiator, host, localAddress, timeout, attachment, new FutureCallback<ManagedAsyncClientConnection>()
{
 
                     @Override
                     public void completed(final ManagedAsyncClientConnection connection)
{
-                        poolEntry.assignConnection(connection);
-                        resultFuture.completed(new InternalConnectionEndpoint(poolEntry));
+                        try {
+                            if (log.isDebugEnabled()) {
+                                log.debug(ConnPoolSupport.getId(internalEndpoint) + ": connected
" + ConnPoolSupport.getId(connection));
+                            }
+                            poolEntry.assignConnection(connection);
+                            resultFuture.completed(internalEndpoint);
+                        } catch (final RuntimeException ex) {
+                            resultFuture.failed(ex);
+                        }
                     }
 
                     @Override
@@ -294,7 +310,11 @@ public class PoolingAsyncClientConnectio
         final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
         final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry = internalEndpoint.getValidatedPoolEntry();
         final HttpRoute route = poolEntry.getRoute();
+        final ManagedAsyncClientConnection connection = poolEntry.getConnection();
         connectionOperator.upgrade(poolEntry.getConnection(), route.getTargetHost());
+        if (log.isDebugEnabled()) {
+            log.debug(ConnPoolSupport.getId(internalEndpoint) + ": upgraded " + ConnPoolSupport.getId(connection));
+        }
     }
 
     @Override
@@ -362,19 +382,21 @@ public class PoolingAsyncClientConnectio
         this.validateAfterInactivity = validateAfterInactivity;
     }
 
+    private static final AtomicLong COUNT = new AtomicLong(0);
+
     class InternalConnectionEndpoint extends AsyncConnectionEndpoint implements Identifiable
{
 
         private final AtomicReference<PoolEntry<HttpRoute, ManagedAsyncClientConnection>>
poolEntryRef;
+        private final String id;
 
         InternalConnectionEndpoint(final PoolEntry<HttpRoute, ManagedAsyncClientConnection>
poolEntry) {
             this.poolEntryRef = new AtomicReference<>(poolEntry);
+            this.id = "ep-" + Long.toHexString(COUNT.incrementAndGet());
         }
 
         @Override
         public String getId() {
-            final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry = poolEntryRef.get();
-            final ManagedAsyncClientConnection connection = poolEntry != null ? poolEntry.getConnection()
: null;
-            return ConnPoolSupport.getId(connection);
+            return id;
         }
 
         PoolEntry<HttpRoute, ManagedAsyncClientConnection> getPoolEntry() {
@@ -400,6 +422,9 @@ public class PoolingAsyncClientConnectio
         public void shutdown() throws IOException {
             final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry = poolEntryRef.get();
             if (poolEntry != null) {
+                if (log.isDebugEnabled()) {
+                    log.debug(id + ": shutdown " + ShutdownType.IMMEDIATE);
+                }
                 poolEntry.discardConnection(ShutdownType.IMMEDIATE);
             }
         }
@@ -408,6 +433,9 @@ public class PoolingAsyncClientConnectio
         public void close() throws IOException {
             final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry = poolEntryRef.get();
             if (poolEntry != null) {
+                if (log.isDebugEnabled()) {
+                    log.debug(id + ": shutdown " + ShutdownType.GRACEFUL);
+                }
                 poolEntry.discardConnection(ShutdownType.GRACEFUL);
             }
         }
@@ -416,10 +444,18 @@ public class PoolingAsyncClientConnectio
         public boolean isConnected() {
             final PoolEntry<HttpRoute, ManagedAsyncClientConnection> poolEntry = poolEntryRef.get();
             if (poolEntry == null) {
-                throw new ConnectionShutdownException();
+                return false;
             }
             final ManagedAsyncClientConnection connection = poolEntry.getConnection();
-            return connection != null && connection.isOpen();
+            if (connection == null) {
+                return false;
+            } else {
+                if (!connection.isOpen()) {
+                    poolEntry.discardConnection(ShutdownType.IMMEDIATE);
+                    return false;
+                }
+                return true;
+            }
         }
 
         @Override
@@ -430,6 +466,9 @@ public class PoolingAsyncClientConnectio
         @Override
         public void execute(final AsyncClientExchangeHandler exchangeHandler, final HttpContext
context) {
             final ManagedAsyncClientConnection connection = getValidatedPoolEntry().getConnection();
+            if (log.isDebugEnabled()) {
+                log.debug(id + ": executing exchange " + ConnPoolSupport.getId(exchangeHandler)
+ " over " + ConnPoolSupport.getId(connection));
+            }
             connection.submitCommand(new ExecutionCommand(exchangeHandler, context));
         }
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecRuntimeImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecRuntimeImpl.java?rev=1793320&r1=1793319&r2=1793320&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecRuntimeImpl.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ExecRuntimeImpl.java
Mon May  1 12:39:16 2017
@@ -47,6 +47,7 @@ import org.apache.hc.core5.http.Connecti
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
 import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TimeValue;
 import org.apache.logging.log4j.Logger;
 
@@ -89,6 +90,7 @@ class ExecRuntimeImpl implements ExecRun
 
     @Override
     public void acquireConnection(final HttpRoute route, final Object object, final HttpClientContext
context) throws IOException {
+        Args.notNull(route, "Route");
         if (endpointRef.get() == null) {
             final LeaseRequest connRequest = manager.lease(route, object);
             state = object;
@@ -104,9 +106,7 @@ class ExecRuntimeImpl implements ExecRun
                 final TimeValue timeout = requestConfig.getConnectionRequestTimeout();
                 final ConnectionEndpoint connectionEndpoint = connRequest.get(timeout.getDuration(),
timeout.getTimeUnit());
                 endpointRef.set(connectionEndpoint);
-                if (!connectionEndpoint.isConnected()) {
-                    reusable = false;
-                }
+                reusable = connectionEndpoint.isConnected();
                 if (cancellableAware != null) {
                     cancellableAware.setCancellable(this);
                 }
@@ -165,6 +165,7 @@ class ExecRuntimeImpl implements ExecRun
         final ConnectionEndpoint endpoint = endpointRef.get();
         if (endpoint != null) {
             endpoint.close();
+            log.debug("Disconnected");
         }
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionManager.java?rev=1793320&r1=1793319&r2=1793320&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionManager.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/nio/AsyncClientConnectionManager.java
Mon May  1 12:39:16 2017
@@ -60,7 +60,7 @@ public interface AsyncClientConnectionMa
      * {@link AsyncConnectionEndpoint#isConnected() disconnected}. The consumer
      * of the endpoint is responsible for fully establishing the route to
      * the endpoint target by calling {@link #connect(AsyncConnectionEndpoint,
-     * ConnectionInitiator, TimeValue, HttpContext, FutureCallback)}
+     * ConnectionInitiator, TimeValue, Object, HttpContext, FutureCallback)}
      * in order to connect directly to the target or to the first proxy hop,
      * and optionally calling {@link #upgrade(AsyncConnectionEndpoint, HttpContext)}
      * method to upgrade the underlying transport to Transport Layer Security
@@ -100,12 +100,14 @@ public interface AsyncClientConnectionMa
      * @param endpoint      the managed endpoint.
      * @param connectTimeout connect timeout.
      * @param context the actual HTTP context.
+     * @param attachment connect request attachment.
      * @param callback result callback.
      */
     Future<AsyncConnectionEndpoint> connect(
             AsyncConnectionEndpoint endpoint,
             ConnectionInitiator connectionInitiator,
             TimeValue connectTimeout,
+            Object attachment,
             HttpContext context,
             FutureCallback<AsyncConnectionEndpoint> callback);
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsStrategy.java?rev=1793320&r1=1793319&r2=1793320&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsStrategy.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/H2TlsStrategy.java
Mon May  1 12:39:16 2017
@@ -131,7 +131,7 @@ public class H2TlsStrategy implements Tl
             final SocketAddress localAddress,
             final SocketAddress remoteAddress,
             final Object attachment) {
-        tlsSession.startTls(sslContext, sslBufferManagement, H2TlsSupport.enforceRequirements(null,
new SSLSessionInitializer() {
+        tlsSession.startTls(sslContext, sslBufferManagement, H2TlsSupport.enforceRequirements(attachment,
new SSLSessionInitializer() {
 
             @Override
             public void initialize(final NamedEndpoint endpoint, final SSLEngine sslEngine)
{



Mime
View raw message