@Contract(threading=SAFE)
public class FutureRequestExecutionService
extends java.lang.Object
implements java.io.Closeable
HttpRequestFutureTask
and schedules them using the provided executor service. Scheduled calls may be cancelled.| Modifier and Type | Field and Description |
|---|---|
private java.util.concurrent.atomic.AtomicBoolean |
closed |
private java.util.concurrent.ExecutorService |
executorService |
private HttpClient |
httpclient |
private FutureRequestExecutionMetrics |
metrics |
| Constructor and Description |
|---|
FutureRequestExecutionService(HttpClient httpclient,
java.util.concurrent.ExecutorService executorService)
Create a new FutureRequestExecutionService.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
<T> HttpRequestFutureTask<T> |
execute(HttpUriRequest request,
org.apache.http.protocol.HttpContext context,
ResponseHandler<T> responseHandler)
Schedule a request for execution.
|
<T> HttpRequestFutureTask<T> |
execute(HttpUriRequest request,
org.apache.http.protocol.HttpContext context,
ResponseHandler<T> responseHandler,
org.apache.http.concurrent.FutureCallback<T> callback)
Schedule a request for execution.
|
FutureRequestExecutionMetrics |
metrics() |
private final HttpClient httpclient
private final java.util.concurrent.ExecutorService executorService
private final FutureRequestExecutionMetrics metrics
private final java.util.concurrent.atomic.AtomicBoolean closed
public FutureRequestExecutionService(HttpClient httpclient, java.util.concurrent.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, org.apache.http.protocol.HttpContext context, ResponseHandler<T> responseHandler)
T - request - request to executeresponseHandler - handler that will process the response.public <T> HttpRequestFutureTask<T> execute(HttpUriRequest request, org.apache.http.protocol.HttpContext context, ResponseHandler<T> responseHandler, org.apache.http.concurrent.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.public FutureRequestExecutionMetrics metrics()
FutureRequestExecutionMetricspublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException