本文整理匯總了Java中org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setValidateAfterInactivity方法的典型用法代碼示例。如果您正苦於以下問題:Java PoolingHttpClientConnectionManager.setValidateAfterInactivity方法的具體用法?Java PoolingHttpClientConnectionManager.setValidateAfterInactivity怎麽用?Java PoolingHttpClientConnectionManager.setValidateAfterInactivity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.conn.PoolingHttpClientConnectionManager
的用法示例。
在下文中一共展示了PoolingHttpClientConnectionManager.setValidateAfterInactivity方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: DefaultConnector
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
*
*/
public DefaultConnector() {
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.closeIdleConnections(120, TimeUnit.SECONDS);
// would be nice to set this from outside -> keep alive
final SocketConfig sConfig = SocketConfig.custom().setSoKeepAlive(true).setSoTimeout(Context.SOCKET_TO).build();
cm.setDefaultSocketConfig(sConfig);
cm.setMaxTotal(150);
cm.setDefaultMaxPerRoute(150);
cm.setValidateAfterInactivity(0);
final HttpRequestRetryHandler rh = new DefaultHttpRequestRetryHandler(3, true);
httpClient = HttpClients.custom().setRetryHandler(rh).setConnectionManager(cm).build();
}
示例2: create
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Override
public HttpClientConnectionManager create(final HttpClientSettings settings) {
ConnectionSocketFactory sslsf = getPreferredSocketFactory(settings);
final PoolingHttpClientConnectionManager cm = new
PoolingHttpClientConnectionManager(
createSocketFactoryRegistry(sslsf),
null,
DefaultSchemePortResolver.INSTANCE,
new DelegatingDnsResolver(settings.getDnsResolver()),
settings.getConnectionPoolTTL(),
TimeUnit.MILLISECONDS);
cm.setValidateAfterInactivity(settings.getValidateAfterInactivityMillis());
cm.setDefaultMaxPerRoute(settings.getMaxConnections());
cm.setMaxTotal(settings.getMaxConnections());
cm.setDefaultSocketConfig(buildSocketConfig(settings));
cm.setDefaultConnectionConfig(buildConnectionConfig(settings));
return cm;
}
示例3: createConnectionManager
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
public PoolingHttpClientConnectionManager createConnectionManager(final Registry<ConnectionSocketFactory> registry) {
if(log.isDebugEnabled()) {
log.debug(String.format("Setup connection pool with registry %s", registry));
}
final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry);
manager.setMaxTotal(preferences.getInteger("http.connections.total"));
manager.setDefaultMaxPerRoute(preferences.getInteger("http.connections.route"));
manager.setValidateAfterInactivity(5000);
return manager;
}
示例4: getConnectionManager
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
public static PoolingHttpClientConnectionManager getConnectionManager(int maxConnections) {
//configure connection manager
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setDefaultMaxPerRoute(maxConnections);
connectionManager.setMaxTotal(maxConnections);
connectionManager.setValidateAfterInactivity(30000);
return connectionManager;
}
示例5: init
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Create
public void init() {
if (this.umaMetadataConfiguration != null) {
if (applicationConfiguration.isRptConnectionPoolUseConnectionPooling()) {
// For more information about PoolingHttpClientConnectionManager, please see:
// http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.html?org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html
log.info("##### Initializing custom ClientExecutor...");
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(applicationConfiguration.getRptConnectionPoolMaxTotal());
connectionManager.setDefaultMaxPerRoute(applicationConfiguration.getRptConnectionPoolDefaultMaxPerRoute());
connectionManager.setValidateAfterInactivity(applicationConfiguration.getRptConnectionPoolValidateAfterInactivity() * 1000);
CloseableHttpClient client = HttpClients.custom()
.setKeepAliveStrategy(connectionKeepAliveStrategy)
.setConnectionManager(connectionManager)
.build();
ClientExecutor clientExecutor = new ApacheHttpClient4Executor(client);
log.info("##### Initializing custom ClientExecutor DONE");
this.resourceSetPermissionRegistrationService = UmaClientFactory.instance().createResourceSetPermissionRegistrationService(this.umaMetadataConfiguration, clientExecutor);
this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadataConfiguration, clientExecutor);
} else {
this.resourceSetPermissionRegistrationService = UmaClientFactory.instance().createResourceSetPermissionRegistrationService(this.umaMetadataConfiguration);
this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadataConfiguration);
}
}
}
示例6: buildHttpClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
* Build a HTTP client based on the current properties.
*
* @return the built HTTP client
*/
private CloseableHttpClient buildHttpClient() {
try {
final ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
final LayeredConnectionSocketFactory sslsf = this.sslSocketFactory;
final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", plainsf)
.register("https", sslsf)
.build();
final PoolingHttpClientConnectionManager connMgmr = new PoolingHttpClientConnectionManager(registry);
connMgmr.setMaxTotal(this.maxPooledConnections);
connMgmr.setDefaultMaxPerRoute(this.maxConnectionsPerRoute);
connMgmr.setValidateAfterInactivity(DEFAULT_TIMEOUT);
final HttpHost httpHost = new HttpHost(InetAddress.getLocalHost());
final HttpRoute httpRoute = new HttpRoute(httpHost);
connMgmr.setMaxPerRoute(httpRoute, MAX_CONNECTIONS_PER_ROUTE);
final RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(this.readTimeout)
.setConnectTimeout(this.connectionTimeout)
.setConnectionRequestTimeout(this.connectionTimeout)
.setCircularRedirectsAllowed(this.circularRedirectsAllowed)
.setRedirectsEnabled(this.redirectsEnabled)
.setAuthenticationEnabled(this.authenticationEnabled)
.build();
final HttpClientBuilder builder = HttpClients.custom()
.setConnectionManager(connMgmr)
.setDefaultRequestConfig(requestConfig)
.setSSLSocketFactory(sslsf)
.setSSLHostnameVerifier(this.hostnameVerifier)
.setRedirectStrategy(this.redirectionStrategy)
.setDefaultCredentialsProvider(this.credentialsProvider)
.setDefaultCookieStore(this.cookieStore)
.setConnectionReuseStrategy(this.connectionReuseStrategy)
.setConnectionBackoffStrategy(this.connectionBackoffStrategy)
.setServiceUnavailableRetryStrategy(this.serviceUnavailableRetryStrategy)
.setProxyAuthenticationStrategy(this.proxyAuthenticationStrategy)
.setDefaultHeaders(this.defaultHeaders)
.useSystemProperties();
return builder.build();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
示例7: buildHttpClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
* Build a HTTP client based on the current properties.
*
* @return the built HTTP client
*/
private CloseableHttpClient buildHttpClient() {
try {
final ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
final LayeredConnectionSocketFactory sslsf = this.sslSocketFactory;
final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", plainsf)
.register("https", sslsf)
.build();
final PoolingHttpClientConnectionManager connMgmr = new PoolingHttpClientConnectionManager(registry);
connMgmr.setMaxTotal(this.maxPooledConnections);
connMgmr.setDefaultMaxPerRoute(this.maxConnectionsPerRoute);
connMgmr.setValidateAfterInactivity(DEFAULT_TIMEOUT);
final HttpHost httpHost = new HttpHost(InetAddress.getLocalHost());
final HttpRoute httpRoute = new HttpRoute(httpHost);
connMgmr.setMaxPerRoute(httpRoute, MAX_CONNECTIONS_PER_ROUTE);
final RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(this.readTimeout)
.setConnectTimeout(Long.valueOf(this.connectionTimeout).intValue())
.setConnectionRequestTimeout(Long.valueOf(this.connectionTimeout).intValue())
.setCircularRedirectsAllowed(this.circularRedirectsAllowed)
.setRedirectsEnabled(this.redirectsEnabled)
.setAuthenticationEnabled(this.authenticationEnabled)
.build();
final HttpClientBuilder builder = HttpClients.custom()
.setConnectionManager(connMgmr)
.setDefaultRequestConfig(requestConfig)
.setSSLSocketFactory(sslsf)
.setSSLHostnameVerifier(this.hostnameVerifier)
.setRedirectStrategy(this.redirectionStrategy)
.setDefaultCredentialsProvider(this.credentialsProvider)
.setDefaultCookieStore(this.cookieStore)
.setConnectionReuseStrategy(this.connectionReuseStrategy)
.setConnectionBackoffStrategy(this.connectionBackoffStrategy)
.setServiceUnavailableRetryStrategy(this.serviceUnavailableRetryStrategy)
.setProxyAuthenticationStrategy(this.proxyAuthenticationStrategy)
.setDefaultHeaders(this.defaultHeaders)
.useSystemProperties();
return builder.build();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
throw Throwables.propagate(e);
}
}
示例8: buildClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Override
protected ExecREST buildClient(RESTPool pool) throws IOException {
SSLContext sslContext;
try {
sslContext = SSLContext.getDefault();
} catch (NoSuchAlgorithmException e) {
throw new IOException(e);
}
Registry<ConnectionSocketFactory> socketRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE)
.register("https", new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE))
.build();
//TODO buffers size
SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(new Long(pool.getSocketTimeout()).intValue())
.setTcpNoDelay(true)
.setSoKeepAlive(true)
.setSoReuseAddress(true)
.build();
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setCharset(StandardCharsets.UTF_8)
.setMalformedInputAction(CodingErrorAction.IGNORE)
.setUnmappableInputAction(CodingErrorAction.IGNORE)
.build();
HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory(
new DefaultHttpRequestWriterFactory(),
new DefaultHttpResponseParserFactory()
);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(new Long(pool.getMaxPoolWait()).intValue())
.setConnectTimeout(new Long(pool.getConnectionTimeout()).intValue())
.setExpectContinueEnabled(pool.expectContinue())
.build();
PoolingHttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(socketRegistry, connFactory);
ccm.setMaxTotal(pool.getMaxTotal());
ccm.setDefaultMaxPerRoute(pool.getMaxPerRoute());
ccm.setDefaultSocketConfig(socketConfig);
ccm.setDefaultConnectionConfig(connectionConfig);
ccm.setValidateAfterInactivity(pool.getValidationOnInactivity());
HttpClientBuilder builder = HttpClients.custom()
.setConnectionManager(ccm)
.setDefaultRequestConfig(requestConfig)
.disableAutomaticRetries()
.setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE)
.disableCookieManagement()
.disableContentCompression();
addProxy(pool, builder);
handleRedirects(pool, builder);
CloseableHttpClient servClient = builder.build();
IdleConnectionEvictor evictor = new IdleConnectionEvictor(ccm, pool.getEvictorSleep(), TimeUnit.MILLISECONDS, pool.getMaxIdleTime(), TimeUnit.MILLISECONDS);
HTTPCClientMonitor monitor = pool.hasConnectionMetrics() ? new HTTPCSyncClientMonitor(pool.getName(), ccm) : null;
return new HTTPCClient(servClient, evictor, monitor);
}
示例9: getClientBuilder
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@SneakyThrows
private HttpClientBuilder getClientBuilder() {
RegistryBuilder<ConnectionSocketFactory> csf = RegistryBuilder.<ConnectionSocketFactory> create();
KeyManager[] keyStoreManagers = null;
if (cmd.get("keystore") != null) {
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance("jks");
// System.out.printf("keystore=%s
// keystorePassword=%s%n",map.get("keystore"),
// map.get("keystorePassword"));
keyStore.load(new FileInputStream(cmd.get("keystore")), null);
kmf.init(keyStore, cmd.get("keystorePassword").toCharArray());
keyStoreManagers = kmf.getKeyManagers();
}
TrustManager[] trustStoreManagers = null;
if (cmd.get("truststore") != null) {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore trustStore = KeyStore.getInstance("jks");
// System.out.printf("truststore=%s
// truststorePassword=%s%n",map.get("truststore"),
// map.get("truststorePassword"));
trustStore.load(new FileInputStream(cmd.get("truststore")), null);
tmf.init(trustStore);
trustStoreManagers = tmf.getTrustManagers();
}
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyStoreManagers, trustStoreManagers, null);
SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
csf.register("https", scsf);
csf.register("http", PlainConnectionSocketFactory.getSocketFactory());
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(csf.build());
int maxPerRoute = 2 * Integer.valueOf(cmd.getOrDefault("pa", "" + Runtime.getRuntime().availableProcessors()));
connManager.setDefaultMaxPerRoute(maxPerRoute);
connManager.setValidateAfterInactivity(-1);
// connManager.
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connManager);
return builder;
}