本文整理汇总了Java中org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.setDefaultConnectionConfig方法的典型用法代码示例。如果您正苦于以下问题:Java PoolingNHttpClientConnectionManager.setDefaultConnectionConfig方法的具体用法?Java PoolingNHttpClientConnectionManager.setDefaultConnectionConfig怎么用?Java PoolingNHttpClientConnectionManager.setDefaultConnectionConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager
的用法示例。
在下文中一共展示了PoolingNHttpClientConnectionManager.setDefaultConnectionConfig方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHttpAsyncClient
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
private CloseableHttpAsyncClient createHttpAsyncClient(YunpianConf conf) throws IOReactorException {
IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setIoThreadCount(Runtime.getRuntime().availableProcessors())
.setConnectTimeout(conf.getConfInt(YunpianConf.HTTP_CONN_TIMEOUT, "10000"))
.setSoTimeout(conf.getConfInt(YunpianConf.HTTP_SO_TIMEOUT, "30000")).build();
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(ioReactor);
ConnectionConfig connectionConfig = ConnectionConfig.custom().setMalformedInputAction(CodingErrorAction.IGNORE)
.setUnmappableInputAction(CodingErrorAction.IGNORE)
.setCharset(Charset.forName(conf.getConf(YunpianConf.HTTP_CHARSET, YunpianConf.HTTP_CHARSET_DEFAULT))).build();
connManager.setDefaultConnectionConfig(connectionConfig);
connManager.setMaxTotal(conf.getConfInt(YunpianConf.HTTP_CONN_MAXTOTAL, "100"));
connManager.setDefaultMaxPerRoute(conf.getConfInt(YunpianConf.HTTP_CONN_MAXPERROUTE, "10"));
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setConnectionManager(connManager).build();
httpclient.start();
return httpclient;
}
示例2: buildAsyncClient
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
protected ExecCallbackAsyncREST<HttpResponse> buildAsyncClient(RESTPool pool) throws IOException {
SSLContext sslContext;
try {
sslContext = SSLContext.getDefault();
} catch (NoSuchAlgorithmException e) {
throw new IOException(e);
}
Registry<SchemeIOSessionStrategy> socketRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create()
.register("http", NoopIOSessionStrategy.INSTANCE)
.register("https", new SSLIOSessionStrategy(sslContext, NoopHostnameVerifier.INSTANCE))
.build();
IOReactorConfig socketConfig = IOReactorConfig.custom()
.setIoThreadCount(pool.getReactorThreadCount())
.setSoTimeout(new Long(pool.getSocketTimeout()).intValue())
.setTcpNoDelay(true)
.setSoKeepAlive(true)
.setSelectInterval(REACTOR_SELECT_INTERVAL)
.build();
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setCharset(StandardCharsets.UTF_8)
.setMalformedInputAction(CodingErrorAction.IGNORE)
.setUnmappableInputAction(CodingErrorAction.IGNORE)
.build();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(new Long(pool.getMaxPoolWait()).intValue())
.setConnectTimeout(new Long(pool.getConnectionTimeout()).intValue())
.setExpectContinueEnabled(pool.expectContinue())
.setRedirectsEnabled(false)
.setStaleConnectionCheckEnabled(pool.getValidationOnInactivity() >= 0)
.build();
NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory = new ManagedNHttpClientConnectionFactory(
new org.apache.http.impl.nio.codecs.DefaultHttpRequestWriterFactory(),
new org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory(),
HeapByteBufferAllocator.INSTANCE
);
//TODO set validateAfterInactivity when supported
PoolingNHttpClientConnectionManager ccm = new PoolingNHttpClientConnectionManager(
new DefaultConnectingIOReactor(socketConfig),
connFactory,
socketRegistry,
new SystemDefaultDnsResolver()
);
ccm.setMaxTotal(pool.getMaxTotal());
ccm.setDefaultMaxPerRoute(pool.getMaxPerRoute());
ccm.setDefaultConnectionConfig(connectionConfig);
HttpAsyncClientBuilder builder = HttpAsyncClients.custom()
.setConnectionManager(ccm)
.setDefaultRequestConfig(requestConfig)
.setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE)
.disableCookieManagement();
IdleAsyncConnectionEvictor evictor = new IdleAsyncConnectionEvictor(ccm, pool.getEvictorSleep(), TimeUnit.MILLISECONDS, pool.getMaxIdleTime(), TimeUnit.MILLISECONDS);
addProxy(pool, builder);
handleRedirects(pool, builder);
CloseableHttpAsyncClient servClient = builder.build();
servClient.start();
HTTPCClientMonitor monitor = pool.hasConnectionMetrics() ? new HTTPCAsyncClientMonitor(pool.getName(), ccm) : null;
return new HTTPCAsyncClient(servClient, evictor, monitor);
}