hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1098288 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio: client/DefaultAsyncRequestDirector.java conn/ClientConnAdaptor.java
Date Sun, 01 May 2011 12:18:39 GMT
Author: olegk
Date: Sun May  1 12:18:39 2011
New Revision: 1098288

URL: http://svn.apache.org/viewvc?rev=1098288&view=rev
Log:
Improved exception handling code in DefaultAsyncRequestDirector

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java?rev=1098288&r1=1098287&r2=1098288&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
Sun May  1 12:18:39 2011
@@ -282,7 +282,7 @@ class DefaultAsyncRequestDirector<T> imp
         }
     }
 
-    private void releaseResources() {
+    private void releaseConnection() {
         if (this.managedConn != null) {
             try {
                 this.managedConn.getContext().removeAttribute(HTTP_EXCHANGE_HANDLER);
@@ -290,8 +290,19 @@ class DefaultAsyncRequestDirector<T> imp
             } catch (IOException ioex) {
                 this.log.debug("I/O error releasing connection", ioex);
             }
+            this.managedConn = null;
+        }
+    }
+
+    private void releaseResources() {
+        if (this.managedConn != null) {
+            try {
+                this.managedConn.abortConnection();
+            } catch (IOException ioex) {
+                this.log.debug("I/O error releasing connection", ioex);
+            }
+            this.managedConn = null;
         }
-        this.managedConn = null;
         if (this.connFuture != null) {
             this.connFuture.cancel(true);
             this.connFuture = null;
@@ -343,13 +354,13 @@ class DefaultAsyncRequestDirector<T> imp
                 } else {
                     this.resultCallback.failed(ex, this);
                 }
-                releaseResources();
+                releaseConnection();
             } else {
                 if (this.followup != null) {
                     HttpRoute actualRoute = this.mainRequest.getRoute();
                     HttpRoute newRoute = this.followup.getRoute();
                     if (!actualRoute.equals(newRoute)) {
-                        releaseResources();
+                        releaseConnection();
                     }
                     this.mainRequest = this.followup;
                 }
@@ -373,10 +384,11 @@ class DefaultAsyncRequestDirector<T> imp
         try {
             this.responseConsumer.cancel();
             this.resultCallback.cancelled(this);
-            releaseResources();
         } catch (RuntimeException runex) {
-            failed(runex);
+            this.resultCallback.failed(runex, this);
             throw runex;
+        } finally {
+            releaseResources();
         }
     }
 

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java?rev=1098288&r1=1098287&r2=1098288&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ClientConnAdaptor.java
Sun May  1 12:18:39 2011
@@ -108,8 +108,6 @@ class ClientConnAdaptor implements Manag
         }
         this.released = true;
         this.reusable = false;
-        IOSession iosession = this.entry.getIOSession();
-        iosession.shutdown();
         this.manager.releaseConnection(this, this.expiry, this.tunit);
         this.entry = null;
         this.conn = null;
@@ -147,8 +145,12 @@ class ClientConnAdaptor implements Manag
         this.reusable = true;
     }
 
-    public synchronized void shutdown() {
-        abortConnection();
+    public synchronized void shutdown() throws IOException {
+        if (this.released) {
+            return;
+        }
+        this.conn.shutdown();
+        this.reusable = false;
     }
 
     public synchronized void close() throws IOException {



Mime
View raw message