hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-client git commit: Added methods to passivate and activate managed connections. These methods are used to restore / store the original socket timeout value upon connection lease / release
Date Fri, 17 Nov 2017 16:51:44 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/master 5da1bd8f8 -> f182b73e4


Added methods to passivate and activate managed connections. These methods are used to restore
/ store the original socket timeout value upon connection lease / release


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/f182b73e
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/f182b73e
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/f182b73e

Branch: refs/heads/master
Commit: f182b73e48ee1a8744994a8b0963ca7f7046f7a6
Parents: 5da1bd8
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Fri Nov 17 17:49:14 2017 +0100
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Fri Nov 17 17:49:14 2017 +0100

----------------------------------------------------------------------
 .../impl/io/BasicHttpClientConnectionManager.java     |  3 +++
 .../impl/io/DefaultManagedHttpClientConnection.java   | 14 ++++++++++++++
 .../impl/io/PoolingHttpClientConnectionManager.java   |  6 +++++-
 .../impl/nio/DefaultManagedAsyncClientConnection.java | 12 ++++++++++++
 .../impl/nio/PoolingAsyncClientConnectionManager.java |  9 +++++++--
 .../client5/http/io/ManagedHttpClientConnection.java  | 14 ++++++++++++++
 .../http/nio/ManagedAsyncClientConnection.java        | 10 ++++++++++
 7 files changed, 65 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/f182b73e/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
index 11b31f9..f884313 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
@@ -245,6 +245,8 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
         checkExpiry();
         if (this.conn == null) {
             this.conn = this.connFactory.createConnection(null);
+        } else {
+            this.conn.activate();
         }
         this.leased = true;
         return this.conn;
@@ -284,6 +286,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
                 }
             } else {
                 this.state = state;
+                conn.passivate();
                 if (TimeValue.isPositive(keepAlive)) {
                     if (this.log.isDebugEnabled()) {
                         this.log.debug("Connection can be kept alive for " + keepAlive);

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/f182b73e/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
index dafa8e2..98e0e29 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java
@@ -69,6 +69,8 @@ final class DefaultManagedHttpClientConnection
     private final String id;
     private final AtomicBoolean closed;
 
+    private int socketTimeout;
+
     public DefaultManagedHttpClientConnection(
             final String id,
             final CharsetDecoder chardecoder,
@@ -101,6 +103,7 @@ final class DefaultManagedHttpClientConnection
             throw new InterruptedIOException("Connection already shutdown");
         }
         super.bind(socketHolder);
+        socketTimeout = socketHolder.getSocket().getSoTimeout();
     }
 
     @Override
@@ -150,6 +153,7 @@ final class DefaultManagedHttpClientConnection
     @Override
     public void bind(final Socket socket) throws IOException {
         super.bind(this.wirelog.isDebugEnabled() ? new LoggingSocketHolder(socket, this.id,
this.wirelog) : new SocketHolder(socket));
+        socketTimeout = socket.getSoTimeout();
     }
 
     @Override
@@ -174,4 +178,14 @@ final class DefaultManagedHttpClientConnection
         }
     }
 
+    @Override
+    public void passivate() {
+        super.setSocketTimeout(0);
+    }
+
+    @Override
+    public void activate() {
+        super.setSocketTimeout(socketTimeout);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/f182b73e/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
index c5e7e86..cb17912 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
@@ -291,7 +291,10 @@ public class PoolingHttpClientConnectionManager
                             }
                         }
                     }
