hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [3/4] httpcomponents-client git commit: HTTP/2 client implementations to support cancellation of ongoing message exchanges without terminating the underlying connections
Date Mon, 15 Jan 2018 08:17:57 GMT
HTTP/2 client implementations to support cancellation of ongoing message exchanges without
terminating the underlying connections


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

Branch: refs/heads/master
Commit: 10126c70ffafc22a2ee5b5df1f8e341eb95546b6
Parents: 695f353
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Fri Jan 12 14:40:32 2018 +0100
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Fri Jan 12 14:40:32 2018 +0100

----------------------------------------------------------------------
 .../apache/hc/client5/http/async/AsyncExecRuntime.java   |  2 +-
 .../http/impl/async/Http2AsyncMainClientExec.java        | 11 +++++------
 .../client5/http/impl/async/HttpAsyncMainClientExec.java |  9 +++++----
 .../http/impl/async/InternalHttp2AsyncExecRuntime.java   | 10 ++++++----
 .../http/impl/async/InternalHttpAsyncExecRuntime.java    |  4 ++--
 .../client5/http/impl/async/MinimalHttp2AsyncClient.java |  4 ++--
 6 files changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/10126c70/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecRuntime.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecRuntime.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecRuntime.java
index 919457c..7c0b027 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecRuntime.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/AsyncExecRuntime.java
@@ -72,7 +72,7 @@ public interface AsyncExecRuntime {
     /**
      * Initiates a message exchange using the given handler.
      */
-    void execute(
+    Cancellable execute(
             AsyncClientExchangeHandler exchangeHandler,
             HttpClientContext context);
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/10126c70/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java
index 18c6892..802e405 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/Http2AsyncMainClientExec.java
@@ -32,12 +32,12 @@ import java.nio.ByteBuffer;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.async.AsyncExecCallback;
 import org.apache.hc.client5.http.async.AsyncExecChain;
 import org.apache.hc.client5.http.async.AsyncExecChainHandler;
 import org.apache.hc.client5.http.async.AsyncExecRuntime;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.concurrent.CancellableDependency;
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
@@ -65,7 +65,7 @@ class Http2AsyncMainClientExec implements AsyncExecChainHandler {
             final AsyncExecChain chain,
             final AsyncExecCallback asyncExecCallback) throws HttpException, IOException
{
         final String exchangeId = scope.exchangeId;
-        final HttpRoute route = scope.route;
+        final CancellableDependency operation = scope.cancellableDependency;
         final HttpClientContext clientContext = scope.clientContext;
         final AsyncExecRuntime execRuntime = scope.execRuntime;
 
@@ -158,12 +158,11 @@ class Http2AsyncMainClientExec implements AsyncExecChainHandler {
         };
 
         if (log.isDebugEnabled()) {
-            execRuntime.execute(
+            operation.setDependency(execRuntime.execute(
                     new LoggingAsyncClientExchangeHandler(log, exchangeId, internalExchangeHandler),
-                    clientContext);
+                    clientContext));
         } else {
-            execRuntime.execute(
-                    internalExchangeHandler, clientContext);
+            operation.setDependency(execRuntime.execute( internalExchangeHandler, clientContext));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/10126c70/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java
index 301382c..1c8eabd 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncMainClientExec.java
@@ -41,6 +41,7 @@ import org.apache.hc.client5.http.async.AsyncExecChain;
 import org.apache.hc.client5.http.async.AsyncExecChainHandler;
 import org.apache.hc.client5.http.async.AsyncExecRuntime;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.concurrent.CancellableDependency;
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
@@ -79,6 +80,7 @@ class HttpAsyncMainClientExec implements AsyncExecChainHandler {
             final AsyncExecCallback asyncExecCallback) throws HttpException, IOException
{
         final String exchangeId = scope.exchangeId;
         final HttpRoute route = scope.route;
+        final CancellableDependency operation = scope.cancellableDependency;
         final HttpClientContext clientContext = scope.clientContext;
         final AsyncExecRuntime execRuntime = scope.execRuntime;
 
@@ -217,12 +219,11 @@ class HttpAsyncMainClientExec implements AsyncExecChainHandler {
         };
 
         if (log.isDebugEnabled()) {
-            execRuntime.execute(
+            operation.setDependency(execRuntime.execute(
                     new LoggingAsyncClientExchangeHandler(log, exchangeId, internalExchangeHandler),
-                    clientContext);
+                    clientContext));
         } else {
-            execRuntime.execute(
-                    internalExchangeHandler, clientContext);
+            operation.setDependency(execRuntime.execute(internalExchangeHandler, clientContext));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/10126c70/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttp2AsyncExecRuntime.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttp2AsyncExecRuntime.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttp2AsyncExecRuntime.java
index be8ef7c..5708b39 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttp2AsyncExecRuntime.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttp2AsyncExecRuntime.java
@@ -37,6 +37,7 @@ import org.apache.hc.client5.http.impl.ConnPoolSupport;
 import org.apache.hc.client5.http.impl.Operations;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.core5.concurrent.Cancellable;
+import org.apache.hc.core5.concurrent.ComplexCancellable;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
@@ -190,14 +191,15 @@ class InternalHttp2AsyncExecRuntime implements AsyncExecRuntime {
     }
 
     @Override
-    public void execute(final AsyncClientExchangeHandler exchangeHandler, final HttpClientContext
context) {
+    public Cancellable execute(final AsyncClientExchangeHandler exchangeHandler, final HttpClientContext
context) {
+        final ComplexCancellable complexCancellable = new ComplexCancellable();
         final Endpoint endpoint = ensureValid();
         final IOSession session = endpoint.session;
         if (!session.isClosed()) {
             if (log.isDebugEnabled()) {
                 log.debug(ConnPoolSupport.getId(endpoint) + ": executing " + ConnPoolSupport.getId(exchangeHandler));
             }
-            session.addLast(new ExecutionCommand(exchangeHandler, context));
+            session.addLast(new ExecutionCommand(exchangeHandler, complexCancellable, context));
         } else {
             final HttpHost target = endpoint.target;
             final RequestConfig requestConfig = context.getRequestConfig();
@@ -210,7 +212,7 @@ class InternalHttp2AsyncExecRuntime implements AsyncExecRuntime {
                     if (log.isDebugEnabled()) {
                         log.debug(ConnPoolSupport.getId(endpoint) + ": executing " + ConnPoolSupport.getId(exchangeHandler));
                     }
-                    session.addLast(new ExecutionCommand(exchangeHandler, context));
+                    session.addLast(new ExecutionCommand(exchangeHandler, complexCancellable,
context));
                 }
 
                 @Override
@@ -225,7 +227,7 @@ class InternalHttp2AsyncExecRuntime implements AsyncExecRuntime {
 
             });
         }
-
+        return complexCancellable;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/10126c70/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java
index dc91be1..e48b8dd 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java
@@ -230,7 +230,7 @@ class InternalHttpAsyncExecRuntime implements AsyncExecRuntime {
     }
 
     @Override
-    public void execute(final AsyncClientExchangeHandler exchangeHandler, final HttpClientContext
context) {
+    public Cancellable execute(final AsyncClientExchangeHandler exchangeHandler, final HttpClientContext
context) {
         final AsyncConnectionEndpoint endpoint = ensureValid();
         if (endpoint.isConnected()) {
             if (log.isDebugEnabled()) {
@@ -264,7 +264,7 @@ class InternalHttpAsyncExecRuntime implements AsyncExecRuntime {
 
             });
         }
-
+        return Operations.nonCancellable();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/10126c70/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttp2AsyncClient.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttp2AsyncClient.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttp2AsyncClient.java
index 2ba4cbe..77be31b 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttp2AsyncClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/MinimalHttp2AsyncClient.java
@@ -214,9 +214,9 @@ public final class MinimalHttp2AsyncClient extends AbstractMinimalHttpAsyncClien
                                 log.debug(ConnPoolSupport.getId(session) + ": executing message
exchange " + exchangeId);
                                 session.addLast(new ExecutionCommand(
                                         new LoggingAsyncClientExchangeHandler(log, exchangeId,
internalExchangeHandler),
-                                        clientContext));
+                                        resultFuture, clientContext));
                             } else {
-                                session.addLast(new ExecutionCommand(internalExchangeHandler,
clientContext));
+                                session.addLast(new ExecutionCommand(internalExchangeHandler,
resultFuture, clientContext));
                             }
                         }
 


Mime
View raw message