Class FutureRequestExecutionService
- java.lang.Object
-
- org.apache.hc.client5.http.impl.classic.FutureRequestExecutionService
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
@Contract(threading=SAFE_CONDITIONAL) public class FutureRequestExecutionService extends java.lang.Object implements java.io.CloseableThis class schedules message execution execution and processing asFutureTasks with the providedExecutorService.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBooleanclosedprivate java.util.concurrent.ExecutorServiceexecutorServiceprivate HttpClienthttpclientprivate FutureRequestExecutionMetricsmetrics
-
Constructor Summary
Constructors Constructor Description FutureRequestExecutionService(HttpClient httpclient, java.util.concurrent.ExecutorService executorService)Create a new FutureRequestExecutionService.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()<T> java.util.concurrent.FutureTask<T>execute(org.apache.hc.core5.http.ClassicHttpRequest request, org.apache.hc.core5.http.protocol.HttpContext context, org.apache.hc.core5.http.io.HttpClientResponseHandler<T> HttpClientResponseHandler)Schedule a request for execution.<T> java.util.concurrent.FutureTask<T>execute(org.apache.hc.core5.http.ClassicHttpRequest request, org.apache.hc.core5.http.protocol.HttpContext context, org.apache.hc.core5.http.io.HttpClientResponseHandler<T> HttpClientResponseHandler, org.apache.hc.core5.concurrent.FutureCallback<T> callback)Schedule a request for execution.FutureRequestExecutionMetricsmetrics()
-
-
-
Field Detail
-
httpclient
private final HttpClient httpclient
-
executorService
private final java.util.concurrent.ExecutorService executorService
-
metrics
private final FutureRequestExecutionMetrics metrics
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
-
Constructor Detail
-
FutureRequestExecutionService
public FutureRequestExecutionService(HttpClient httpclient, java.util.concurrent.ExecutorService executorService)
Create a new FutureRequestExecutionService.- Parameters:
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)
-
-
Method Detail
-
execute
public <T> java.util.concurrent.FutureTask<T> execute(org.apache.hc.core5.http.ClassicHttpRequest request, org.apache.hc.core5.http.protocol.HttpContext context, org.apache.hc.core5.http.io.HttpClientResponseHandler<T> HttpClientResponseHandler)Schedule a request for execution.- Type Parameters:
T-- Parameters:
request- request to executeHttpClientResponseHandler- handler that will process the response.- Returns:
- HttpAsyncClientFutureTask for the scheduled request.
-
execute
public <T> java.util.concurrent.FutureTask<T> execute(org.apache.hc.core5.http.ClassicHttpRequest request, org.apache.hc.core5.http.protocol.HttpContext context, org.apache.hc.core5.http.io.HttpClientResponseHandler<T> HttpClientResponseHandler, org.apache.hc.core5.concurrent.FutureCallback<T> callback)Schedule a request for execution.- Type Parameters:
T-- Parameters:
request- request to executecontext- optional context; use null if not needed.HttpClientResponseHandler- handler that will process the response.callback- callback handler that will be called when the request is scheduled, started, completed, failed, or cancelled.- Returns:
- HttpAsyncClientFutureTask for the scheduled request.
-
metrics
public FutureRequestExecutionMetrics metrics()
- Returns:
- metrics gathered for this instance.
- See Also:
FutureRequestExecutionMetrics
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-