Example usage for org.apache.http.impl.nio.client CloseableHttpAsyncClient CloseableHttpAsyncClient

List of usage examples for org.apache.http.impl.nio.client CloseableHttpAsyncClient CloseableHttpAsyncClient

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.client CloseableHttpAsyncClient CloseableHttpAsyncClient.

Prototype

CloseableHttpAsyncClient

Source Link

Usage

From source file:co.paralleluniverse.fibers.dropwizard.InstrumentedNHttpClientBuilder.java

@Override
public CloseableHttpAsyncClient build() {

    final CloseableHttpAsyncClient ac = super.build();
    return new CloseableHttpAsyncClient() {

        @Override/*from w ww  .j  av a  2s. c  o  m*/
        public boolean isRunning() {
            return ac.isRunning();
        }

        @Override
        public void start() {
            ac.start();
        }

        @Override
        public <T> Future<T> execute(HttpAsyncRequestProducer requestProducer,
                HttpAsyncResponseConsumer<T> responseConsumer, HttpContext context,
                FutureCallback<T> callback) {
            final Timer.Context timerContext;
            try {
                timerContext = timer(requestProducer.generateRequest()).time();
            } catch (IOException | HttpException ex) {
                throw new AssertionError();
            }
            try {
                return ac.execute(requestProducer, responseConsumer, context, callback);
            } finally {
                timerContext.stop();
            }
        }

        @Override
        public void close() throws IOException {
            ac.close();
        }
    };
}