Top Description Fields Constructors Methods
org.apache.http.impl.client

public Class FutureRequestExecutionService

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Annotations
@Contract
threading:SAFE
Imports
java.io.Closeable, .IOException, java.util.concurrent.ExecutorService, java.util.concurrent.atomic.AtomicBoolean, org.apache.http.annotation.Contract, .ThreadingBehavior, org.apache.http.client.HttpClient, .ResponseHandler, org.apache.http.client.methods.HttpUriRequest, org.apache.http.concurrent.FutureCallback, org.apache.http.protocol.HttpContext

HttpAsyncClientWithFuture wraps calls to execute with a HttpRequestFutureTask and schedules them using the provided executor service. Scheduled calls may be cancelled.

Field Summary

Modifier and TypeField and Description
private final AtomicBoolean
private final ExecutorService
private final HttpClient
private final FutureRequestExecutionMetrics

Constructor Summary

AccessConstructor and Description
public
FutureRequestExecutionService(final HttpClient
you should tune your httpclient instance to match your needs. You should align the max number of connections in the pool and the number of threads in the executor; it doesn't make sense to have more threads than connections and if you have less connections than threads, the threads will just end up blocking on getting a connection from the pool.
httpclient
,
final ExecutorService
any executorService will do here. E.g. java.util.concurrent.Executors#newFixedThreadPool(int)
executorService
)

Create a new FutureRequestExecutionService.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
public <T> HttpRequestFutureTask<T>

Returns:

HttpAsyncClientFutureTask for the scheduled request.
execute
(final HttpUriRequest
request to execute
request
,
final HttpContext context, final ResponseHandler<T>
handler that will process the response.
responseHandler
)

Schedule a request for execution.

public <T> HttpRequestFutureTask<T>

Returns:

HttpAsyncClientFutureTask for the scheduled request.
execute
(final HttpUriRequest
request to execute
request
,
final HttpContext
optional context; use null if not needed.
context
,
final ResponseHandler<T>
handler that will process the response.
responseHandler
,
final FutureCallback<T>
callback handler that will be called when the request is scheduled, started, completed, failed, or cancelled.
callback
)

Schedule a request for execution.

public FutureRequestExecutionMetrics

Returns:

metrics gathered for this instance.
metrics
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
private final AtomicBoolean closed
executorServiceback to summary
private final ExecutorService executorService
httpclientback to summary
private final HttpClient httpclient
metricsback to summary
private final FutureRequestExecutionMetrics metrics

Constructor Detail

FutureRequestExecutionServiceback to summary
public FutureRequestExecutionService(final HttpClient httpclient, final ExecutorService executorService)

Create a new FutureRequestExecutionService.

Parameters
httpclient:HttpClient

you should tune your httpclient instance to match your needs. You should align the max number of connections in the pool and the number of threads in the executor; it doesn't make sense to have more threads than connections and if you have less connections than threads, the threads will just end up blocking on getting a connection from the pool.

executorService:ExecutorService

any executorService will do here. E.g. java.util.concurrent.Executors#newFixedThreadPool(int)

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
executeback to summary
public <T> HttpRequestFutureTask<T> execute(final HttpUriRequest request, final HttpContext context, final ResponseHandler<T> responseHandler)

Schedule a request for execution.

Parameters
request:HttpUriRequest

request to execute

responseHandler:ResponseHandler<T>

handler that will process the response.

Returns:HttpRequestFutureTask<T>

HttpAsyncClientFutureTask for the scheduled request.

executeback to summary
public <T> HttpRequestFutureTask<T> execute(final HttpUriRequest request, final HttpContext context, final ResponseHandler<T> responseHandler, final FutureCallback<T> callback)

Schedule a request for execution.

Parameters
request:HttpUriRequest

request to execute

context:HttpContext

optional context; use null if not needed.

responseHandler:ResponseHandler<T>

handler that will process the response.

callback:FutureCallback<T>

callback handler that will be called when the request is scheduled, started, completed, failed, or cancelled.

Returns:HttpRequestFutureTask<T>

HttpAsyncClientFutureTask for the scheduled request.

metricsback to summary
public FutureRequestExecutionMetrics metrics()
Returns:FutureRequestExecutionMetrics

metrics gathered for this instance.

See Also
FutureRequestExecutionMetrics