hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1055176 - in /httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client: DefaultAsyncRequestDirector.java HttpExchange.java NHttpClientProtocolHandler.java
Date Tue, 04 Jan 2011 20:38:57 GMT
Author: olegk
Date: Tue Jan  4 20:38:56 2011
New Revision: 1055176

URL: http://svn.apache.org/viewvc?rev=1055176&view=rev
Log:
Remove exchange handler from the I/O session context when the session is released back to
the pool

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

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java?rev=1055176&r1=1055175&r2=1055176&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
Tue Jan  4 20:38:56 2011
@@ -289,6 +289,7 @@ class DefaultAsyncRequestDirector<T> imp
     private void releaseResources() {
         if (this.managedConn != null) {
             try {
+                this.managedConn.getContext().removeAttribute(HTTP_EXCHANGE_HANDLER);
                 this.managedConn.releaseConnection();
             } catch (IOException ioex) {
                 this.log.debug("I/O error releasing connection", ioex);

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchange.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchange.java?rev=1055176&r1=1055175&r2=1055176&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchange.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/HttpExchange.java
Tue Jan  4 20:38:56 2011
@@ -28,7 +28,6 @@ package org.apache.http.impl.nio.client;
 
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
-import org.apache.http.nio.client.HttpAsyncExchangeHandler;
 
 class HttpExchange {
 
@@ -36,7 +35,6 @@ class HttpExchange {
     private MessageState responseState;
     private HttpRequest request;
     private HttpResponse response;
-    private HttpAsyncExchangeHandler<?> handler;
     private boolean valid;
     private int timeout;
 
@@ -79,14 +77,6 @@ class HttpExchange {
         this.response = response;
     }
 
-    public void setHandler(final HttpAsyncExchangeHandler<?> handler) {
-        this.handler = handler;
-    }
-
-    public HttpAsyncExchangeHandler<?> getHandler() {
-        return this.handler;
-    }
-
     public int getTimeout() {
         return this.timeout;
     }

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/NHttpClientProtocolHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/NHttpClientProtocolHandler.java?rev=1055176&r1=1055175&r2=1055176&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/NHttpClientProtocolHandler.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/NHttpClientProtocolHandler.java
Tue Jan  4 20:38:56 2011
@@ -98,39 +98,31 @@ class NHttpClientProtocolHandler impleme
     public void closed(final NHttpClientConnection conn) {
         HttpContext context = conn.getContext();
         HttpExchange httpexchange = getHttpExchange(context);
+        HttpAsyncExchangeHandler<?> handler = getHandler(context);
         if (this.log.isDebugEnabled()) {
             this.log.debug("Disconnected " + formatState(conn, httpexchange));
         }
-        if (httpexchange != null) {
-            HttpAsyncExchangeHandler<?> handler = httpexchange.getHandler();
-            if (handler != null) {
-                handler.cancel();
-            }
+        if (handler != null) {
+            handler.cancel();
         }
     }
 
     public void exception(final NHttpClientConnection conn, final HttpException ex) {
         HttpContext context = conn.getContext();
-        HttpExchange httpexchange = getHttpExchange(context);
+        HttpAsyncExchangeHandler<?> handler = getHandler(context);
         this.log.error("HTTP protocol exception: " + ex.getMessage(), ex);
-        if (httpexchange != null) {
-            HttpAsyncExchangeHandler<?> handler = httpexchange.getHandler();
-            if (handler != null) {
-                handler.failed(ex);
-            }
+        if (handler != null) {
+            handler.failed(ex);
         }
         closeConnection(conn);
     }
 
     public void exception(final NHttpClientConnection conn, final IOException ex) {
         HttpContext context = conn.getContext();
-        HttpExchange httpexchange = getHttpExchange(context);
+        HttpAsyncExchangeHandler<?> handler = getHandler(context);
         this.log.error("I/O error: " + ex.getMessage(), ex);
-        if (httpexchange != null) {
-            HttpAsyncExchangeHandler<?> handler = httpexchange.getHandler();
-            if (handler != null) {
-                handler.failed(ex);
-            }
+        if (handler != null) {
+            handler.failed(ex);
         }
         shutdownConnection(conn);
     }
@@ -151,7 +143,6 @@ class NHttpClientProtocolHandler impleme
             }
             return;
         }
-        httpexchange.setHandler(handler);
         try {
             HttpRequest request = handler.generateRequest();
             httpexchange.setRequest(request);
@@ -195,14 +186,14 @@ class NHttpClientProtocolHandler impleme
     public void inputReady(final NHttpClientConnection conn, final ContentDecoder decoder)
{
         HttpContext context = conn.getContext();
         HttpExchange httpexchange = getHttpExchange(context);
+        HttpAsyncExchangeHandler<?> handler = getHandler(context);
         if (this.log.isDebugEnabled()) {
             this.log.debug("Input ready " + formatState(conn, httpexchange));
         }
-        HttpAsyncExchangeHandler<?> handler = httpexchange.getHandler();
         try {
             handler.consumeContent(decoder, conn);
             if (decoder.isCompleted()) {
-                processResponse(conn, httpexchange);
+                processResponse(conn, httpexchange, handler);
             }
         } catch (IOException ex) {
             if (this.log.isDebugEnabled()) {
@@ -216,10 +207,10 @@ class NHttpClientProtocolHandler impleme
     public void outputReady(final NHttpClientConnection conn, final ContentEncoder encoder)
{
         HttpContext context = conn.getContext();
         HttpExchange httpexchange = getHttpExchange(context);
+        HttpAsyncExchangeHandler<?> handler = getHandler(context);
         if (this.log.isDebugEnabled()) {
             this.log.debug("Output ready " + formatState(conn, httpexchange));
         }
-        HttpAsyncExchangeHandler<?> handler = httpexchange.getHandler();
         try {
             if (httpexchange.getRequestState() == MessageState.ACK) {
                 conn.suspendOutput();
@@ -241,10 +232,10 @@ class NHttpClientProtocolHandler impleme
     public void responseReceived(final NHttpClientConnection conn) {
         HttpContext context = conn.getContext();
         HttpExchange httpexchange = getHttpExchange(context);
+        HttpAsyncExchangeHandler<?> handler = getHandler(context);
         if (this.log.isDebugEnabled()) {
             this.log.debug("Response received " + formatState(conn, httpexchange));
         }
-        HttpAsyncExchangeHandler<?> handler = httpexchange.getHandler();
         try {
             HttpResponse response = conn.getHttpResponse();
             HttpRequest request = httpexchange.getRequest();
@@ -272,7 +263,7 @@ class NHttpClientProtocolHandler impleme
             }
             handler.responseReceived(response);
             if (!canResponseHaveBody(request, response)) {
-                processResponse(conn, httpexchange);
+                processResponse(conn, httpexchange, handler);
             }
         } catch (IOException ex) {
             if (this.log.isDebugEnabled()) {
@@ -292,10 +283,10 @@ class NHttpClientProtocolHandler impleme
     public void timeout(final NHttpClientConnection conn) {
         HttpContext context = conn.getContext();
         HttpExchange httpexchange = getHttpExchange(context);
+        HttpAsyncExchangeHandler<?> handler = getHandler(context);
         if (this.log.isDebugEnabled()) {
             this.log.debug("Timeout " + formatState(conn, httpexchange));
         }
-        HttpAsyncExchangeHandler<?> handler = httpexchange.getHandler();
         try {
             if (httpexchange.getRequestState() == MessageState.ACK) {
                 continueRequest(conn, httpexchange);
@@ -326,7 +317,8 @@ class NHttpClientProtocolHandler impleme
     }
 
     private HttpAsyncExchangeHandler<?> getHandler(final HttpContext context) {
-        return (HttpAsyncExchangeHandler<?>) context.getAttribute(DefaultAsyncRequestDirector.HTTP_EXCHANGE_HANDLER);
+        return (HttpAsyncExchangeHandler<?>) context.getAttribute(
+                DefaultAsyncRequestDirector.HTTP_EXCHANGE_HANDLER);
     }
 
     private void continueRequest(
@@ -348,8 +340,8 @@ class NHttpClientProtocolHandler impleme
 
     private void processResponse(
             final NHttpClientConnection conn,
-            final HttpExchange httpexchange) throws IOException {
-        HttpAsyncExchangeHandler<?> handler = httpexchange.getHandler();
+            final HttpExchange httpexchange,
+            final HttpAsyncExchangeHandler<?> handler) throws IOException {
         if (!httpexchange.isValid()) {
             conn.close();
         }
@@ -370,9 +362,6 @@ class NHttpClientProtocolHandler impleme
             this.log.debug("Response processed " + formatState(conn, httpexchange));
         }
         handler.responseCompleted();
-        if (handler.isDone()) {
-            httpexchange.setHandler(null);
-        }
         httpexchange.reset();
     }
 



Mime
View raw message