hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [16/50] httpcomponents-core git commit: Do not automatically close HttpAsyncRequestExecutionHandler on an I/O error allowing the handler to retry
Date Tue, 09 May 2017 20:03:07 GMT
Do not automatically close HttpAsyncRequestExecutionHandler on an I/O error allowing the handler
to retry

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.2.x@1439903
13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/4.2.x
Commit: 12a8cd8d2aba45064b8bd6b4b0b77addd499e3af
Parents: 576ac96
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Tue Jan 29 14:19:02 2013 +0000
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Tue Jan 29 14:19:02 2013 +0000

----------------------------------------------------------------------
 .../nio/protocol/HttpAsyncRequestExecutor.java  | 31 ++++++++++----------
 .../protocol/TestHttpAsyncRequestExecutor.java  |  2 --
 2 files changed, 15 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/12a8cd8d/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
index a6009b5..282fc72 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
@@ -104,8 +104,8 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler
{
     public void closed(final NHttpClientConnection conn) {
         State state = getState(conn);
         HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
-        if (state == null || !state.isValid()) {
-            closeHandler(handler, null);
+        if (state == null || (handler != null && handler.isDone())) {
+            closeHandler(handler);
         }
         if (state != null) {
             state.reset();
@@ -117,7 +117,7 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler
{
         shutdownConnection(conn);
         HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
         if (handler != null) {
-            closeHandler(handler, cause);
+            handler.failed(cause);
         } else {
             log(cause);
         }
@@ -131,7 +131,7 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler
{
         }
         HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
         if (handler != null && handler.isDone()) {
-            closeHandler(handler, null);
+            closeHandler(handler);
             state.reset();
             handler = null;
         }
@@ -258,7 +258,8 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler
{
         if (state != null) {
             if (state.getRequestState().compareTo(MessageState.READY) != 0) {
                 state.invalidate();
-                closeHandler(getHandler(conn), new ConnectionClosedException("Connection
closed"));
+                HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
+                handler.failed(new ConnectionClosedException("Connection closed"));
             }
         }
         // Closing connection in an orderly manner and
@@ -283,7 +284,11 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler
{
                 return;
             } else {
                 state.invalidate();
-                closeHandler(getHandler(conn), new SocketTimeoutException());
+                HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
+                if (handler != null) {
+                    handler.failed(new SocketTimeoutException());
+                    handler.close();
+                }
             }
         }
         if (conn.getStatus() == NHttpConnection.ACTIVE) {
@@ -337,18 +342,12 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler
{
         }
     }
 
-    private void closeHandler(final HttpAsyncRequestExecutionHandler<?> handler, final
Exception ex) {
+    private void closeHandler(final HttpAsyncRequestExecutionHandler<?> handler) {
         if (handler != null) {
             try {
-                if (ex != null) {
-                    handler.failed(ex);
-                }
-            } finally {
-                try {
-                    handler.close();
-                } catch (IOException ioex) {
-                    log(ioex);
-                }
+                handler.close();
+            } catch (IOException ioex) {
+                log(ioex);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/12a8cd8d/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
b/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
index 68ce3a7..76a33b2 100644
--- a/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
+++ b/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
@@ -148,7 +148,6 @@ public class TestHttpAsyncRequestExecutor {
         this.protocolHandler.exception(this.conn, httpex);
 
         Mockito.verify(this.exchangeHandler).failed(httpex);
-        Mockito.verify(this.exchangeHandler).close();
         Mockito.verify(this.conn).shutdown();
     }
 
@@ -164,7 +163,6 @@ public class TestHttpAsyncRequestExecutor {
         this.protocolHandler.exception(this.conn, ioex);
 
         Mockito.verify(this.exchangeHandler).failed(ioex);
-        Mockito.verify(this.exchangeHandler).close();
         Mockito.verify(this.conn).shutdown();
     }
 


Mime
View raw message