hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1793305 [2/5] - in /httpcomponents/httpclient/trunk: ./ httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/ httpclient5-fluent/src/examples/org/apache/hc/client5/http/examples/fluent/ httpclient5-fluent/src/main/java/org...
Date Mon, 01 May 2017 10:47:11 GMT
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java Mon May  1 10:47:09 2017
@@ -30,19 +30,16 @@ package org.apache.hc.client5.http.impl.
 import java.io.Closeable;
 import java.io.IOException;
 import java.net.ProxySelector;
-import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
 import org.apache.hc.client5.http.SchemePortResolver;
 import org.apache.hc.client5.http.config.RequestConfig;
 import org.apache.hc.client5.http.impl.DefaultConnectionKeepAliveStrategy;
 import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
-import org.apache.hc.client5.http.impl.DefaultThreadFactory;
 import org.apache.hc.client5.http.impl.DefaultUserTokenHandler;
 import org.apache.hc.client5.http.impl.IdleConnectionEvictor;
 import org.apache.hc.client5.http.impl.NoopUserTokenHandler;
@@ -55,6 +52,7 @@ import org.apache.hc.client5.http.protoc
 import org.apache.hc.client5.http.protocol.RequestExpectContinue;
 import org.apache.hc.client5.http.protocol.UserTokenHandler;
 import org.apache.hc.client5.http.routing.HttpRoutePlanner;
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
@@ -63,8 +61,7 @@ import org.apache.hc.core5.http.HttpRequ
 import org.apache.hc.core5.http.HttpRequestInterceptor;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpResponseInterceptor;
-import org.apache.hc.core5.http.HttpVersion;
-import org.apache.hc.core5.http.config.ConnectionConfig;
+import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
@@ -73,6 +70,7 @@ import org.apache.hc.core5.http.protocol
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
 import org.apache.hc.core5.http.protocol.RequestUserAgent;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.protocol.H2RequestConnControl;
 import org.apache.hc.core5.http2.protocol.H2RequestContent;
