Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 69B12200C77 for ; Mon, 1 May 2017 14:39:21 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 683E0160BC1; Mon, 1 May 2017 12:39:21 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3B4FC160BC0 for ; Mon, 1 May 2017 14:39:20 +0200 (CEST) Received: (qmail 16490 invoked by uid 500); 1 May 2017 12:39:19 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 16473 invoked by uid 99); 1 May 2017 12:39:19 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 May 2017 12:39:19 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 811853A4766 for ; Mon, 1 May 2017 12:39:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170501123918.811853A4766@svn01-us-west.apache.org> archived-at: Mon, 01 May 2017 12:39:21 -0000 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 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>() { void leaseCompleted(final PoolEntry 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 callback) { Args.notNull(endpoint, "Endpoint"); @@ -263,12 +272,19 @@ public class PoolingAsyncClientConnectio } final InetSocketAddress localAddress = route.getLocalSocketAddress(); final Future connectFuture = connectionOperator.connect( - connectionInitiator, host, localAddress, timeout, new FutureCallback() { + connectionInitiator, host, localAddress, timeout, attachment, new FutureCallback() { @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 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> poolEntryRef; + private final String id; InternalConnectionEndpoint(final PoolEntry poolEntry) { this.poolEntryRef = new AtomicReference<>(poolEntry); + this.id = "ep-" + Long.toHexString(COUNT.incrementAndGet()); } @Override public String getId() { - final PoolEntry poolEntry = poolEntryRef.get(); - final ManagedAsyncClientConnection connection = poolEntry != null ? poolEntry.getConnection() : null; - return ConnPoolSupport.getId(connection); + return id; } PoolEntry getPoolEntry() { @@ -400,6 +422,9 @@ public class PoolingAsyncClientConnectio public void shutdown() throws IOException { final PoolEntry 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 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 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 connect( AsyncConnectionEndpoint endpoint, ConnectionInitiator connectionInitiator, TimeValue connectTimeout, + Object attachment, HttpContext context, FutureCallback 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) {