Example usage for org.apache.http.impl.nio.client DefaultResultCallback DefaultResultCallback

List of usage examples for org.apache.http.impl.nio.client DefaultResultCallback DefaultResultCallback

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.client DefaultResultCallback DefaultResultCallback.

Prototype

DefaultResultCallback(final BasicFuture<T> future, final Queue<HttpAsyncRequestExecutionHandler<?>> queue) 

Source Link

Usage

From source file:org.apache.http.impl.nio.client.AbstractHttpAsyncClient.java

@Override
public <T> Future<T> execute(final HttpAsyncRequestProducer requestProducer,
        final HttpAsyncResponseConsumer<T> responseConsumer, final HttpContext context,
        final FutureCallback<T> callback) {
    if (this.terminated) {
        throw new IllegalStateException("Client has been shut down");
    }/*  w  w w. j a v  a 2  s. c  om*/
    final BasicFuture<T> future = new BasicFuture<T>(callback);
    final ResultCallback<T> resultCallback = new DefaultResultCallback<T>(future, this.queue);
    DefaultAsyncRequestDirector<T> httpexchange;
    synchronized (this) {
        final HttpContext defaultContext = createHttpContext();
        HttpContext execContext;
        if (context == null) {
            execContext = defaultContext;
        } else {
            execContext = new DefaultedHttpContext(context, defaultContext);
        }
        httpexchange = new DefaultAsyncRequestDirector<T>(this.log, requestProducer, responseConsumer,
                execContext, resultCallback, this.connmgr, getProtocolProcessor(), getRoutePlanner(),
                getConnectionReuseStrategy(), getConnectionKeepAliveStrategy(), getRedirectStrategy(),
                getTargetAuthenticationStrategy(), getProxyAuthenticationStrategy(), getUserTokenHandler(),
                getParams());
    }
    this.queue.add(httpexchange);
    httpexchange.start();
    return future;
}