-                    if (!poolEntry.hasConnection()) {
+                    final ManagedHttpClientConnection conn = poolEntry.getConnection();
+                    if (conn != null) {
+                        conn.activate();
+                    } else {
                         poolEntry.assignConnection(connFactory.createConnection(null));
                     }
                     if (log.isDebugEnabled()) {
@@ -335,6 +338,7 @@ public class PoolingHttpClientConnectionManager
             if (reusable) {
                 entry.updateState(state);
                 entry.updateExpiry(keepAlive);
+                conn.passivate();
                 if (this.log.isDebugEnabled()) {
                     final String s;
                     if (TimeValue.isPositive(keepAlive)) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/f182b73e/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultManagedAsyncClientConnection.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultManagedAsyncClientConnection.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultManagedAsyncClientConnection.java
index 1132ffe..8a8a85a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultManagedAsyncClientConnection.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultManagedAsyncClientConnection.java
@@ -66,10 +66,12 @@ final class DefaultManagedAsyncClientConnection implements ManagedAsyncClientCon
     private final Logger log = LogManager.getLogger(getClass());
 
     private final IOSession ioSession;
+    private final int socketTimeout;
     private final AtomicBoolean closed;
 
     public DefaultManagedAsyncClientConnection(final IOSession ioSession) {
         this.ioSession = ioSession;
+        this.socketTimeout = ioSession.getSocketTimeout();
         this.closed = new AtomicBoolean();
     }
 
@@ -186,4 +188,14 @@ final class DefaultManagedAsyncClientConnection implements ManagedAsyncClientCon
         ioSession.addLast(command);
     }
 
+    @Override
+    public void passivate() {
+        ioSession.setSocketTimeout(0);
+    }
+
+    @Override
+    public void activate() {
+        ioSession.setSocketTimeout(socketTimeout);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/f182b73e/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
index 1afb96e..7973f61 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
@@ -217,12 +217,16 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
                 route, state, requestTimeout, new FutureCallback<PoolEntry<HttpRoute,
ManagedAsyncClientConnection>>() {
 
                     void leaseCompleted(final PoolEntry<HttpRoute, ManagedAsyncClientConnection>
poolEntry) {
+                        final ManagedAsyncClientConnection connection = poolEntry.getConnection();
+                        if (connection != null) {
+                            connection.activate();
+                        }
                         if (log.isDebugEnabled()) {
-                            log.debug("Connection leased: " + ConnPoolSupport.formatStats(poolEntry.getConnection(),
route, state, pool));
+                            log.debug("Connection leased: " + ConnPoolSupport.formatStats(connection,
route, state, pool));
                         }
                         final AsyncConnectionEndpoint endpoint = new InternalConnectionEndpoint(poolEntry);
                         if (log.isDebugEnabled()) {
-                            log.debug(ConnPoolSupport.getId(endpoint) + ": acquired " + ConnPoolSupport.getId(poolEntry.getConnection()));
+                            log.debug(ConnPoolSupport.getId(endpoint) + ": acquired " + ConnPoolSupport.getId(connection));
                         }
                         resultFuture.completed(endpoint);
                     }
@@ -296,6 +300,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
             if (reusable) {
                 entry.updateState(state);
                 entry.updateExpiry(keepAlive);
+                connection.passivate();
                 if (log.isDebugEnabled()) {
                     final String s;
                     if (TimeValue.isPositive(keepAlive)) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/f182b73e/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java
index fa0e92d..d9b1df7 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/io/ManagedHttpClientConnection.java
@@ -72,4 +72,18 @@ public interface ManagedHttpClientConnection extends HttpClientConnection
{
      */
     SSLSession getSSLSession();
 
+    /**
+     * Puts the connection into idle mode.
+     *
+     * @since 5.0
+     */
+    void passivate();
+
+    /**
+     * Restores the connection from idle mode.
+     *
+     * @since 5.0
+     */
+    void activate();
+
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/f182b73e/httpclient5/src/main/java/org/apache/hc/client5/http/nio/ManagedAsyncClientConnection.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/nio/ManagedAsyncClientConnection.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/nio/ManagedAsyncClientConnection.java
index 6726660..6a14f20 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/nio/ManagedAsyncClientConnection.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/nio/ManagedAsyncClientConnection.java
@@ -39,4 +39,14 @@ public interface ManagedAsyncClientConnection extends HttpConnection, TransportS
 
     void submitCommand(Command command);
 
+    /**
+     * Puts the connection into idle mode.
+     */
+    void passivate();
+
+    /**
+     * Restores the connection from idle mode.
+     */
+    void activate();
+
 }


Mime
View raw message