hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1043057 - in /httpcomponents/httpasyncclient/trunk/src: main/java/org/apache/http/impl/nio/client/ main/java/org/apache/http/nio/client/ test/java/org/apache/http/impl/nio/client/
Date Tue, 07 Dec 2010 14:17:32 GMT
Author: olegk
Date: Tue Dec  7 14:17:31 2010
New Revision: 1043057

URL: http://svn.apache.org/viewvc?rev=1043057&view=rev
Log:
HttpAsyncClient API redesign

Added:
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncRequestProducer.java
      - copied, changed from r1042948, httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncExchangeHandler.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncResponseConsumer.java
      - copied, changed from r1042948, httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncExchangeHandler.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java
      - copied, changed from r1042948, httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java
      - copied, changed from r1042948, httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java
Removed:
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncExchangeHandler.java
Modified:
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncClient.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java
    httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java
    httpcomponents/httpasyncclient/trunk/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncClient.java?rev=1043057&r1=1043056&r2=1043057&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncClient.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncClient.java
Tue Dec  7 14:17:31 2010
@@ -41,7 +41,8 @@ import org.apache.http.impl.DefaultConne
 import org.apache.http.impl.nio.conn.BasicIOSessionManager;
 import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
 import org.apache.http.nio.client.HttpAsyncClient;
-import org.apache.http.nio.client.HttpAsyncExchangeHandler;
+import org.apache.http.nio.client.HttpAsyncRequestProducer;
+import org.apache.http.nio.client.HttpAsyncResponseConsumer;
 import org.apache.http.nio.concurrent.FutureCallback;
 import org.apache.http.nio.conn.IOSessionManager;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
