Java 类org.apache.http.impl.client.DefaultBackoffStrategy 实例源码

项目:snowizard    文件:SnowizardClient.java   
/**
 * Get a new CloseableHttpClient
 * 
 * @return CloseableHttpClient
 */
public static CloseableHttpClient newHttpClient() {
    final SocketConfig socketConfig = SocketConfig.custom()
            .setSoKeepAlive(Boolean.TRUE).setTcpNoDelay(Boolean.TRUE)
            .setSoTimeout(SOCKET_TIMEOUT_MS).build();

    final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();
    manager.setDefaultMaxPerRoute(MAX_HOSTS);
    manager.setMaxTotal(MAX_HOSTS);
    manager.setDefaultSocketConfig(socketConfig);

    final RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(CONNECTION_TIMEOUT_MS)
            .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .setStaleConnectionCheckEnabled(Boolean.FALSE)
            .setSocketTimeout(SOCKET_TIMEOUT_MS).build();

    final CloseableHttpClient client = HttpClients
            .custom()
            .disableRedirectHandling()
            .setConnectionManager(manager)
            .setDefaultRequestConfig(requestConfig)
            .setConnectionReuseStrategy(
                    new DefaultConnectionReuseStrategy())
            .setConnectionBackoffStrategy(new DefaultBackoffStrategy())
            .setRetryHandler(
                    new DefaultHttpRequestRetryHandler(MAX_RETRIES, false))
            .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy())
            .build();
    return client;
}