Class FutureRequestExecutionService

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    @Contract(threading=SAFE)
    public class FutureRequestExecutionService
    extends java.lang.Object
    implements java.io.Closeable
    HttpAsyncClientWithFuture wraps calls to execute with a HttpRequestFutureTask and schedules them using the provided executor service. Scheduled calls may be cancelled.
    • 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> HttpRequestFutureTask<T> execute​(HttpUriRequest request,
                                                    HttpContext context,
                                                    ResponseHandler<T> responseHandler)
        Schedule a request for execution.
        Type Parameters:
        T -
        Parameters:
        request - request to execute
        responseHandler - handler that will process the response.
        Returns:
        HttpAsyncClientFutureTask for the scheduled request.
      • execute

        public <T> HttpRequestFutureTask<T> execute​(HttpUriRequest request,
                                                    HttpContext context,
                                                    ResponseHandler<T> responseHandler,
                                                    FutureCallback<T> callback)
        Schedule a request for execution.
        Type Parameters:
        T -
        Parameters:
        request - request to execute
        context - 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.
        Returns:
        HttpAsyncClientFutureTask for the scheduled request.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException