@ThreadSafe public class FutureRequestExecutionService extends Object implements Closeable
HttpRequestFutureTask
and schedules them using the provided executor service. Scheduled calls may be cancelled.
Similar to the non-blockcing HttpAsyncClient, a callback handler api is provided.Constructor and Description |
---|
FutureRequestExecutionService(HttpClient httpclient,
ExecutorService executorService)
Create a new FutureRequestExecutionService.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
<T> HttpRequestFutureTask<T> |
execute(HttpUriRequest request,
HttpContext context,
ResponseHandler<T> responseHandler)
Schedule a request for execution.
|
<T> HttpRequestFutureTask<T> |
execute(HttpUriRequest request,
HttpContext context,
ResponseHandler<T> responseHandler,
FutureCallback<T> callback)
Schedule a request for execution.
|
<T> List<Future<T>> |
executeMultiple(HttpContext context,
ResponseHandler<T> responseHandler,
FutureCallback<T> callback,
long timeout,
TimeUnit timeUnit,
HttpUriRequest... requests)
Schedule multiple requests for execution with a timeout.
|
<T> List<Future<T>> |
executeMultiple(ResponseHandler<T> responseHandler,
HttpUriRequest... requests)
Schedule multiple requests for execution.
|
FutureRequestExecutionMetrics |
metrics() |
public FutureRequestExecutionService(HttpClient httpclient, ExecutorService executorService)
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
- any executorService will do here. E.g. Executors.newFixedThreadPool(int)
public <T> HttpRequestFutureTask<T> execute(HttpUriRequest request, HttpContext context, ResponseHandler<T> responseHandler)
T
- request
- request to executeresponseHandler
- handler that will process the response.InterruptedException
public <T> HttpRequestFutureTask<T> execute(HttpUriRequest request, HttpContext context, ResponseHandler<T> responseHandler, FutureCallback<T> callback)
T
- request
- request to executecontext
- optional context; use null if not needed.responseHandler
- handler that will process the response.callback
- callback handler that will be called when the request is scheduled,
started, completed, failed, or cancelled.InterruptedException
public <T> List<Future<T>> executeMultiple(ResponseHandler<T> responseHandler, HttpUriRequest... requests) throws InterruptedException
T
- responseHandler
- handler that will process the responses.requests
- one or more requests.InterruptedException
public <T> List<Future<T>> executeMultiple(HttpContext context, ResponseHandler<T> responseHandler, FutureCallback<T> callback, long timeout, TimeUnit timeUnit, HttpUriRequest... requests) throws InterruptedException
T
- context
- optional context; use null if not needed.responseHandler
- handler that will process the responses.callback
- callback handler that will be called when requests are scheduled,
started, completed, failed, or cancelled.timeout
- timeUnit
- requests
- one or more requests.InterruptedException
public FutureRequestExecutionMetrics metrics()
FutureRequestExecutionMetrics
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 1999-2013 The Apache Software Foundation. All Rights Reserved.