Example usage for org.apache.http.conn DnsResolver DnsResolver

List of usage examples for org.apache.http.conn DnsResolver DnsResolver

Introduction

In this page you can find the example usage for org.apache.http.conn DnsResolver DnsResolver.

Prototype

DnsResolver

Source Link

Usage

From source file:io.fabric8.kit.build.service.docker.access.hc.util.AbstractNativeClientBuilder.java

private DnsResolver nullDnsResolver() {
    return new DnsResolver() {
        @Override/*from ww  w. java2 s. c  o m*/
        public InetAddress[] resolve(final String host) throws UnknownHostException {
            return new InetAddress[] { null };
        }
    };
}

From source file:net.yacy.cora.protocol.http.HTTPClient.java

private static PoolingHttpClientConnectionManager initPoolingConnectionManager() {
    final PlainConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
    final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", plainsf).register("https", getSSLSocketFactory()).build();
    final PoolingHttpClientConnectionManager pooling = new PoolingHttpClientConnectionManager(registry, null,
            null, new DnsResolver() {
                @Override//from   w w  w . j  a va 2s  .  co m
                public InetAddress[] resolve(final String host0) throws UnknownHostException {
                    final InetAddress ip = Domains.dnsResolve(host0);
                    if (ip == null)
                        throw new UnknownHostException(host0);
                    return new InetAddress[] { ip };
                }
            }, DEFAULT_POOLED_CONNECTION_TIME_TO_LIVE, TimeUnit.SECONDS);
    initPoolMaxConnections(pooling, maxcon);

    pooling.setValidateAfterInactivity(default_timeout); // on init set to default 5000ms
    final SocketConfig socketConfig = SocketConfig.custom()
            // Defines whether the socket can be bound even though a previous connection is still in a timeout state.
            .setSoReuseAddress(true)
            // SO_TIMEOUT: maximum period inactivity between two consecutive data packets in milliseconds
            .setSoTimeout(3000)
            // conserve bandwidth by minimizing the number of segments that are sent
            .setTcpNoDelay(false).build();
    pooling.setDefaultSocketConfig(socketConfig);

    return pooling;
}