@@ -81,6 +79,7 @@ import org.apache.hc.core5.pool.ConnPool
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOReactorException;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.hc.core5.util.VersionInfo;
 
 /**
@@ -109,12 +108,13 @@ import org.apache.hc.core5.util.VersionI
  */
 public class HttpAsyncClientBuilder {
 
-    private HttpVersion protocolVersion;
+    private HttpVersionPolicy versionPolicy;
     private AsyncClientConnectionManager connManager;
     private boolean connManagerShared;
     private IOReactorConfig ioReactorConfig;
     private H1Config h1Config;
     private H2Config h2Config;
+    private CharCodingConfig charCodingConfig;
     private SchemePortResolver schemePortResolver;
     private ConnectionReuseStrategy reuseStrategy;
     private ConnectionKeepAliveStrategy keepAliveStrategy;
@@ -132,8 +132,7 @@ public class HttpAsyncClientBuilder {
     private RequestConfig defaultRequestConfig;
     private boolean evictExpiredConnections;
     private boolean evictIdleConnections;
-    private long maxIdleTime;
-    private TimeUnit maxIdleTimeUnit;
+    private TimeValue maxIdleTime;
 
     private boolean systemProperties;
     private boolean connectionStateDisabled;
@@ -149,10 +148,26 @@ public class HttpAsyncClientBuilder {
     }
 
     /**
-     * Sets HTTP protocol version.
+     * Sets HTTP protocol version policy.
      */
-    public final HttpAsyncClientBuilder setProtocolVersion(final HttpVersion protocolVersion) {
-        this.protocolVersion = protocolVersion;
+    public final HttpAsyncClientBuilder setVersionPolicy(final HttpVersionPolicy versionPolicy) {
+        this.versionPolicy = versionPolicy;
+        return this;
+    }
+
+    /**
+     * Sets {@link H1Config} configuration.
+     */
+    public final HttpAsyncClientBuilder setH1Config(final H1Config h1Config) {
+        this.h1Config = h1Config;
+        return this;
+    }
+
+    /**
+     * Sets {@link H2Config} configuration.
+     */
+    public final HttpAsyncClientBuilder setH2Config(final H2Config h2Config) {
+        this.h2Config = h2Config;
         return this;
     }
 
@@ -189,32 +204,15 @@ public class HttpAsyncClientBuilder {
     }
 
     /**
-     * Sets {@link H1Config} configuration.
-     * <p>
-     * Please note this setting applies only if {@link #setProtocolVersion(HttpVersion)} is
-     * set to {@code HTTP/1.1} or below.
+     * Sets {@link CharCodingConfig} configuration.
      */
-    public final HttpAsyncClientBuilder setH1Config(final H1Config h1Config) {
-        this.h1Config = h1Config;
-        return this;
-    }
-
-    /**
-     * Sets {@link H2Config} configuration.
-     * <p>
-     * Please note this setting applies only if {@link #setProtocolVersion(HttpVersion)} is
-     * set to {@code HTTP/2} or above.
-     */
-    public final HttpAsyncClientBuilder setH2Config(final H2Config h2Config) {
-        this.h2Config = h2Config;
+    public final HttpAsyncClientBuilder setCharCodingConfig(final CharCodingConfig charCodingConfig) {
+        this.charCodingConfig = charCodingConfig;
         return this;
     }
 
     /**
      * Assigns {@link ConnectionReuseStrategy} instance.
-     * <p>
-     * Please note this setting applies only if {@link #setProtocolVersion(HttpVersion)} is
-     * set to {@code HTTP/1.1} or below.
      */
     public final HttpAsyncClientBuilder setConnectionReuseStrategy(final ConnectionReuseStrategy reuseStrategy) {
         this.reuseStrategy = reuseStrategy;
@@ -396,17 +394,15 @@ public class HttpAsyncClientBuilder {
      * use a shared connection manager.
      *
      * @see #setConnectionManagerShared(boolean)
-     * @see ConnPoolControl#closeIdle(long, TimeUnit)
+     * @see ConnPoolControl#closeIdle(TimeValue)
      *
      * @param maxIdleTime maximum time persistent connections can stay idle while kept alive
      * in the connection pool. Connections whose inactivity period exceeds this value will
      * get closed and evicted from the pool.
-     * @param maxIdleTimeUnit time unit for the above parameter.
      */
-    public final HttpAsyncClientBuilder evictIdleConnections(final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
+    public final HttpAsyncClientBuilder evictIdleConnections(final TimeValue maxIdleTime) {
         this.evictIdleConnections = true;
         this.maxIdleTime = maxIdleTime;
-        this.maxIdleTimeUnit = maxIdleTimeUnit;
         return this;
     }
 
@@ -507,8 +503,7 @@ public class HttpAsyncClientBuilder {
             if (evictExpiredConnections || evictIdleConnections) {
                 if (connManagerCopy instanceof ConnPoolControl) {
                     final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor((ConnPoolControl<?>) connManagerCopy,
-                            maxIdleTime > 0 ? maxIdleTime : 10, maxIdleTimeUnit != null ? maxIdleTimeUnit : TimeUnit.SECONDS,
-                            maxIdleTime, maxIdleTimeUnit);
+                            maxIdleTime,  maxIdleTime);
                     closeablesCopy.add(new Closeable() {
 
                         @Override
@@ -522,47 +517,41 @@ public class HttpAsyncClientBuilder {
             }
             closeablesCopy.add(connManagerCopy);
         }
-        final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
-        final IOEventHandlerFactory ioEventHandlerFactory;
-        if (protocolVersion != null && protocolVersion.greaterEquals(HttpVersion.HTTP_2)) {
-            ioEventHandlerFactory = new DefaultAsyncHttp2ClientEventHandlerFactory(
-                    httpProcessor,
-                    new HandlerFactory<AsyncPushConsumer>() {
-
+        ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;
+        if (reuseStrategyCopy == null) {
+            if (systemProperties) {
+                final String s = System.getProperty("http.keepAlive", "true");
+                if ("true".equalsIgnoreCase(s)) {
+                    reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE;
+                } else {
+                    reuseStrategyCopy = new ConnectionReuseStrategy() {
                         @Override
-                        public AsyncPushConsumer create(final HttpRequest request) throws HttpException {
-                            return pushConsumerRegistry.get(request);
+                        public boolean keepAlive(
+                                final HttpRequest request, final HttpResponse response, final HttpContext context) {
+                            return false;
                         }
-
-                    },
-                    StandardCharsets.US_ASCII,
-                    h2Config != null ? h2Config : H2Config.DEFAULT);
-        } else {
-            ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;
-            if (reuseStrategyCopy == null) {
-                if (systemProperties) {
-                    final String s = System.getProperty("http.keepAlive", "true");
-                    if ("true".equalsIgnoreCase(s)) {
-                        reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE;
-                    } else {
-                        reuseStrategyCopy = new ConnectionReuseStrategy() {
-                            @Override
-                            public boolean keepAlive(
-                                    final HttpRequest request, final HttpResponse response, final HttpContext context) {
-                                return false;
-                            }
-                        };
-                    }
-                } else {
-                    reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE;
+                    };
                 }
+            } else {
+                reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE;
             }
-            ioEventHandlerFactory = new DefaultAsyncHttp1ClientEventHandlerFactory(
-                    httpProcessor,
-                    h1Config != null ? h1Config : H1Config.DEFAULT,
-                    ConnectionConfig.DEFAULT,
-                    reuseStrategyCopy);
         }
+        final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
+        final IOEventHandlerFactory ioEventHandlerFactory = new HttpAsyncClientEventHandlerFactory(
+                httpProcessor,
+                new HandlerFactory<AsyncPushConsumer>() {
+
+                    @Override
+                    public AsyncPushConsumer create(final HttpRequest request) throws HttpException {
+                        return pushConsumerRegistry.get(request);
+                    }
+
+                },
+                versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE,
+                h2Config != null ? h2Config : H2Config.DEFAULT,
+                h1Config != null ? h1Config : H1Config.DEFAULT,
+                charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
+                reuseStrategyCopy);
         try {
             return new InternalHttpAsyncClient(
                     ioEventHandlerFactory,

Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java (from r1790039, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/DefaultAsyncHttp2ClientEventHandlerFactory.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/DefaultAsyncHttp2ClientEventHandlerFactory.java&r1=1790039&r2=1793305&rev=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/DefaultAsyncHttp2ClientEventHandlerFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java Mon May  1 10:47:09 2017
@@ -28,7 +28,7 @@
 package org.apache.hc.client5.http.impl.async;
 
 import java.io.IOException;
-import java.nio.charset.Charset;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.hc.client5.http.impl.ConnPoolSupport;
@@ -38,20 +38,36 @@ import org.apache.hc.client5.http.impl.l
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ConnectionClosedException;
+import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpConnection;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.Http1StreamListener;
+import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory;
+import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestWriterFactory;
+import org.apache.hc.core5.http.impl.nio.DefaultHttpResponseParserFactory;
+import org.apache.hc.core5.http.message.RequestLine;
+import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
 import org.apache.hc.core5.http.nio.HandlerFactory;
+import org.apache.hc.core5.http.nio.NHttpMessageParserFactory;
+import org.apache.hc.core5.http.nio.NHttpMessageWriterFactory;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.frame.FramePrinter;
 import org.apache.hc.core5.http2.frame.RawFrame;
+import org.apache.hc.core5.http2.impl.nio.ClientHttp2StreamMultiplexerFactory;
 import org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiator;
 import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
 import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.util.Args;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -60,7 +76,7 @@ import org.apache.logging.log4j.Logger;
  * @since 5.0
  */
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
-public class DefaultAsyncHttp2ClientEventHandlerFactory implements IOEventHandlerFactory {
+public class HttpAsyncClientEventHandlerFactory implements IOEventHandlerFactory {
 
     private final Logger streamLog = LogManager.getLogger(ClientHttpProtocolNegotiator.class);
     private final Logger wireLog = LogManager.getLogger("org.apache.hc.client5.http.wire");
@@ -71,22 +87,35 @@ public class DefaultAsyncHttp2ClientEven
 
     private final HttpProcessor httpProcessor;
     private final HandlerFactory<AsyncPushConsumer> exchangeHandlerFactory;
-    private final Charset charset;
+    private final HttpVersionPolicy versionPolicy;
     private final H2Config h2Config;
+    private final H1Config h1Config;
+    private final CharCodingConfig charCodingConfig;
+    private final ConnectionReuseStrategy http1ConnectionReuseStrategy;
+    private final NHttpMessageParserFactory<HttpResponse> http1ResponseParserFactory;
+    private final NHttpMessageWriterFactory<HttpRequest> http1RequestWriterFactory;
 
-    DefaultAsyncHttp2ClientEventHandlerFactory(
+    HttpAsyncClientEventHandlerFactory(
             final HttpProcessor httpProcessor,
             final HandlerFactory<AsyncPushConsumer> exchangeHandlerFactory,
-            final Charset charset,
-            final H2Config h2Config) {
+            final HttpVersionPolicy versionPolicy,
+            final H2Config h2Config,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
+            final ConnectionReuseStrategy connectionReuseStrategy) {
         this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
         this.exchangeHandlerFactory = exchangeHandlerFactory;
-        this.charset = charset;
-        this.h2Config = h2Config;
+        this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
+        this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
+        this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
+        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
+        this.http1ConnectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy : DefaultConnectionReuseStrategy.INSTANCE;
+        this.http1ResponseParserFactory = new DefaultHttpResponseParserFactory(h1Config);
+        this.http1RequestWriterFactory = DefaultHttpRequestWriterFactory.INSTANCE;
     }
 
     @Override
-    public IOEventHandler createHandler(final IOSession ioSession) {
+    public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
         final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
         if (sessionLog.isDebugEnabled()
                 || streamLog.isDebugEnabled()
@@ -96,34 +125,79 @@ public class DefaultAsyncHttp2ClientEven
                 || framePayloadLog.isDebugEnabled()
                 || flowCtrlLog.isDebugEnabled()) {
             final String id = ConnPoolSupport.getId(ioSession);
-            return new LoggingIOEventHandler(new DefaultAsyncHttpClientProtocolNegotiator(
-                    new LoggingIOSession(ioSession, id, sessionLog, wireLog),
-                    httpProcessor, exchangeHandlerFactory, charset, h2Config,
-                    new ConnectionListener() {
+            final ConnectionListener connectionListener = new ConnectionListener() {
+
+                @Override
+                public void onConnect(final HttpConnection connection) {
+                    if (streamLog.isDebugEnabled()) {
+                        streamLog.debug(id + ": " + connection + " connected");
+                    }
+                }
+
+                @Override
+                public void onDisconnect(final HttpConnection connection) {
+                    if (streamLog.isDebugEnabled()) {
+                        streamLog.debug(id + ": " + connection + " disconnected");
+                    }
+                }
+
+                @Override
+                public void onError(final HttpConnection connection, final Exception ex) {
+                    if (ex instanceof ConnectionClosedException) {
+                        return;
+                    }
+                    streamLog.error(id + ": " + ex.getMessage(), ex);
+                }
+
+            };
+            final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(
+                    httpProcessor,
+                    h1Config,
+                    charCodingConfig,
+                    http1ConnectionReuseStrategy,
+                    http1ResponseParserFactory,
+                    http1RequestWriterFactory,
+                    connectionListener,
+                    new Http1StreamListener() {
 
                         @Override
-                        public void onConnect(final HttpConnection connection) {
-                            if (streamLog.isDebugEnabled()) {
-                                streamLog.debug(id + ": " + connection + " connected");
+                        public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
+                            if (headerLog.isDebugEnabled()) {
+                                headerLog.debug(id + " >> " + new RequestLine(request));
+                                for (final Iterator<Header> it = request.headerIterator(); it.hasNext(); ) {
+                                    headerLog.debug(id + " >> " + it.next());
+                                }
                             }
                         }
 
                         @Override
-                        public void onDisconnect(final HttpConnection connection) {
-                            if (streamLog.isDebugEnabled()) {
-                                streamLog.debug(id + ": " + connection + " disconnected");
+                        public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
+                            if (headerLog.isDebugEnabled()) {
+                                headerLog.debug(id + " << " + new StatusLine(response));
+                                for (final Iterator<Header> it = response.headerIterator(); it.hasNext(); ) {
+                                    headerLog.debug(id + " << " + it.next());
+                                }
                             }
                         }
 
                         @Override
-                        public void onError(final HttpConnection connection, final Exception ex) {
-                            if (ex instanceof ConnectionClosedException) {
-                                return;
+                        public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
+                            if (streamLog.isDebugEnabled()) {
+                                if (keepAlive) {
+                                    streamLog.debug(id + " Connection is kept alive");
+                                } else {
+                                    streamLog.debug(id + " Connection is not kept alive");
+                                }
                             }
-                            streamLog.error(id + ": " + ex.getMessage(), ex);
                         }
 
-                    },
+                    });
+            final ClientHttp2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientHttp2StreamMultiplexerFactory(
+                    httpProcessor,
+                    exchangeHandlerFactory,
+                    h2Config,
+                    charCodingConfig,
+                    connectionListener,
                     new Http2StreamListener() {
 
                         final FramePrinter framePrinter = new FramePrinter();
@@ -206,12 +280,39 @@ public class DefaultAsyncHttp2ClientEven
                             }
                         }
 
-            }), id, streamLog);
+                    });
+            final LoggingIOSession loggingIOSession = new LoggingIOSession(ioSession, id, sessionLog, wireLog);
+            return new LoggingIOEventHandler(
+                    new ClientHttpProtocolNegotiator(
+                            loggingIOSession,
+                            http1StreamHandlerFactory,
+                            http2StreamHandlerFactory,
+                            attachment instanceof HttpVersionPolicy ? (HttpVersionPolicy) attachment : versionPolicy,
+                            connectionListener),
+                    id,
+                    streamLog);
         } else {
-            return new DefaultAsyncHttpClientProtocolNegotiator(ioSession,
-                    httpProcessor, exchangeHandlerFactory, charset, h2Config, null, null);
+            final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(
+                    httpProcessor,
+                    h1Config,
+                    charCodingConfig,
+                    http1ConnectionReuseStrategy,
+                    http1ResponseParserFactory,
+                    http1RequestWriterFactory,
+                    null, null);
+            final ClientHttp2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientHttp2StreamMultiplexerFactory(
+                    httpProcessor,
+                    exchangeHandlerFactory,
+                    h2Config,
+                    charCodingConfig,
+                    null, null);
+            return new ClientHttpProtocolNegotiator(
+                    ioSession,
+                    http1StreamHandlerFactory,
+                    http2StreamHandlerFactory,
+                    attachment instanceof HttpVersionPolicy ? (HttpVersionPolicy) attachment : versionPolicy,
+                    null);
         }
-
    }
 
 }

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientEventHandlerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java Mon May  1 10:47:09 2017
@@ -27,22 +27,16 @@
 
 package org.apache.hc.client5.http.impl.async;
 
-import java.nio.charset.StandardCharsets;
-
-import org.apache.hc.client5.http.impl.DefaultThreadFactory;
 import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
 import org.apache.hc.client5.http.nio.AsyncClientConnectionManager;
-import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpVersion;
-import org.apache.hc.core5.http.config.ConnectionConfig;
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
+import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.hc.core5.http.nio.AsyncPushConsumer;
-import org.apache.hc.core5.http.nio.HandlerFactory;
 import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.http.protocol.RequestUserAgent;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.protocol.H2RequestConnControl;
 import org.apache.hc.core5.http2.protocol.H2RequestContent;
@@ -72,44 +66,13 @@ public class HttpAsyncClients {
     }
 
     /**
-     * Creates HTTP/1.1 {@link CloseableHttpAsyncClient} instance with default
-     * configuration.
-     */
-    public static CloseableHttpAsyncClient createDefault() {
-        return HttpAsyncClientBuilder.create().build();
-    }
-
-    /**
-     * Creates HTTP/2 {@link CloseableHttpAsyncClient} instance with the given
-     * configuration.
-     */
-    public static CloseableHttpAsyncClient createDefault(final H2Config config) {
-        return HttpAsyncClientBuilder.create()
-                .setProtocolVersion(HttpVersion.HTTP_2)
-                .setH2Config(config)
-                .build();
-    }
-
-    /**
-     * Creates HTTP/1.1 {@link CloseableHttpAsyncClient} instance with default
+     * Creates {@link CloseableHttpAsyncClient} instance with default
      * configuration and system properties.
      */
     public static CloseableHttpAsyncClient createSystem() {
         return HttpAsyncClientBuilder.create().useSystemProperties().build();
     }
 
-    /**
-     * Creates HTTP/2 {@link CloseableHttpAsyncClient} instance with the given
-     * configuration and system properties.
-     */
-    public static CloseableHttpAsyncClient createSystem(final H2Config config) {
-        return HttpAsyncClientBuilder.create()
-                .useSystemProperties()
-                .setProtocolVersion(HttpVersion.HTTP_2)
-                .setH2Config(config)
-                .build();
-    }
-
     private static HttpProcessor createMinimalProtocolProcessor() {
         return new DefaultHttpProcessor(
                 new H2RequestContent(),
@@ -136,72 +99,46 @@ public class HttpAsyncClients {
         }
     }
 
-    private static MinimalHttpAsyncClient createMinimalImpl(
+    public static MinimalHttpAsyncClient createMinimal(
+            final HttpVersionPolicy versionPolicy,
+            final H2Config h2Config,
             final H1Config h1Config,
             final AsyncClientConnectionManager connmgr) {
         return createMinimalImpl(
-                new DefaultAsyncHttp1ClientEventHandlerFactory(
+                new HttpAsyncClientEventHandlerFactory(
                         createMinimalProtocolProcessor(),
+                        null,
+                        versionPolicy,
+                        h2Config,
                         h1Config,
-                        ConnectionConfig.DEFAULT,
+                        CharCodingConfig.DEFAULT,
                         DefaultConnectionReuseStrategy.INSTANCE),
                 new AsyncPushConsumerRegistry(),
                 connmgr);
     }
 
-    private static MinimalHttpAsyncClient createMinimalImpl(
-            final H2Config h2Config,
-            final AsyncClientConnectionManager connmgr) {
-        final AsyncPushConsumerRegistry pushConsumerRegistry = new AsyncPushConsumerRegistry();
-        return createMinimalImpl(
-                new DefaultAsyncHttp2ClientEventHandlerFactory(
-                        createMinimalProtocolProcessor(),
-                        new HandlerFactory<AsyncPushConsumer>() {
-
-                            @Override
-                            public AsyncPushConsumer create(final HttpRequest request) throws HttpException {
-                                return pushConsumerRegistry.get(request);
-                            }
-
-                        },
-                        StandardCharsets.US_ASCII,
-                        h2Config),
-                pushConsumerRegistry,
-                connmgr);
-    }
-
     /**
      * Creates {@link CloseableHttpAsyncClient} instance that provides
-     * essential HTTP/1.1 message transport only.
+     * essential HTTP/1.1 and HTTP/2 message transport only.
      */
     public static CloseableHttpAsyncClient createMinimal() {
-        return createMinimalImpl(H1Config.DEFAULT, PoolingAsyncClientConnectionManagerBuilder.create().build());
+        return createMinimal(
+                HttpVersionPolicy.NEGOTIATE,
+                H2Config.DEFAULT,
+                H1Config.DEFAULT,
+                PoolingAsyncClientConnectionManagerBuilder.create().build());
     }
 
     /**
      * Creates {@link CloseableHttpAsyncClient} instance that provides
-     * essential HTTP/1.1 message transport only.
+     * essential HTTP/1.1 and HTTP/2 message transport only.
      */
     public static CloseableHttpAsyncClient createMinimal(final AsyncClientConnectionManager connManager) {
-        return createMinimalImpl(H1Config.DEFAULT, connManager);
-    }
-
-    /**
-     * Creates {@link CloseableHttpAsyncClient} instance that provides
-     * essential HTTP/2 message transport only.
-     */
-    public static CloseableHttpAsyncClient createMinimal(final H2Config h2Config) {
-        return createMinimal(h2Config, PoolingAsyncClientConnectionManagerBuilder.create().build());
-    }
-
-    /**
-     * Creates {@link CloseableHttpAsyncClient} instance that provides
-     * essential HTTP/2 message transport only.
-     */
-    public static CloseableHttpAsyncClient createMinimal(
-            final H2Config h2Config,
-            final AsyncClientConnectionManager connManager) {
-        return createMinimalImpl(h2Config, connManager);
+        return createMinimal(
+                HttpVersionPolicy.NEGOTIATE,
+                H2Config.DEFAULT,
+                H1Config.DEFAULT,
+                connManager);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java Mon May  1 10:47:09 2017
@@ -32,14 +32,12 @@ import java.nio.ByteBuffer;
 import java.util.List;
 import java.util.concurrent.Future;
 import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
 import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.async.AsyncClientEndpoint;
 import org.apache.hc.client5.http.config.Configurable;
 import org.apache.hc.client5.http.config.RequestConfig;
 import org.apache.hc.client5.http.impl.ConnPoolSupport;
@@ -58,6 +56,7 @@ import org.apache.hc.core5.http.HttpRequ
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.http.nio.AsyncRequestProducer;
 import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
@@ -70,6 +69,7 @@ import org.apache.hc.core5.reactor.IORea
 import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
+import org.apache.hc.core5.util.TimeValue;
 
 class InternalHttpAsyncClient extends AbstractHttpAsyncClientBase {
 
@@ -123,7 +123,7 @@ class InternalHttpAsyncClient extends Ab
             final HttpClientContext clientContext,
             final FutureCallback<AsyncConnectionEndpoint> callback) {
         final RequestConfig requestConfig = clientContext.getRequestConfig();
-        connmgr.lease(route, userToken, requestConfig.getConnectTimeout(), TimeUnit.MILLISECONDS,
+        connmgr.lease(route, userToken, requestConfig.getConnectTimeout(),
                 new FutureCallback<AsyncConnectionEndpoint>() {
 
                     @Override
@@ -134,7 +134,7 @@ class InternalHttpAsyncClient extends Ab
                             connmgr.connect(
                                     connectionEndpoint,
                                     getConnectionInitiator(),
-                                    requestConfig.getConnectTimeout(), TimeUnit.MILLISECONDS,
+                                    requestConfig.getConnectTimeout(),
                                     clientContext,
                                     new FutureCallback<AsyncConnectionEndpoint>() {
 
@@ -233,20 +233,23 @@ class InternalHttpAsyncClient extends Ab
                 @Override
                 public void completed(final AsyncConnectionEndpoint connectionEndpoint) {
                     final InternalAsyncClientEndpoint endpoint = new InternalAsyncClientEndpoint(route, connectionEndpoint);
-                    endpoint.executeAndRelease(requestProducer, responseConsumer, clientContext, new FutureCallback<T>() {
+                    endpoint.execute(requestProducer, responseConsumer, clientContext, new FutureCallback<T>() {
 
                         @Override
                         public void completed(final T result) {
+                            endpoint.releaseAndReuse();
                             future.completed(result);
                         }
 
                         @Override
                         public void failed(final Exception ex) {
+                            endpoint.releaseAndDiscard();
                             future.failed(ex);
                         }
 
                         @Override
                         public void cancelled() {
+                            endpoint.releaseAndDiscard();
                             future.cancel();
                         }
 
@@ -283,14 +286,14 @@ class InternalHttpAsyncClient extends Ab
         private final AsyncConnectionEndpoint connectionEndpoint;
         private final AtomicBoolean reusable;
         private final AtomicReference<Object> userTokenRef;
-        private final AtomicLong keepAlive;
+        private final AtomicReference<TimeValue> keepAliveRef;
         private final AtomicBoolean released;
 
         InternalAsyncClientEndpoint(final HttpRoute route, final AsyncConnectionEndpoint connectionEndpoint) {
             this.route = route;
             this.connectionEndpoint = connectionEndpoint;
             this.reusable = new AtomicBoolean(true);
-            this.keepAlive = new AtomicLong(Long.MAX_VALUE);
+            this.keepAliveRef = new AtomicReference<>(TimeValue.NEG_ONE_MILLISECONDS);
             this.userTokenRef = new AtomicReference<>(null);
             this.released = new AtomicBoolean(false);
         }
@@ -353,7 +356,7 @@ class InternalHttpAsyncClient extends Ab
                     }
                     exchangeHandler.consumeResponse(response, entityDetails);
 
-                    keepAlive.set(keepAliveStrategy.getKeepAliveDuration(response, context));
+                    keepAliveRef.set(keepAliveStrategy.getKeepAliveDuration(response, context));
 
                     if (entityDetails == null) {
                         updateState();
@@ -429,9 +432,9 @@ class InternalHttpAsyncClient extends Ab
             if (released.compareAndSet(false, true)) {
                 if (!reusable.get()) {
                     closeEndpoint();
-                    connmgr.release(connectionEndpoint, null, -1L, TimeUnit.MILLISECONDS);
+                    connmgr.release(connectionEndpoint, null, TimeValue.NEG_ONE_MILLISECONDS);
                 } else {
-                    connmgr.release(connectionEndpoint, userTokenRef.get(), keepAlive.get(), TimeUnit.MILLISECONDS);
+                    connmgr.release(connectionEndpoint, userTokenRef.get(), keepAliveRef.get());
                 }
             }
         }
@@ -440,7 +443,7 @@ class InternalHttpAsyncClient extends Ab
         public void releaseAndDiscard() {
             if (released.compareAndSet(false, true)) {
                 closeEndpoint();
-                connmgr.release(connectionEndpoint, null, -1L, TimeUnit.MILLISECONDS);
+                connmgr.release(connectionEndpoint, null, TimeValue.NEG_ONE_MILLISECONDS);
             }
         }
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttpAsyncClient.java Mon May  1 10:47:09 2017
@@ -29,22 +29,21 @@ package org.apache.hc.client5.http.impl.
 import java.io.IOException;
 import java.util.concurrent.Future;
 import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.async.AsyncClientEndpoint;
 import org.apache.hc.client5.http.config.Configurable;
 import org.apache.hc.client5.http.config.RequestConfig;
-import org.apache.hc.client5.http.impl.ComplexFuture;
 import org.apache.hc.client5.http.nio.AsyncClientConnectionManager;
 import org.apache.hc.client5.http.nio.AsyncConnectionEndpoint;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.core5.concurrent.BasicFuture;
 import org.apache.hc.core5.concurrent.Cancellable;
+import org.apache.hc.core5.concurrent.ComplexFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.http.nio.AsyncRequestProducer;
 import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
@@ -54,6 +53,7 @@ import org.apache.hc.core5.reactor.IORea
 import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
+import org.apache.hc.core5.util.TimeValue;
 
 class MinimalHttpAsyncClient extends AbstractHttpAsyncClientBase {
 
@@ -72,13 +72,13 @@ class MinimalHttpAsyncClient extends Abs
 
     private Future<AsyncConnectionEndpoint> leaseEndpoint(
             final HttpHost host,
-            final int connectTimeout,
+            final TimeValue connectTimeout,
             final HttpClientContext clientContext,
             final FutureCallback<AsyncConnectionEndpoint> callback) {
         final ComplexFuture<AsyncConnectionEndpoint> resultFuture = new ComplexFuture<>(callback);
         final Future<AsyncConnectionEndpoint> leaseFuture = connmgr.lease(
                 new HttpRoute(host), null,
-                connectTimeout, TimeUnit.MILLISECONDS,
+                connectTimeout,
                 new FutureCallback<AsyncConnectionEndpoint>() {
 
                     @Override
@@ -89,7 +89,7 @@ class MinimalHttpAsyncClient extends Abs
                             final Future<AsyncConnectionEndpoint> connectFuture = connmgr.connect(
                                     connectionEndpoint,
                                     getConnectionInitiator(),
-                                    connectTimeout, TimeUnit.MILLISECONDS,
+                                    connectTimeout,
                                     clientContext,
                                     new FutureCallback<AsyncConnectionEndpoint>() {
 
@@ -187,20 +187,23 @@ class MinimalHttpAsyncClient extends Abs
                     @Override
                     public void completed(final AsyncConnectionEndpoint connectionEndpoint) {
                         final InternalAsyncClientEndpoint endpoint = new InternalAsyncClientEndpoint(connectionEndpoint);
-                        endpoint.executeAndRelease(requestProducer, responseConsumer, clientContext, new FutureCallback<T>() {
+                        endpoint.execute(requestProducer, responseConsumer, clientContext, new FutureCallback<T>() {
 
                             @Override
                             public void completed(final T result) {
+                                endpoint.releaseAndReuse();
                                 resultFuture.completed(result);
                             }
 
                             @Override
                             public void failed(final Exception ex) {
+                                endpoint.releaseAndDiscard();
                                 resultFuture.failed(ex);
                             }
 
                             @Override
                             public void cancelled() {
+                                endpoint.releaseAndDiscard();
                                 resultFuture.cancel();
                             }
 
@@ -256,7 +259,7 @@ class MinimalHttpAsyncClient extends Abs
         @Override
         public void releaseAndReuse() {
             if (released.compareAndSet(false, true)) {
-                connmgr.release(connectionEndpoint, null, Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+                connmgr.release(connectionEndpoint, null, TimeValue.NEG_ONE_MILLISECONDS);
             }
         }
 
@@ -267,7 +270,7 @@ class MinimalHttpAsyncClient extends Abs
                     connectionEndpoint.close();
                 } catch (final IOException ignore) {
                 }
-                connmgr.release(connectionEndpoint, null, -1L, TimeUnit.MILLISECONDS);
+                connmgr.release(connectionEndpoint, null, TimeValue.ZERO_MILLISECONDS);
             }
         }
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java Mon May  1 10:47:09 2017
@@ -60,9 +60,11 @@ import org.apache.hc.core5.http.config.S
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
 import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
 import org.apache.hc.core5.util.LangUtils;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -219,13 +221,7 @@ public class BasicHttpClientConnectionMa
     private synchronized void shutdownConnection() {
         if (this.conn != null) {
             this.log.debug("Shutting down connection");
-            try {
-                this.conn.shutdown();
-            } catch (final IOException iox) {
-                if (this.log.isDebugEnabled()) {
-                    this.log.debug("I/O exception shutting down connection", iox);
-                }
-            }
+            this.conn.shutdown(ShutdownType.GRACEFUL);
             this.conn = null;
         }
     }
@@ -267,11 +263,8 @@ public class BasicHttpClientConnectionMa
     }
 
     @Override
-    public synchronized void release(
-            final ConnectionEndpoint endpoint,
-            final Object state,
-            final long keepalive, final TimeUnit tunit) {
-        Args.notNull(endpoint, "Endpoint");
+    public synchronized void release(final ConnectionEndpoint endpoint, final Object state, final TimeValue keepAlive) {
+        Args.notNull(endpoint, "Managed endpoint");
         final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
         final ManagedHttpClientConnection conn = internalEndpoint.detach();
         if (conn != null && this.log.isDebugEnabled()) {
@@ -281,26 +274,29 @@ public class BasicHttpClientConnectionMa
             return;
         }
         try {
+            if (keepAlive == null) {
+                this.conn.shutdown(ShutdownType.GRACEFUL);
+            }
             this.updated = System.currentTimeMillis();
             if (!this.conn.isOpen()) {
                 this.conn = null;
                 this.route = null;
                 this.conn = null;
                 this.expiry = Long.MAX_VALUE;
+                if (this.log.isDebugEnabled()) {
+                    this.log.debug("Connection is not kept alive");
+                }
             } else {
                 this.state = state;
-                if (this.log.isDebugEnabled()) {
-                    final String s;
-                    if (keepalive > 0) {
-                        s = "for " + keepalive + " " + tunit;
-                    } else {
-                        s = "indefinitely";
+                if (TimeValue.isPositive(keepAlive)) {
+                    if (this.log.isDebugEnabled()) {
+                        this.log.debug("Connection can be kept alive for " + keepAlive);
                     }
-                    this.log.debug("Connection can be kept alive " + s);
-                }
-                if (keepalive > 0) {
-                    this.expiry = this.updated + tunit.toMillis(keepalive);
+                    this.expiry = this.updated + keepAlive.toMillis();
                 } else {
+                    if (this.log.isDebugEnabled()) {
+                        this.log.debug("Connection can be kept alive indefinitely");
+                    }
                     this.expiry = Long.MAX_VALUE;
                 }
             }
@@ -310,11 +306,7 @@ public class BasicHttpClientConnectionMa
     }
 
     @Override
-    public void connect(
-            final ConnectionEndpoint endpoint,
-            final long connectTimeout,
-            final TimeUnit timeUnit,
-            final HttpContext context) throws IOException {
+    public void connect(final ConnectionEndpoint endpoint, final TimeValue connectTimeout, final HttpContext context) throws IOException {
         Args.notNull(endpoint, "Endpoint");
 
         final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
@@ -332,7 +324,7 @@ public class BasicHttpClientConnectionMa
                 internalEndpoint.getConnection(),
                 host,
                 route.getLocalSocketAddress(),
-                (int) (timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS).toMillis(connectTimeout),
+                connectTimeout,
                 this.socketConfig,
                 context);
     }
@@ -415,10 +407,10 @@ public class BasicHttpClientConnectionMa
         }
 
         @Override
-        public void shutdown() throws IOException {
+        public void shutdown(final ShutdownType shutdownType) {
             final ManagedHttpClientConnection conn = detach();
             if (conn != null) {
-                conn.shutdown();
+                conn.shutdown(shutdownType);
             }
         }
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java Mon May  1 10:47:09 2017
@@ -54,6 +54,7 @@ import org.apache.hc.core5.http.config.L
 import org.apache.hc.core5.http.config.SocketConfig;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -103,14 +104,17 @@ public class DefaultHttpClientConnection
             final ManagedHttpClientConnection conn,
             final HttpHost host,
             final InetSocketAddress localAddress,
-            final int connectTimeout,
+            final TimeValue connectTimeout,
             final SocketConfig socketConfig,
             final HttpContext context) throws IOException {
+        Args.notNull(conn, "Connection");
+        Args.notNull(host, "Host");
+        Args.notNull(socketConfig, "Socket config");
+        Args.notNull(context, "Context");
         final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(context);
         final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
         if (sf == null) {
-            throw new UnsupportedSchemeException(host.getSchemeName() +
-                    " protocol is not supported");
+            throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
         }
         final InetAddress[] addresses = host.getAddress() != null ?
                 new InetAddress[] { host.getAddress() } : this.dnsResolver.resolve(host.getHostName());
@@ -120,7 +124,7 @@ public class DefaultHttpClientConnection
             final boolean last = i == addresses.length - 1;
 
             Socket sock = sf.createSocket(context);
-            sock.setSoTimeout(socketConfig.getSoTimeout());
+            sock.setSoTimeout(socketConfig.getSoTimeout().toMillisIntBound());
             sock.setReuseAddress(socketConfig.isSoReuseAddress());
             sock.setTcpNoDelay(socketConfig.isTcpNoDelay());
             sock.setKeepAlive(socketConfig.isSoKeepAlive());
@@ -131,7 +135,7 @@ public class DefaultHttpClientConnection
                 sock.setSendBufferSize(socketConfig.getSndBufSize());
             }
 
-            final int linger = socketConfig.getSoLinger();
+            final int linger = socketConfig.getSoLinger().toMillisIntBound();
             if (linger >= 0) {
                 sock.setSoLinger(true, linger);
             }
@@ -142,8 +146,7 @@ public class DefaultHttpClientConnection
                 this.log.debug("Connecting to " + remoteAddress);
             }
             try {
-                sock = sf.connectSocket(
-                        connectTimeout, sock, host, remoteAddress, localAddress, context);
+                sock = sf.connectSocket(connectTimeout, sock, host, remoteAddress, localAddress, context);
                 conn.bind(sock);
                 if (this.log.isDebugEnabled()) {
                     this.log.debug("Connection established " + conn);

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java Mon May  1 10:47:09 2017
@@ -39,7 +39,6 @@ import javax.net.ssl.SSLSocket;
 
 import org.apache.hc.client5.http.impl.logging.LoggingSocketHolder;
 import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
-import org.apache.hc.client5.http.utils.Identifiable;
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ContentLengthStrategy;
@@ -51,6 +50,8 @@ import org.apache.hc.core5.http.io.HttpM
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
 import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.util.Identifiable;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -70,7 +71,6 @@ public class DefaultManagedHttpClientCon
 
     public DefaultManagedHttpClientConnection(
             final String id,
-            final int buffersize,
             final CharsetDecoder chardecoder,
             final CharsetEncoder charencoder,
             final H1Config h1Config,
@@ -78,16 +78,13 @@ public class DefaultManagedHttpClientCon
             final ContentLengthStrategy outgoingContentStrategy,
             final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
             final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
-        super(buffersize, chardecoder, charencoder, h1Config, incomingContentStrategy, outgoingContentStrategy,
-                requestWriterFactory, responseParserFactory);
+        super(h1Config, chardecoder, charencoder, incomingContentStrategy, outgoingContentStrategy, requestWriterFactory, responseParserFactory);
         this.id = id;
         this.closed = new AtomicBoolean();
     }
 
-    public DefaultManagedHttpClientConnection(
-            final String id,
-            final int buffersize) {
-        this(id, buffersize, null, null, null, null, null, null, null);
+    public DefaultManagedHttpClientConnection(final String id) {
+        this(id, null, null, null, null, null, null, null);
     }
 
     @Override
@@ -141,12 +138,12 @@ public class DefaultManagedHttpClientCon
     }
 
     @Override
-    public void shutdown() throws IOException {
+    public void shutdown(final ShutdownType shutdownType) {
         if (this.closed.compareAndSet(false, true)) {
             if (this.log.isDebugEnabled()) {
-                this.log.debug(this.id + ": Shutdown connection");
+                this.log.debug(this.id + ": Shutdown connection " + shutdownType);
             }
-            super.shutdown();
+            super.shutdown(shutdownType);
         }
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java Mon May  1 10:47:09 2017
@@ -41,7 +41,7 @@ import org.apache.hc.core5.annotation.Th
 import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ContentLengthStrategy;
-import org.apache.hc.core5.http.config.ConnectionConfig;
+import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
 import org.apache.hc.core5.http.impl.io.DefaultHttpRequestWriterFactory;
@@ -61,7 +61,7 @@ public class ManagedHttpClientConnection
     public static final ManagedHttpClientConnectionFactory INSTANCE = new ManagedHttpClientConnectionFactory();
 
     private final H1Config h1Config;
-    private final ConnectionConfig connectionConfig;
+    private final CharCodingConfig charCodingConfig;
     private final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory;
     private final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory;
     private final ContentLengthStrategy incomingContentStrategy;
@@ -69,14 +69,14 @@ public class ManagedHttpClientConnection
 
     public ManagedHttpClientConnectionFactory(
             final H1Config h1Config,
-            final ConnectionConfig connectionConfig,
+            final CharCodingConfig charCodingConfig,
             final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
             final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory,
             final ContentLengthStrategy incomingContentStrategy,
             final ContentLengthStrategy outgoingContentStrategy) {
         super();
         this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
-        this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
+        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
         this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory :
                 DefaultHttpRequestWriterFactory.INSTANCE;
         this.responseParserFactory = responseParserFactory != null ? responseParserFactory :
@@ -89,17 +89,17 @@ public class ManagedHttpClientConnection
 
     public ManagedHttpClientConnectionFactory(
             final H1Config h1Config,
-            final ConnectionConfig connectionConfig,
+            final CharCodingConfig charCodingConfig,
             final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
             final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
-        this(h1Config, connectionConfig, requestWriterFactory, responseParserFactory, null, null);
+        this(h1Config, charCodingConfig, requestWriterFactory, responseParserFactory, null, null);
     }
 
     public ManagedHttpClientConnectionFactory(
             final H1Config h1Config,
-            final ConnectionConfig connectionConfig,
+            final CharCodingConfig charCodingConfig,
             final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
-        this(h1Config, connectionConfig, null, responseParserFactory);
+        this(h1Config, charCodingConfig, null, responseParserFactory);
     }
 
     public ManagedHttpClientConnectionFactory() {
@@ -110,11 +110,11 @@ public class ManagedHttpClientConnection
     public ManagedHttpClientConnection createConnection(final Socket socket) throws IOException {
         CharsetDecoder chardecoder = null;
         CharsetEncoder charencoder = null;
-        final Charset charset = this.connectionConfig.getCharset();
-        final CodingErrorAction malformedInputAction = this.connectionConfig.getMalformedInputAction() != null ?
-                this.connectionConfig.getMalformedInputAction() : CodingErrorAction.REPORT;
-        final CodingErrorAction unmappableInputAction = this.connectionConfig.getUnmappableInputAction() != null ?
-                this.connectionConfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
+        final Charset charset = this.charCodingConfig.getCharset();
+        final CodingErrorAction malformedInputAction = this.charCodingConfig.getMalformedInputAction() != null ?
+                this.charCodingConfig.getMalformedInputAction() : CodingErrorAction.REPORT;
+        final CodingErrorAction unmappableInputAction = this.charCodingConfig.getUnmappableInputAction() != null ?
+                this.charCodingConfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
         if (charset != null) {
             chardecoder = charset.newDecoder();
             chardecoder.onMalformedInput(malformedInputAction);
@@ -126,7 +126,6 @@ public class ManagedHttpClientConnection
         final String id = "http-outgoing-" + Long.toString(COUNTER.getAndIncrement());
         final DefaultManagedHttpClientConnection conn = new DefaultManagedHttpClientConnection(
                 id,
-                connectionConfig.getBufferSize(),
                 chardecoder,
                 charencoder,
                 h1Config,

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java Mon May  1 10:47:09 2017
@@ -27,9 +27,7 @@
 package org.apache.hc.client5.http.impl.io;
 
 import java.io.IOException;
-import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -62,9 +60,9 @@ import org.apache.hc.core5.http.config.R
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.http.config.SocketConfig;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
-import org.apache.hc.core5.http.io.HttpClientConnection;
 import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.pool.ConnPoolControl;
 import org.apache.hc.core5.pool.ConnPoolListener;
 import org.apache.hc.core5.pool.ConnPoolPolicy;
@@ -73,6 +71,7 @@ import org.apache.hc.core5.pool.PoolStat
 import org.apache.hc.core5.pool.StrictConnPool;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -115,7 +114,7 @@ public class PoolingHttpClientConnection
     private final AtomicBoolean closed;
 
     private volatile SocketConfig defaultSocketConfig;
-    private volatile int validateAfterInactivity;
+    private volatile TimeValue validateAfterInactivity;
 
     private static Registry<ConnectionSocketFactory> getDefaultRegistry() {
         return RegistryBuilder.<ConnectionSocketFactory>create()
@@ -128,9 +127,8 @@ public class PoolingHttpClientConnection
         this(getDefaultRegistry());
     }
 
-    public PoolingHttpClientConnectionManager(
-            final long timeToLive, final TimeUnit tunit) {
-        this(getDefaultRegistry(), null, null ,null, ConnPoolPolicy.LIFO, null, timeToLive, tunit);
+    public PoolingHttpClientConnectionManager(final TimeValue timeToLive) {
+        this(getDefaultRegistry(), null, null ,null, ConnPoolPolicy.LIFO, null, timeToLive);
     }
 
     public PoolingHttpClientConnectionManager(
@@ -159,7 +157,7 @@ public class PoolingHttpClientConnection
             final Registry<ConnectionSocketFactory> socketFactoryRegistry,
             final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
             final DnsResolver dnsResolver) {
-        this(socketFactoryRegistry, connFactory, null, dnsResolver, ConnPoolPolicy.LIFO, null, -1, TimeUnit.MILLISECONDS);
+        this(socketFactoryRegistry, connFactory, null, dnsResolver, ConnPoolPolicy.LIFO, null, TimeValue.NEG_ONE_MILLISECONDS);
     }
 
     public PoolingHttpClientConnectionManager(
@@ -169,9 +167,9 @@ public class PoolingHttpClientConnection
             final DnsResolver dnsResolver,
             final ConnPoolPolicy connPoolPolicy,
             final ConnPoolListener<HttpRoute> connPoolListener,
-            final long timeToLive, final TimeUnit tunit) {
+            final TimeValue timeToLive) {
         this(new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver),
-            connFactory, connPoolPolicy, connPoolListener, timeToLive, tunit);
+            connFactory, connPoolPolicy, connPoolListener, timeToLive);
     }
 
     public PoolingHttpClientConnectionManager(
@@ -179,12 +177,12 @@ public class PoolingHttpClientConnection
             final HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
             final ConnPoolPolicy connPoolPolicy,
             final ConnPoolListener<HttpRoute> connPoolListener,
-            final long timeToLive, final TimeUnit tunit) {
+            final TimeValue timeToLive) {
         super();
         this.connectionOperator = Args.notNull(httpClientConnectionOperator, "Connection operator");
         this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE;
         this.pool = new StrictConnPool<>(
-                DEFAULT_MAX_CONNECTIONS_PER_ROUTE, DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive, tunit, connPoolPolicy, connPoolListener);
+                DEFAULT_MAX_CONNECTIONS_PER_ROUTE, DEFAULT_MAX_TOTAL_CONNECTIONS, timeToLive, connPoolPolicy, connPoolListener);
         this.closed = new AtomicBoolean(false);
     }
 
@@ -217,7 +215,7 @@ public class PoolingHttpClientConnection
     public void close() {
         if (this.closed.compareAndSet(false, true)) {
             this.log.debug("Connection manager is shutting down");
-            this.pool.shutdown();
+            this.pool.shutdown(ShutdownType.GRACEFUL);
             this.log.debug("Connection manager shut down");
         }
     }
@@ -261,10 +259,10 @@ public class PoolingHttpClientConnection
                     throw ex;
                 }
                 try {
-                    if (validateAfterInactivity > 0) {
+                    if (TimeValue.isPositive(validateAfterInactivity)) {
                         final ManagedHttpClientConnection conn = poolEntry.getConnection();
                         if (conn != null
-                                && poolEntry.getUpdated() + validateAfterInactivity <= System.currentTimeMillis()) {
+                                && poolEntry.getUpdated() + validateAfterInactivity.toMillis() <= System.currentTimeMillis()) {
                             boolean stale;
                             try {
                                 stale = conn.isStale();
@@ -275,7 +273,7 @@ public class PoolingHttpClientConnection
                                 if (log.isDebugEnabled()) {
                                     log.debug("Connection " + ConnPoolSupport.getId(conn) + " is stale");
                                 }
-                                poolEntry.discardConnection();
+                                poolEntry.discardConnection(ShutdownType.IMMEDIATE);
                             }
                         }
                     }
@@ -308,25 +306,25 @@ public class PoolingHttpClientConnection
     }
 
     @Override
-    public void release(
-            final ConnectionEndpoint endpoint,
-            final Object state,
-            final long keepAlive, final TimeUnit timeUnit) {
+    public void release(final ConnectionEndpoint endpoint, final Object state, final TimeValue keepAlive) {
         Args.notNull(endpoint, "Managed endpoint");
         final PoolEntry<HttpRoute, ManagedHttpClientConnection> entry = cast(endpoint).detach();
         if (entry == null) {
             return;
         }
         final ManagedHttpClientConnection conn = entry.getConnection();
+        if (conn != null && keepAlive == null) {
+            conn.shutdown(ShutdownType.GRACEFUL);
+        }
         boolean reusable = conn != null && conn.isOpen();
         try {
             if (reusable) {
-                final TimeUnit effectiveUnit = timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS;
-                entry.updateConnection(keepAlive, effectiveUnit, state);
+                entry.updateState(state);
+                entry.updateExpiry(keepAlive);
                 if (this.log.isDebugEnabled()) {
                     final String s;
-                    if (keepAlive > 0) {
-                        s = "for " + (double) effectiveUnit.toMillis(keepAlive) / 1000 + " seconds";
+                    if (TimeValue.isPositive(keepAlive)) {
+                        s = "for " + keepAlive;
                     } else {
                         s = "indefinitely";
                     }
@@ -346,11 +344,7 @@ public class PoolingHttpClientConnection
     }
 
     @Override
-    public void connect(
-            final ConnectionEndpoint endpoint,
-            final long connectTimeout,
-            final TimeUnit timeUnit,
-            final HttpContext context) throws IOException {
+    public void connect(final ConnectionEndpoint endpoint, final TimeValue connectTimeout, final HttpContext context) throws IOException {
         Args.notNull(endpoint, "Managed endpoint");
         final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
         if (internalEndpoint.isConnected()) {
@@ -371,15 +365,13 @@ public class PoolingHttpClientConnection
                 poolEntry.getConnection(),
                 host,
                 route.getLocalSocketAddress(),
-                (int) (timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS).toMillis(connectTimeout),
-                this.defaultSocketConfig != null ? this.defaultSocketConfig : SocketConfig.DEFAULT,
+                connectTimeout,
+                defaultSocketConfig != null ? this.defaultSocketConfig : SocketConfig.DEFAULT,
                 context);
     }
 
     @Override
-    public void upgrade(
-            final ConnectionEndpoint endpoint,
-            final HttpContext context) throws IOException {
+    public void upgrade(final ConnectionEndpoint endpoint, final HttpContext context) throws IOException {
         Args.notNull(endpoint, "Managed endpoint");
         final InternalConnectionEndpoint internalEndpoint = cast(endpoint);
         final PoolEntry<HttpRoute, ManagedHttpClientConnection> poolEntry = internalEndpoint.getValidatedPoolEntry();
@@ -388,11 +380,12 @@ public class PoolingHttpClientConnection
     }
 
     @Override
-    public void closeIdle(final long idleTimeout, final TimeUnit tunit) {
+    public void closeIdle(final TimeValue idleTime) {
+        Args.notNull(idleTime, "Idle time");
         if (this.log.isDebugEnabled()) {
-            this.log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
+            this.log.debug("Closing connections idle longer than " + idleTime);
         }
-        this.pool.closeIdle(idleTimeout, tunit);
+        this.pool.closeIdle(idleTime);
     }
 
     @Override
@@ -465,11 +458,11 @@ public class PoolingHttpClientConnection
     }
 
     /**
-     * @see #setValidateAfterInactivity(int)
+     * @see #setValidateAfterInactivity(TimeValue)
      *
      * @since 4.4
      */
-    public int getValidateAfterInactivity() {
+    public TimeValue getValidateAfterInactivity() {
         return validateAfterInactivity;
     }
 
@@ -483,36 +476,8 @@ public class PoolingHttpClientConnection
      *
      * @since 4.4
      */
-    public void setValidateAfterInactivity(final int ms) {
-        validateAfterInactivity = ms;
-    }
-
-    static class ConfigData {
-
-        private final Map<HttpHost, SocketConfig> socketConfigMap;
-        private volatile SocketConfig defaultSocketConfig;
-
-        ConfigData() {
-            super();
-            this.socketConfigMap = new ConcurrentHashMap<>();
-        }
-
-        public SocketConfig getDefaultSocketConfig() {
-            return this.defaultSocketConfig;
-        }
-
-        public void setDefaultSocketConfig(final SocketConfig defaultSocketConfig) {
-            this.defaultSocketConfig = defaultSocketConfig;
-        }
-
-        public SocketConfig getSocketConfig(final HttpHost host) {
-            return this.socketConfigMap.get(host);
-        }
-
-        public void setSocketConfig(final HttpHost host, final SocketConfig socketConfig) {
-            this.socketConfigMap.put(host, socketConfig);
-        }
-
+    public void setValidateAfterInactivity(final TimeValue validateAfterInactivity) {
+        this.validateAfterInactivity = validateAfterInactivity;
     }
 
     class InternalConnectionEndpoint extends ConnectionEndpoint {
@@ -544,14 +509,10 @@ public class PoolingHttpClientConnection
         }
 
         @Override
-        public void shutdown() throws IOException {
+        public void shutdown(final ShutdownType shutdownType) {
             final PoolEntry<HttpRoute, ManagedHttpClientConnection> poolEntry = poolEntryRef.get();
             if (poolEntry != null) {
-                final HttpClientConnection connection = poolEntry.getConnection();
-                poolEntry.discardConnection();
-                if (connection != null) {
-                    connection.shutdown();
-                }
+                poolEntry.discardConnection(shutdownType);
             }
         }
 
@@ -559,7 +520,7 @@ public class PoolingHttpClientConnection
         public void close() throws IOException {
             final PoolEntry<HttpRoute, ManagedHttpClientConnection> poolEntry = poolEntryRef.get();
             if (poolEntry != null) {
-                poolEntry.discardConnection();
+                poolEntry.discardConnection(ShutdownType.GRACEFUL);
             }
         }
 
@@ -582,7 +543,8 @@ public class PoolingHttpClientConnection
                 final HttpContext context) throws IOException, HttpException {
             Args.notNull(request, "HTTP request");
             Args.notNull(requestExecutor, "Request executor");
-            return requestExecutor.execute(request, getValidatedPoolEntry().getConnection(), context);
+            final ManagedHttpClientConnection connection = getValidatedPoolEntry().getConnection();
+            return requestExecutor.execute(request, connection, context);
         }
 
     }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java Mon May  1 10:47:09 2017
@@ -27,8 +27,6 @@
 
 package org.apache.hc.client5.http.impl.io;
 
-import java.util.concurrent.TimeUnit;
-
 import org.apache.hc.client5.http.DnsResolver;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.SchemePortResolver;
@@ -42,6 +40,7 @@ import org.apache.hc.core5.http.config.S
 import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.pool.ConnPoolListener;
 import org.apache.hc.core5.pool.ConnPoolPolicy;
+import org.apache.hc.core5.util.TimeValue;
 
 /**
  * Builder for {@link PoolingHttpClientConnectionManager} instances.
@@ -84,9 +83,8 @@ public class PoolingHttpClientConnection
     private int maxConnTotal = 0;
     private int maxConnPerRoute = 0;
 
-    private long connTimeToLive = -1;
-    private TimeUnit connTimeToLiveTimeUnit = TimeUnit.MILLISECONDS;
-    private int validateAfterInactivity = 2000;
+    private TimeValue timeToLive;
+    private TimeValue validateAfterInactivity;
 
     public static PoolingHttpClientConnectionManagerBuilder create() {
         return new PoolingHttpClientConnectionManagerBuilder();
@@ -173,9 +171,8 @@ public class PoolingHttpClientConnection
     /**
      * Sets maximum time to live for persistent connections
      */
-    public final PoolingHttpClientConnectionManagerBuilder setConnectionTimeToLive(final long connTimeToLive, final TimeUnit connTimeToLiveTimeUnit) {
-        this.connTimeToLive = connTimeToLive;
-        this.connTimeToLiveTimeUnit = connTimeToLiveTimeUnit;
+    public final PoolingHttpClientConnectionManagerBuilder setConnectionTimeToLive(final TimeValue timeToLive) {
+        this.timeToLive = timeToLive;
         return this;
     }
 
@@ -185,7 +182,7 @@ public class PoolingHttpClientConnection
      *
      * @see org.apache.hc.core5.http.io.HttpClientConnection#isStale()
      */
-    public final PoolingHttpClientConnectionManagerBuilder setValidateAfterInactivity(final int validateAfterInactivity) {
+    public final PoolingHttpClientConnectionManagerBuilder setValidateAfterInactivity(final TimeValue validateAfterInactivity) {
         this.validateAfterInactivity = validateAfterInactivity;
         return this;
     }
@@ -214,8 +211,7 @@ public class PoolingHttpClientConnection
                 dnsResolver,
                 connPoolPolicy,
                 connPoolListener,
-                connTimeToLive,
-                connTimeToLiveTimeUnit != null ? connTimeToLiveTimeUnit : TimeUnit.MILLISECONDS);
+                timeToLive != null ? timeToLive : TimeValue.NEG_ONE_MILLISECONDS);
         poolingmgr.setValidateAfterInactivity(this.validateAfterInactivity);
         if (defaultSocketConfig != null) {
             poolingmgr.setDefaultSocketConfig(defaultSocketConfig);

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOEventHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOEventHandler.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOEventHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOEventHandler.java Mon May  1 10:47:09 2017
@@ -30,9 +30,12 @@ package org.apache.hc.client5.http.impl.
 import java.io.IOException;
 import java.net.SocketAddress;
 
-import org.apache.hc.core5.http.HttpConnectionMetrics;
+import javax.net.ssl.SSLSession;
+
+import org.apache.hc.core5.http.EndpointDetails;
 import org.apache.hc.core5.http.ProtocolVersion;
 import org.apache.hc.core5.http.impl.nio.HttpConnectionEventHandler;
+import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.logging.log4j.Logger;
 
@@ -98,8 +101,13 @@ public class LoggingIOEventHandler imple
     }
 
     @Override
-    public HttpConnectionMetrics getMetrics() {
-        return handler.getMetrics();
+    public SSLSession getSSLSession() {
+        return handler.getSSLSession();
+    }
+
+    @Override
+    public EndpointDetails getEndpointDetails() {
+        return handler.getEndpointDetails();
     }
 
     @Override
@@ -144,11 +152,11 @@ public class LoggingIOEventHandler imple
     }
 
     @Override
-    public void shutdown() throws IOException {
+    public void shutdown(final ShutdownType shutdownType) {
         if (log.isDebugEnabled()) {
-            log.debug(id + " shutdown");
+            log.debug(id + " shutdown " + shutdownType);
         }
-        handler.shutdown();
+        handler.shutdown(shutdownType);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java?rev=1793305&r1=1793304&r2=1793305&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/logging/LoggingIOSession.java Mon May  1 10:47:09 2017
@@ -34,26 +34,26 @@ import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
 
 import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
 
+import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.reactor.IOEventHandler;
-import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.logging.log4j.Logger;
 
-public class LoggingIOSession implements IOSession, TransportSecurityLayer {
+public class LoggingIOSession implements TlsCapableIOSession {
 
     private final Logger log;
     private final Wire wirelog;
     private final String id;
-    private final IOSession session;
+    private final TlsCapableIOSession session;
     private final ByteChannel channel;
 
-    public LoggingIOSession(final IOSession session, final String id, final Logger log, final Logger wirelog) {
+    public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log, final Logger wirelog) {
         super();
         this.session = session;
         this.id = id;
@@ -62,11 +62,16 @@ public class LoggingIOSession implements
         this.channel = new LoggingByteChannel();
     }
 
-    public LoggingIOSession(final IOSession session, final String id, final Logger log) {
+    public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log) {
         this(session, id, log, null);
     }
 
     @Override
+    public String getId() {
+        return session.getId();
+    }
+
+    @Override
     public void addLast(final Command command) {
         this.session.addLast(command);
     }
@@ -163,11 +168,11 @@ public class LoggingIOSession implements
     }
 
     @Override
-    public void shutdown() {
+    public void shutdown(final ShutdownType shutdownType) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug(this.id + " " + this.session + ": Shutdown");
+            this.log.debug(this.id + " " + this.session + ": Shutdown " + shutdownType);
         }
-        this.session.shutdown();
+        this.session.shutdown(shutdownType);
     }
 
     @Override
@@ -194,25 +199,17 @@ public class LoggingIOSession implements
     }
 
     @Override
-    public void start(
+    public void startTls(
             final SSLContext sslContext,
             final SSLBufferManagement sslBufferManagement,
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier) throws UnsupportedOperationException {
-        if (session instanceof TransportSecurityLayer) {
-            ((TransportSecurityLayer) session).start(sslContext, sslBufferManagement, initializer, verifier);
-        } else {
-            throw new UnsupportedOperationException();
-        }
+        session.startTls(sslContext, sslBufferManagement, initializer, verifier);
     }
 
     @Override
-    public SSLSession getSSLSession() {
-        if (session instanceof TransportSecurityLayer) {
-            return ((TransportSecurityLayer) session).getSSLSession();
-        } else {
-            return null;
-        }
+    public TlsDetails getTlsDetails() {
+        return session.getTlsDetails();
     }
 
     @Override



Mime
View raw message