hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xasima <xas...@gmail.com>
Subject Re: how to terminate data consuming by asyncclient without declining of the result
Date Wed, 10 Aug 2011 12:39:29 GMT
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,
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
 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,
        *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) {
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*

> 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? Do i need to rewrite
 AbstractHttpAsyncClient to allow him to accept custom ResultCallback
instead of the Default one.
        ResultCallback<T> resultCallback = new
DefaultResultCallback<T>(future, this.queue);

> > Can you recommend another approach to perform partial nio data consuming
> (n
> > threads) and parsing (m threads).
> From what I can gather you would much better off using an HTTP client
> based on a blocking I/O model.

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.

Best regards,
     ~ Xasima ~

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message