hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: how to terminate data consuming by asyncclient without declining of the result
Date Wed, 10 Aug 2011 14:00:09 GMT
On Wed, 2011-08-10 at 15:39 +0300, Xasima wrote:
> On Tue, Aug 9, 2011 at 10:24 PM, Oleg Kalnichevski <olegk@apache.org> wrote:
> 
> > On Tue, 2011-08-09 at 19:24 +0300, Xasima wrote:
> >
> > You can use IOControl#shutdown() to shut down the underlying connection.
> >
> 
> Sorry,  I can't avoid  an empty result of future.get() here
> Future<Integer> future = httpclient.execute(httpAsyncGet, parsingConsumer,
> futureCallback);
> Integer res = future.get();
> 
> due to the following reasons.
> 
> 1) control.shutdown() add the connection to the closedConnectionsQueue.
> 2) Later AbstractIOReactor executes processClosedSessions() procedure in
> which NHttpClientProtocolHandler execute cancel due to not empty handler on
> conn.
>  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 (handler != null) {*
> *            handler.cancel();*
> *        }*
>     }
> 3) the later is processed by DefaultAsyncRequestDirector with accessing the
> methods of DefaultResultCallback
> public void cancelled(final HttpAsyncExchangeHandler<T> handler) {
>         this.future.cancel(true);
>         this.queue.remove(handler);
>     }
> Please, compare the latest with another method in this class  ...
>  public void completed(final T result, final HttpAsyncExchangeHandler<T>
> handler) {
>         *this.future.completed(result); // HERE future.result = result*
>         this.queue.remove(handler);
>     }
> 
>
> 
> > You will also have to build a custom HttpAsyncResponseConsumer
> > implementation that retains its state even if the underlying connection
> > gets terminated.
> 
> 
> Thus my custom HttpAsyncResponseConsumer that tries to execute if(isTerminated)
> this.result = buildResult(); even in cancel() method doesn't help me. It
> seems that DefaultAsyncRequestDirector doesn't copy
> my  HttpAsyncResponseConsumer.getResults() into the BasicFuture.result
> 
> Can you provide any work around?

I just added a bit of code intended to make sure the state of the
response consumer gets carried over to its respective future even if the
HTTP exchange has been canceled prematurely.

http://svn.apache.org/viewvc?view=revision&revision=1156184

Please upgrade to the latest SVN shapshot to pick up the fix.

Please also note that one can always get the result from the response
consumer regardless of the state of the future object.


> I'm trying to minimize CPU& Memory load when parsing a number of (search
> based) http connections, so blocking I/O may not be suitable for this case.
> 

What makes you think blocking I/O is less efficient in terms of CPU and
memory utilization?  

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message