hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1439907 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
Date Tue, 29 Jan 2013 14:34:37 GMT
Author: olegk
Date: Tue Jan 29 14:34:36 2013
New Revision: 1439907

URL: http://svn.apache.org/viewvc?rev=1439907&view=rev
Log:
Do not automatically close HttpAsyncRequestExecutionHandler on an I/O error allowing the handler
to retry

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1439907&r1=1439906&r2=1439907&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
Tue Jan 29 14:34:36 2013
@@ -110,8 +110,8 @@ public class HttpAsyncRequestExecutor im
     public void closed(final NHttpClientConnection conn) {
         final State state = getState(conn);
         final 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();
@@ -123,7 +123,7 @@ public class HttpAsyncRequestExecutor im
         shutdownConnection(conn);
         final HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
         if (handler != null) {
-            closeHandler(handler, cause);
+            handler.failed(cause);
         } else {
             log(cause);
         }
@@ -137,7 +137,7 @@ public class HttpAsyncRequestExecutor im
         }
         HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
         if (handler != null && handler.isDone()) {
-            closeHandler(handler, null);
+            closeHandler(handler);
             state.reset();
             handler = null;
         }
@@ -260,7 +260,8 @@ public class HttpAsyncRequestExecutor im
         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
@@ -285,7 +286,11 @@ public class HttpAsyncRequestExecutor im
                 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) {
@@ -335,18 +340,12 @@ public class HttpAsyncRequestExecutor im
         }
     }
 
-    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 (final IOException ioex) {
-                    log(ioex);
-                }
+                handler.close();
+            } catch (final IOException ioex) {
+                log(ioex);
             }
         }
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java?rev=1439907&r1=1439906&r2=1439907&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
Tue Jan 29 14:34:36 2013
@@ -147,7 +147,6 @@ public class TestHttpAsyncRequestExecuto
         this.protocolHandler.exception(this.conn, httpex);
 
         Mockito.verify(this.exchangeHandler).failed(httpex);
-        Mockito.verify(this.exchangeHandler).close();
         Mockito.verify(this.conn).shutdown();
     }
 
@@ -163,7 +162,6 @@ public class TestHttpAsyncRequestExecuto
         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