本文整理汇总了Java中org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setDefaultMaxPerRoute方法的典型用法代码示例。如果您正苦于以下问题:Java PoolingHttpClientConnectionManager.setDefaultMaxPerRoute方法的具体用法?Java PoolingHttpClientConnectionManager.setDefaultMaxPerRoute怎么用?Java PoolingHttpClientConnectionManager.setDefaultMaxPerRoute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.conn.PoolingHttpClientConnectionManager
的用法示例。
在下文中一共展示了PoolingHttpClientConnectionManager.setDefaultMaxPerRoute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConnectionManager
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
protected HttpClientConnectionManager createConnectionManager(Registry<ConnectionSocketFactory> registry, int maxTotalConnections, int connectionsPerRoute) {
// setup the connection live time
PoolingHttpClientConnectionManager answer =
new PoolingHttpClientConnectionManager(registry, null, null, null, getConnectionTimeToLive(), TimeUnit.MILLISECONDS);
int localMaxTotalConnections = maxTotalConnections;
if (localMaxTotalConnections == 0) {
localMaxTotalConnections = getMaxTotalConnections();
}
if (localMaxTotalConnections > 0) {
answer.setMaxTotal(localMaxTotalConnections);
}
int localConnectionsPerRoute = connectionsPerRoute;
if (localConnectionsPerRoute == 0) {
localConnectionsPerRoute = getConnectionsPerRoute();
}
if (localConnectionsPerRoute > 0) {
answer.setDefaultMaxPerRoute(localConnectionsPerRoute);
}
LOG.info("Created ClientConnectionManager " + answer);
return answer;
}
示例2: create
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
public HttpClientConnectionManager create(ApacheSdkHttpClientFactory configuration,
AttributeMap standardOptions) {
ConnectionSocketFactory sslsf = getPreferredSocketFactory(standardOptions);
final PoolingHttpClientConnectionManager cm = new
PoolingHttpClientConnectionManager(
createSocketFactoryRegistry(sslsf),
null,
DefaultSchemePortResolver.INSTANCE,
null,
configuration.connectionTimeToLive().orElse(Defaults.CONNECTION_POOL_TTL).toMillis(),
TimeUnit.MILLISECONDS);
cm.setDefaultMaxPerRoute(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
cm.setMaxTotal(standardOptions.get(SdkHttpConfigurationOption.MAX_CONNECTIONS));
cm.setDefaultSocketConfig(buildSocketConfig(standardOptions));
return cm;
}
示例3: InternalPredictionService
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
@Autowired
public InternalPredictionService(AppProperties appProperties){
this.appProperties = appProperties;
connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(150);
connectionManager.setDefaultMaxPerRoute(150);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(DEFAULT_REQ_TIMEOUT)
.setConnectTimeout(DEFAULT_CON_TIMEOUT)
.setSocketTimeout(DEFAULT_SOCKET_TIMEOUT).build();
httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setRetryHandler(new HttpRetryHandler())
.build();
}
示例4: init
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
public void init() {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
/* 配置同时支持 HTTP 和 HTPPS */
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
/* 初始化连接管理器 */
poolConnManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
poolConnManager.setMaxTotal(maxTotal);
poolConnManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionRequestTimeout)
.setSocketTimeout(socketTimeout).setConnectTimeout(connectTimeout).build();
httpClient = getConnection();
log.info("HttpConnectionManager初始化完成...");
} catch (Exception e) {
log.error("error", e);
}
}
示例5: createDefaultHttpClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
protected CloseableHttpClient createDefaultHttpClient() {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(maxConnections);
cm.setDefaultMaxPerRoute(maxConnections);
Builder config = RequestConfig.custom()
.setConnectionRequestTimeout(connectionRequestTimeout)
.setConnectTimeout(connectTimeout)
.setSocketTimeout(socketTimeout);
// TODO: Set Credentials
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(cm).setDefaultRequestConfig(config.build())
.build();
return httpClient;
}
示例6: getPool
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
public HttpClient getPool() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
HttpClientBuilder builder = HttpClientBuilder.create();
connectionManager.setMaxTotal(maxConnections);
connectionManager.setDefaultMaxPerRoute(maxConnections);
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeOut)
.setConnectionRequestTimeout(timeOut).setSocketTimeout(timeOut)
.build();
connectionMonitor = new IdleConnectionMonitorThread(connectionManager);
connectionMonitor.start();
builder.setConnectionManager(connectionManager);
builder.setKeepAliveStrategy(myStrategy);
CloseableHttpClient defaultHttpClient = builder
.setDefaultRequestConfig(config).build();
logger.debug("prepared client");
return defaultHttpClient;
}
示例7: HttpTransportClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
public HttpTransportClient(int retryAttemptsNetworkErrorCount, int retryAttemptsInvalidStatusCount) {
this.retryAttemptsNetworkErrorCount = retryAttemptsNetworkErrorCount;
this.retryAttemptsInvalidStatusCount = retryAttemptsInvalidStatusCount;
CookieStore cookieStore = new BasicCookieStore();
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(SOCKET_TIMEOUT_MS)
.setConnectTimeout(CONNECTION_TIMEOUT_MS)
.setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
.setCookieSpec(CookieSpecs.STANDARD)
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(MAX_SIMULTANEOUS_CONNECTIONS);
connectionManager.setDefaultMaxPerRoute(MAX_SIMULTANEOUS_CONNECTIONS);
httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setDefaultCookieStore(cookieStore)
.setUserAgent(USER_AGENT)
.build();
}
示例8: createHttpClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private CloseableHttpClient createHttpClient(String hostname, int port) {
ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
LayeredConnectionSocketFactory sslsf = SSLConnectionSocketFactory.getSocketFactory();
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory> create()
.register("http", plainsf).register("https", sslsf).build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
// 将最大连接数增加
cm.setMaxTotal(maxTotal);
// 将每个路由基础的连接增加
cm.setDefaultMaxPerRoute(maxPerRoute);
HttpHost httpHost = new HttpHost(hostname, port);
// 将目标主机的最大连接数增加
cm.setMaxPerRoute(new HttpRoute(httpHost), maxRoute);
// 请求重试处理
return HttpClients.custom().setConnectionManager(cm).setRetryHandler(httpRequestRetryHandler).build();
}
示例9: Dispatcher
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
Dispatcher(final String clientID, final String authToken) {
undocumented = new UndocumentedDispatcher();
final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(CONNECTION_COUNT);
connectionManager.setDefaultMaxPerRoute(CONNECTION_COUNT);
final List<Header> headers = new ArrayList<>();
headers.add(new BasicHeader(HttpHeaders.ACCEPT, "application/vnd.twitchtv.v3+json"));
headers.add(new BasicHeader("Client-ID", clientID));
if (authToken != null) {
headers.add(new BasicHeader("Authorization", "OAuth " + authToken));
}
HTTP_CLIENT = HttpClients.custom().setDefaultHeaders(headers).setConnectionManager(connectionManager).build();
}
示例10: FluxRuntimeConnectorHttpImpl
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
public FluxRuntimeConnectorHttpImpl(Long connectionTimeout, Long socketTimeout, String fluxEndpoint, ObjectMapper objectMapper) {
this.fluxEndpoint = fluxEndpoint;
this.objectMapper = objectMapper;
RequestConfig clientConfig = RequestConfig.custom()
.setConnectTimeout((connectionTimeout).intValue())
.setSocketTimeout((socketTimeout).intValue())
.setConnectionRequestTimeout((socketTimeout).intValue())
.build();
PoolingHttpClientConnectionManager syncConnectionManager = new PoolingHttpClientConnectionManager();
syncConnectionManager.setMaxTotal(MAX_TOTAL);
syncConnectionManager.setDefaultMaxPerRoute(MAX_PER_ROUTE);
closeableHttpClient = HttpClientBuilder.create().setDefaultRequestConfig(clientConfig).setConnectionManager(syncConnectionManager)
.build();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
HttpClientUtils.closeQuietly(closeableHttpClient);
}));
}
示例11: createClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private CloseableHttpClient createClient(String user, String password) {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(TOTAL_CONN);
cm.setDefaultMaxPerRoute(ROUTE_CONN);
logger.info("Pooling connection manager created.");
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
logger.info("Default credentials provider created.");
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost(rootUri.getHost(), rootUri.getPort(), rootUri.getScheme()), basicAuth);
logger.info("Auth cache created.");
httpContext = HttpClientContext.create();
httpContext.setCredentialsProvider(credentialsProvider);
httpContext.setAuthCache(authCache);
logger.info("HttpContext filled with Auth cache.");
return HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(cm)
.build();
}
示例12: Singleton
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
private Singleton() {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
// Increase max total connection to 200
cm.setMaxTotal(200);
// Increase default max connection per route to 20
cm.setDefaultMaxPerRoute(20);
// Build the client.
threadSafeClient = HttpClients.custom()
.setConnectionManager(cm)
.build();
// Start up an eviction thread.
monitor = new IdleConnectionMonitorThread(cm);
// Don't stop quitting.
monitor.setDaemon(true);
monitor.start();
}
示例13: getAzureClientBuilder
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
public HttpClientBuilder getAzureClientBuilder() throws CloudException {
try {
//boolean disableSSLValidation = isSSLValidationDisabled();
boolean disableSSLValidation = true;
HttpClientBuilder builder = HttpClientBuilder.create();
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", new AzureSSLSocketFactory(new AzureX509(this), disableSSLValidation))
.build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry);
connManager.setMaxTotal(200);
connManager.setDefaultMaxPerRoute(20);
builder.setConnectionManager(connManager);
return builder;
} catch (Exception e) {
throw new CloudException(e.getMessage());
}
}
示例14: createConnectionManager
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
protected HttpClientConnectionManager createConnectionManager() {
if (httpClientConfig.isMultiThreaded()) {
log.debug("Multi-threaded http connection manager created");
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
final Integer maxTotal = httpClientConfig.getMaxTotalConnection();
if (maxTotal != null) {
cm.setMaxTotal(maxTotal);
}
final Integer defaultMaxPerRoute = httpClientConfig.getDefaultMaxTotalConnectionPerRoute();
if (defaultMaxPerRoute != null) {
cm.setDefaultMaxPerRoute(defaultMaxPerRoute);
}
final Map<HttpRoute, Integer> maxPerRoute = httpClientConfig.getMaxTotalConnectionPerRoute();
for (final HttpRoute route : maxPerRoute.keySet()) {
cm.setMaxPerRoute(route, maxPerRoute.get(route));
}
return cm;
}
log.debug("Default http connection is created without multi threaded option");
return new BasicHttpClientConnectionManager();
}
示例15: DWServerConnection
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //导入方法依赖的package包/类
public DWServerConnection(DWSettingsProvider settingsProvider) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
this.settingsProvider = settingsProvider;
// SSLContextFactory to allow all hosts. Without this an SSLException is thrown with self signed certs
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (arg0, arg1) -> true).build();
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", socketFactory).build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connectionManager.setMaxTotal(200);
connectionManager.setDefaultMaxPerRoute(20);
client = HttpClients.custom()
.setConnectionManager(connectionManager)
.build();
context = new HttpClientContext();
context.setCredentialsProvider(getCredientials());
}