All Downloads are FREE. Search and download functionalities are using the official Maven repository.

netflix.ocelli.rxnetty.HttpClientPool Maven / Gradle / Ivy

package netflix.ocelli.rxnetty;

import io.netty.buffer.ByteBuf;
import io.reactivex.netty.RxNetty;
import io.reactivex.netty.pipeline.PipelineConfigurator;
import io.reactivex.netty.protocol.http.client.HttpClient;
import io.reactivex.netty.protocol.http.client.HttpClientRequest;
import io.reactivex.netty.protocol.http.client.HttpClientResponse;
import netflix.ocelli.Host;
import rx.functions.Func1;

/**
 * An implementation of {@link RxNettyClientPool} for HTTP clients.
 *
 * @author Nitesh Kant
 */
public class HttpClientPool extends RxNettyClientPool, HttpClientResponse, HttpClient> {

    private final Func1> clientFactory;

    public HttpClientPool(final PipelineConfigurator, HttpClientRequest> configurator) {
        this(new Func1>() {
            @Override
            public HttpClient call(Host host) {
                return RxNetty.createHttpClient(host.getHostName(), host.getPort(), configurator);
            }
        });
    }

    public HttpClientPool(Func1> clientFactory) {
        this.clientFactory = clientFactory;
    }

    @Override
    protected HttpClient createClient(Host host) {
        return clientFactory.call(host);
    }

    public static HttpClientPool newPool() {
        return new HttpClientPool(new Func1>() {
            @Override
            public HttpClient call(Host host) {
                return RxNetty.createHttpClient(host.getHostName(), host.getPort());
            }
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy