private HttpClientConnectionManager createConnectionManager(HttpConfig config) { Registry<ConnectionSocketFactory> registry = createSocketFactoryRegistry(config); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry); connectionManager.setMaxTotal(config.getMaxConnections()); connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionsPerHost()); return connectionManager; }
public NingAsyncHttpClient(HttpConfig config) { Preconditions.checkNotNull(config); NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); int workerThreads = Math.min(Runtime.getRuntime().availableProcessors(), 4); this.workerExecutorService = newWorkerThreadPool(workerThreads); this.channelFactory = newSocketChannelFactory(this.workerExecutorService, workerThreads); nettyConfig.setSocketChannelFactory(this.channelFactory); nettyConfig.setNettyTimer(TIMER); AsyncHttpClientConfig ningConfig = new AsyncHttpClientConfig.Builder() .addRequestFilter(new ThrottleRequestFilter(config.getMaxConnections())) .addRequestFilter(new AcceptEncodingRequestFilter()) .setMaxConnectionsPerHost(config.getMaxConnectionsPerHost()) .setConnectTimeout(config.getConnectTimeoutMillis()) .setRequestTimeout(config.getRequestTimeoutMillis()) .setReadTimeout(config.getRequestTimeoutMillis()) .setMaxRedirects(config.getMaxRedirects()) .setFollowRedirect(config.isFollowRedirects()) .setHostnameVerifier(new NingHostnameVerifier(config.getSSLConfig())) .setSSLContext(NingSSLContext.forConfig(config.getSSLConfig())) .setAsyncHttpClientProviderConfig(nettyConfig) .setUserAgent(config.getUserAgent()) .setIOThreadMultiplier(1) .build(); this.ningClient = new com.ning.http.client.AsyncHttpClient(ningConfig); this.requestConverter = new NingHttpRequestConverter(config.getObjectMapper()); this.defaultOptions = config.getOptions(); this.mapper = config.getObjectMapper(); }