@@ -169,13 +170,15 @@ public class BasicHttpAsyncClient implem
     }
 
     public <T> Future<T> execute(
-            final HttpAsyncExchangeHandler<T> handler,
+            final HttpAsyncRequestProducer requestProducer,
+            final HttpAsyncResponseConsumer<T> responseConsumer,
             final HttpContext context,
             final FutureCallback<T> callback) {
         DefaultAsyncRequestDirector<T> httpexchange;
         synchronized (this) {
             httpexchange = new DefaultAsyncRequestDirector<T>(
-                    handler,
+                    requestProducer,
+                    responseConsumer,
                     callback,
                     this.sessmrg,
                     createHttpProcessor(),
@@ -187,16 +190,19 @@ public class BasicHttpAsyncClient implem
     }
 
     public <T> Future<T> execute(
-            final HttpAsyncExchangeHandler<T> handler,
+            final HttpAsyncRequestProducer requestProducer,
+            final HttpAsyncResponseConsumer<T> responseConsumer,
             final FutureCallback<T> callback) {
-        return execute(handler, new BasicHttpContext(), callback);
+        return execute(requestProducer, responseConsumer, new BasicHttpContext(), callback);
     }
 
     public Future<HttpResponse> execute(
             final HttpHost target, final HttpRequest request, final HttpContext context,
             final FutureCallback<HttpResponse> callback) {
-        BasicHttpAsyncExchangeHandler handler = new BasicHttpAsyncExchangeHandler(target,
request);
-        return execute(handler, context, callback);
+        return execute(
+                new BasicHttpAsyncRequestProducer(target, request),
+                new BasicHttpAsyncResponseConsumer(),
+                context, callback);
     }
 
     public Future<HttpResponse> execute(

Copied: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncRequestProducer.java
(from r1042948, httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncExchangeHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncRequestProducer.java?p2=httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncRequestProducer.java&p1=httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncExchangeHandler.java&r1=1042948&r2=1043057&rev=1043057&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncExchangeHandler.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncRequestProducer.java
Tue Dec  7 14:17:31 2010
@@ -32,30 +32,20 @@ import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.client.HttpAsyncExchangeHandler;
-import org.apache.http.nio.entity.BufferingNHttpEntity;
-import org.apache.http.nio.entity.ConsumingNHttpEntity;
+import org.apache.http.nio.client.HttpAsyncRequestProducer;
 import org.apache.http.nio.entity.NHttpEntityWrapper;
 import org.apache.http.nio.entity.ProducingNHttpEntity;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 
-public class BasicHttpAsyncExchangeHandler implements HttpAsyncExchangeHandler<HttpResponse>
{
+public class BasicHttpAsyncRequestProducer implements HttpAsyncRequestProducer {
 
     private final HttpHost target;
     private final HttpRequest request;
 
-    private volatile HttpResponse response;
     private volatile ProducingNHttpEntity contentProducingEntity;
-    private volatile ConsumingNHttpEntity contentConsumingEntity;
-    private volatile HttpResponse result;
-    private volatile Exception ex;
-    private volatile boolean completed;
 
-    public BasicHttpAsyncExchangeHandler(final HttpHost target, final HttpRequest request)
{
+    public BasicHttpAsyncRequestProducer(final HttpHost target, final HttpRequest request)
{
         super();
         if (target == null) {
             throw new IllegalArgumentException("Target host may not be null");
@@ -75,15 +65,6 @@ public class BasicHttpAsyncExchangeHandl
         return this.target;
     }
 
-    protected ConsumingNHttpEntity createConsumingHttpEntity(
-            final HttpResponse response) throws IOException {
-        if (response.getEntity() != null) {
-            return new BufferingNHttpEntity(response.getEntity(), new HeapByteBufferAllocator());
-        } else {
-            return null;
-        }
-    }
-
     protected ProducingNHttpEntity createProducingHttpEntity(
             final HttpRequest request) throws IOException {
         HttpEntityEnclosingRequest entityReq;
@@ -103,16 +84,6 @@ public class BasicHttpAsyncExchangeHandl
         }
     }
 
-    private ConsumingNHttpEntity getConsumingHttpEntity() throws IOException {
-        if (this.contentConsumingEntity == null) {
-            this.contentConsumingEntity = createConsumingHttpEntity(this.response);
-            if (this.contentConsumingEntity == null) {
-                throw new IllegalStateException("Content consumer is null");
-            }
-        }
-        return this.contentConsumingEntity;
-    }
-
     private ProducingNHttpEntity getProducingHttpEntity() throws IOException {
         if (this.contentProducingEntity == null) {
             this.contentProducingEntity = createProducingHttpEntity(this.request);
@@ -129,20 +100,20 @@ public class BasicHttpAsyncExchangeHandl
         producer.produceContent(encoder, ioctrl);
     }
 
-    public synchronized void responseReceived(final HttpResponse response) {
-        if (this.response != null) {
-            throw new IllegalStateException("HTTP response already set");
+    public synchronized boolean isRepeatable() {
+        if (this.request instanceof HttpEntityEnclosingRequest) {
+            HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
+            if (entity != null) {
+                return entity.isRepeatable();
+            } else {
+                return true;
+            }
+        } else {
+            return true;
         }
-        this.response = response;
-    }
-
-    public synchronized void consumeContent(
-            final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
-        ConsumingNHttpEntity consumer = getConsumingHttpEntity();
-        consumer.consumeContent(decoder, ioctrl);
     }
 
-    private void reset() {
+    public synchronized void resetRequest() {
         if (this.contentProducingEntity != null) {
             try {
                 this.contentProducingEntity.finish();
@@ -150,60 +121,6 @@ public class BasicHttpAsyncExchangeHandl
             } catch (IOException ex) {
             }
         }
-        if (this.contentConsumingEntity != null) {
-            try {
-                this.contentConsumingEntity.finish();
-                this.contentConsumingEntity = null;
-            } catch (IOException ex) {
-            }
-        }
-    }
-
-    public synchronized void cancel() {
-        if (this.completed) {
-            return;
-        }
-        this.completed = true;
-        this.response = null;
-        reset();
-    }
-
-    public synchronized void failed(final Exception ex) {
-        if (this.completed) {
-            return;
-        }
-        this.completed = true;
-        this.ex = ex;
-        this.response = null;
-        reset();
-    }
-
-    public synchronized void completed() {
-        if (this.completed) {
-            return;
-        }
-        this.completed = true;
-        if (this.response != null) {
-            this.result = this.response;
-            this.result.setEntity(this.contentConsumingEntity);
-        }
-        reset();
-    }
-
-    public boolean isCompleted() {
-        return this.completed;
-    }
-
-    public Exception getException() {
-        return this.ex;
-    }
-
-    public void setEx(Exception ex) {
-        this.ex = ex;
-    }
-
-    public HttpResponse getResult() {
-        return this.response;
     }
 
 }

Copied: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncResponseConsumer.java
(from r1042948, httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncExchangeHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncResponseConsumer.java?p2=httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncResponseConsumer.java&p1=httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncExchangeHandler.java&r1=1042948&r2=1043057&rev=1043057&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncExchangeHandler.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/impl/nio/client/BasicHttpAsyncResponseConsumer.java
Tue Dec  7 14:17:31 2010
@@ -28,51 +28,24 @@ package org.apache.http.impl.nio.client;
 
 import java.io.IOException;
 
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.nio.ContentDecoder;
-import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.client.HttpAsyncExchangeHandler;
+import org.apache.http.nio.client.HttpAsyncResponseConsumer;
 import org.apache.http.nio.entity.BufferingNHttpEntity;
 import org.apache.http.nio.entity.ConsumingNHttpEntity;
-import org.apache.http.nio.entity.NHttpEntityWrapper;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
 
-public class BasicHttpAsyncExchangeHandler implements HttpAsyncExchangeHandler<HttpResponse>
{
-
-    private final HttpHost target;
-    private final HttpRequest request;
+public class BasicHttpAsyncResponseConsumer implements HttpAsyncResponseConsumer<HttpResponse>
{
 
     private volatile HttpResponse response;
-    private volatile ProducingNHttpEntity contentProducingEntity;
     private volatile ConsumingNHttpEntity contentConsumingEntity;
     private volatile HttpResponse result;
     private volatile Exception ex;
     private volatile boolean completed;
 
-    public BasicHttpAsyncExchangeHandler(final HttpHost target, final HttpRequest request)
{
+    public BasicHttpAsyncResponseConsumer() {
         super();
-        if (target == null) {
-            throw new IllegalArgumentException("Target host may not be null");
-        }
-        if (request == null) {
-            throw new IllegalArgumentException("HTTP request may not be null");
-        }
-        this.target = target;
-        this.request = request;
-    }
-
-    public HttpRequest generateRequest() {
-        return this.request;
-    }
-
-    public HttpHost getTarget() {
-        return this.target;
     }
 
     protected ConsumingNHttpEntity createConsumingHttpEntity(
@@ -84,25 +57,6 @@ public class BasicHttpAsyncExchangeHandl
         }
     }
 
-    protected ProducingNHttpEntity createProducingHttpEntity(
-            final HttpRequest request) throws IOException {
-        HttpEntityEnclosingRequest entityReq;
-        HttpEntity entity = null;
-        if (request instanceof HttpEntityEnclosingRequest) {
-            entityReq = (HttpEntityEnclosingRequest) request;
-            entity = entityReq.getEntity();
-        }
-        if (entity != null) {
-            if (entity instanceof ProducingNHttpEntity) {
-                return (ProducingNHttpEntity) entity;
-            } else {
-                return new NHttpEntityWrapper(entity);
-            }
-        } else {
-            return null;
-        }
-    }
-
     private ConsumingNHttpEntity getConsumingHttpEntity() throws IOException {
         if (this.contentConsumingEntity == null) {
             this.contentConsumingEntity = createConsumingHttpEntity(this.response);
@@ -113,22 +67,6 @@ public class BasicHttpAsyncExchangeHandl
         return this.contentConsumingEntity;
     }
 
-    private ProducingNHttpEntity getProducingHttpEntity() throws IOException {
-        if (this.contentProducingEntity == null) {
-            this.contentProducingEntity = createProducingHttpEntity(this.request);
-            if (this.contentProducingEntity == null) {
-                throw new IllegalStateException("Content producer is null");
-            }
-        }
-        return this.contentProducingEntity;
-    }
-
-    public synchronized void produceContent(
-            final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
-        ProducingNHttpEntity producer = getProducingHttpEntity();
-        producer.produceContent(encoder, ioctrl);
-    }
-
     public synchronized void responseReceived(final HttpResponse response) {
         if (this.response != null) {
             throw new IllegalStateException("HTTP response already set");
@@ -143,13 +81,6 @@ public class BasicHttpAsyncExchangeHandl
     }
 
     private void reset() {
-        if (this.contentProducingEntity != null) {
-            try {
-                this.contentProducingEntity.finish();
-                this.contentProducingEntity = null;
-            } catch (IOException ex) {
-            }
-        }
         if (this.contentConsumingEntity != null) {
             try {
                 this.contentConsumingEntity.finish();

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=1043057&r1=1043056&r2=1043057&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 Dec  7 14:17:31 2010
@@ -50,6 +50,8 @@ import org.apache.http.nio.ContentDecode
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
 import org.apache.http.nio.client.HttpAsyncExchangeHandler;
+import org.apache.http.nio.client.HttpAsyncRequestProducer;
+import org.apache.http.nio.client.HttpAsyncResponseConsumer;
 import org.apache.http.nio.concurrent.BasicFuture;
 import org.apache.http.nio.concurrent.FutureCallback;
 import org.apache.http.nio.conn.IOSessionManager;
@@ -65,8 +67,9 @@ class DefaultAsyncRequestDirector<T> imp
 
     public static final String HTTP_EXCHANGE_HANDLER = "http.nio.async-exchange-handler";
 
+    private final HttpAsyncRequestProducer requestProducer;
+    private final HttpAsyncResponseConsumer<T> responseConsumer;
     private final BasicFuture<T> resultFuture;
-    private final HttpAsyncExchangeHandler<T> handler;
     private final IOSessionManager<HttpRoute> sessmrg;
     private final HttpProcessor httppocessor;
     private final HttpContext localContext;
@@ -79,14 +82,16 @@ class DefaultAsyncRequestDirector<T> imp
     private ManagedIOSession managedSession;
 
     public DefaultAsyncRequestDirector(
-            final HttpAsyncExchangeHandler<T> handler,
+            final HttpAsyncRequestProducer requestProducer,
+            final HttpAsyncResponseConsumer<T> responseConsumer,
             final FutureCallback<T> callback,
             final IOSessionManager<HttpRoute> sessmrg,
             final HttpProcessor httppocessor,
             final HttpContext localContext,
             final HttpParams clientParams) {
         super();
-        this.handler = handler;
+        this.requestProducer = requestProducer;
+        this.responseConsumer = responseConsumer;
         this.resultFuture = new BasicFuture<T>(callback);
         this.sessmrg = sessmrg;
         this.httppocessor = httppocessor;
@@ -96,8 +101,8 @@ class DefaultAsyncRequestDirector<T> imp
 
     public void start() {
         try {
-            HttpHost target = this.handler.getTarget();
-            this.originalRequest = this.handler.generateRequest();
+            HttpHost target = this.requestProducer.getTarget();
+            this.originalRequest = this.requestProducer.generateRequest();
             HttpParams params = new ClientParamsStack(
                     null, this.clientParams, this.originalRequest.getParams(), null);
             this.currentRequest = wrapRequest(this.originalRequest);
@@ -123,7 +128,7 @@ class DefaultAsyncRequestDirector<T> imp
     }
 
     public HttpHost getTarget() {
-        return this.handler.getTarget();
+        return this.requestProducer.getTarget();
     }
 
     public HttpRequest generateRequest() throws IOException, HttpException {
@@ -150,19 +155,30 @@ class DefaultAsyncRequestDirector<T> imp
 
     public void produceContent(
             final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
-        this.handler.produceContent(encoder, ioctrl);
+        this.requestProducer.produceContent(encoder, ioctrl);
+        if (encoder.isCompleted()) {
+            this.requestProducer.resetRequest();
+        }
+    }
+
+    public boolean isRepeatable() {
+        return this.requestProducer.isRepeatable();
+    }
+
+    public void resetRequest() {
+        this.requestProducer.resetRequest();
     }
 
     public void responseReceived(final HttpResponse response) throws IOException, HttpException
{
         response.setParams(this.currentRequest.getParams());
         this.localContext.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
         this.httppocessor.process(response, this.localContext);
-        this.handler.responseReceived(response);
+        this.responseConsumer.responseReceived(response);
     }
 
     public void consumeContent(
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
-        this.handler.consumeContent(decoder, ioctrl);
+        this.responseConsumer.consumeContent(decoder, ioctrl);
     }
 
     public synchronized void completed() {
@@ -171,8 +187,9 @@ class DefaultAsyncRequestDirector<T> imp
                 this.managedSession.releaseSession();
             }
             this.managedSession = null;
-            this.handler.completed();
-            this.resultFuture.completed(this.handler.getResult());
+            this.requestProducer.resetRequest();
+            this.responseConsumer.completed();
+            this.resultFuture.completed(this.responseConsumer.getResult());
         } catch (RuntimeException runex) {
             this.resultFuture.failed(runex);
             throw runex;
@@ -186,7 +203,8 @@ class DefaultAsyncRequestDirector<T> imp
                 this.managedSession.abortSession();
             }
             this.managedSession = null;
-            this.handler.failed(ex);
+            this.requestProducer.resetRequest();
+            this.responseConsumer.failed(ex);
             this.resultFuture.failed(ex);
         } catch (RuntimeException runex) {
             this.resultFuture.failed(ex);
@@ -201,7 +219,8 @@ class DefaultAsyncRequestDirector<T> imp
                 this.managedSession.abortSession();
             }
             this.managedSession = null;
-            this.handler.cancel();
+            this.requestProducer.resetRequest();
+            this.responseConsumer.cancel();
             this.resultFuture.cancel(true);
         } catch (RuntimeException runex) {
             this.resultFuture.failed(runex);
@@ -210,11 +229,11 @@ class DefaultAsyncRequestDirector<T> imp
     }
 
     public boolean isCompleted() {
-        return this.handler.isCompleted();
+        return this.responseConsumer.isCompleted();
     }
 
     public T getResult() {
-        return this.handler.getResult();
+        return this.responseConsumer.getResult();
     }
 
     private synchronized void sessionRequestCompleted(final ManagedIOSession session) {
@@ -226,7 +245,8 @@ class DefaultAsyncRequestDirector<T> imp
 
     private synchronized void sessionRequestFailed(final Exception ex) {
         try {
-            this.handler.failed(ex);
+            this.requestProducer.resetRequest();
+            this.responseConsumer.failed(ex);
         } finally {
             this.resultFuture.failed(ex);
         }
@@ -234,7 +254,8 @@ class DefaultAsyncRequestDirector<T> imp
 
     private synchronized void sessionRequestCancelled() {
         try {
-            this.handler.cancel();
+            this.requestProducer.resetRequest();
+            this.responseConsumer.cancel();
         } finally {
             this.resultFuture.cancel(true);
         }

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java?rev=1043057&r1=1043056&r2=1043057&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncClient.java
Tue Dec  7 14:17:31 2010
@@ -44,11 +44,14 @@ public interface HttpAsyncClient {
     IOReactorStatus getStatus();
 
     <T> Future<T> execute(
-            HttpAsyncExchangeHandler<T> handler, HttpContext context,
+            HttpAsyncRequestProducer requestProducer,
+            HttpAsyncResponseConsumer<T> responseConsumer,
+            HttpContext context,
             FutureCallback<T> callback);
 
     <T> Future<T> execute(
-            HttpAsyncExchangeHandler<T> handler,
+            HttpAsyncRequestProducer requestProducer,
+            HttpAsyncResponseConsumer<T> responseConsumer,
             FutureCallback<T> callback);
 
     Future<HttpResponse> execute(

Modified: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java?rev=1043057&r1=1043056&r2=1043057&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java
Tue Dec  7 14:17:31 2010
@@ -26,36 +26,7 @@
  */
 package org.apache.http.nio.client;
 
-import java.io.IOException;
-
-import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.nio.ContentDecoder;
-import org.apache.http.nio.ContentEncoder;
-import org.apache.http.nio.IOControl;
-
-public interface HttpAsyncExchangeHandler<T> {
-
-    HttpHost getTarget();
-
-    HttpRequest generateRequest() throws IOException, HttpException;
-
-    void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException;
-
-    void responseReceived(HttpResponse response) throws IOException, HttpException;
-
-    void consumeContent(ContentDecoder decoder, IOControl ioctrl) throws IOException;
-
-    void completed();
-
-    void failed(Exception ex);
-
-    void cancel();
-
-    boolean isCompleted();
-
-    T getResult();
+public interface HttpAsyncExchangeHandler<T>
+    extends HttpAsyncRequestProducer, HttpAsyncResponseConsumer<T> {
 
 }

Copied: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java
(from r1042948, httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java?p2=httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java&p1=httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java&r1=1042948&r2=1043057&rev=1043057&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java
Tue Dec  7 14:17:31 2010
@@ -31,12 +31,10 @@ import java.io.IOException;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
 
-public interface HttpAsyncExchangeHandler<T> {
+public interface HttpAsyncRequestProducer {
 
     HttpHost getTarget();
 
@@ -44,18 +42,8 @@ public interface HttpAsyncExchangeHandle
 
     void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException;
 
-    void responseReceived(HttpResponse response) throws IOException, HttpException;
+    boolean isRepeatable();
 
-    void consumeContent(ContentDecoder decoder, IOControl ioctrl) throws IOException;
-
-    void completed();
-
-    void failed(Exception ex);
-
-    void cancel();
-
-    boolean isCompleted();
-
-    T getResult();
+    void resetRequest();
 
 }

Copied: httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java
(from r1042948, httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java?p2=httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java&p1=httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java&r1=1042948&r2=1043057&rev=1043057&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncExchangeHandler.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java
Tue Dec  7 14:17:31 2010
@@ -29,20 +29,11 @@ package org.apache.http.nio.client;
 import java.io.IOException;
 
 import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.nio.ContentDecoder;
-import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
 
-public interface HttpAsyncExchangeHandler<T> {
-
-    HttpHost getTarget();
-
-    HttpRequest generateRequest() throws IOException, HttpException;
-
-    void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException;
+public interface HttpAsyncResponseConsumer<T> {
 
     void responseReceived(HttpResponse response) throws IOException, HttpException;
 

Modified: httpcomponents/httpasyncclient/trunk/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java?rev=1043057&r1=1043056&r2=1043057&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
(original)
+++ httpcomponents/httpasyncclient/trunk/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
Tue Dec  7 14:17:31 2010
@@ -149,33 +149,26 @@ public class TestHttpAsync extends Serve
     public void testMultipleRequestFailures() throws Exception {
         this.httpclient.start();
 
-        Queue<Future<HttpResponse>> queue = new LinkedList<Future<HttpResponse>>();
-
-        for (int i = 0; i < 3; i++) {
-            HttpGet httpget = new HttpGet("/random/2048");
-            BasicHttpAsyncExchangeHandler kaboom = new BasicHttpAsyncExchangeHandler(this.target,
httpget) {
-
-                @Override
-                public void consumeContent(final ContentDecoder decoder, final IOControl
ioctrl)
-                        throws IOException {
-                    throw new IOException("Kaboom");
-                }
-
-            };
-            queue.add(this.httpclient.execute(kaboom, null));
-        }
-
-        while (!queue.isEmpty()) {
-            Future<HttpResponse> future = queue.remove();
-            try {
-                future.get();
-                Assert.fail("ExecutionException expected");
-            } catch (ExecutionException ex) {
-                Throwable t = ex.getCause();
-                Assert.assertNotNull(t);
-                Assert.assertTrue(t instanceof IOException);
-                Assert.assertEquals("Kaboom", t.getMessage());
+        HttpGet httpget = new HttpGet("/random/2048");
+        BasicHttpAsyncRequestProducer requestProducer = new BasicHttpAsyncRequestProducer(this.target,
httpget) ;
+        BasicHttpAsyncResponseConsumer responseConsumer = new BasicHttpAsyncResponseConsumer()
{
+
+            @Override
+            public void consumeContent(final ContentDecoder decoder, final IOControl ioctrl)
+                    throws IOException {
+                throw new IOException("Kaboom");
             }
+
+        };
+        Future<HttpResponse> future = this.httpclient.execute(requestProducer, responseConsumer,
null);
+        try {
+            future.get();
+            Assert.fail("ExecutionException expected");
+        } catch (ExecutionException ex) {
+            Throwable t = ex.getCause();
+            Assert.assertNotNull(t);
+            Assert.assertTrue(t instanceof IOException);
+            Assert.assertEquals("Kaboom", t.getMessage());
         }
     }
 



Mime
View raw message