本文整理匯總了Java中org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setMaxTotal方法的典型用法代碼示例。如果您正苦於以下問題:Java PoolingHttpClientConnectionManager.setMaxTotal方法的具體用法?Java PoolingHttpClientConnectionManager.setMaxTotal怎麽用?Java PoolingHttpClientConnectionManager.setMaxTotal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.conn.PoolingHttpClientConnectionManager
的用法示例。
在下文中一共展示了PoolingHttpClientConnectionManager.setMaxTotal方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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;
}
示例3: 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;
}
示例4: 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();
}
示例5: httpClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
* Http client.
*
* @param connectorContext connector context
* @return HttpClient
*/
@Bean
public HttpClient httpClient(final ConnectorContext connectorContext) {
final int timeout = (int) TimeUtil.toTime(
connectorContext.getConfiguration().getOrDefault(DruidConfigConstants.HTTP_TIMEOUT, "5s"),
TimeUnit.SECONDS,
TimeUnit.MILLISECONDS
);
final int poolsize = Integer.parseInt(connectorContext.getConfiguration()
.getOrDefault(DruidConfigConstants.POOL_SIZE, "10"));
final RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout)
.setConnectionRequestTimeout(timeout)
.setSocketTimeout(timeout)
.setMaxRedirects(3)
.build();
final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(poolsize);
return HttpClientBuilder
.create()
.setDefaultRequestConfig(config)
.setConnectionManager(connectionManager)
.build();
}
示例6: 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();
}
示例7: SAClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
public SAClient(LoadBalancingPolicy<URI, HttpHost> loadBalancingPolicy) {
this.loadBalancingPolicy = loadBalancingPolicy;
final PoolingHttpClientConnectionManager fClientCm = new PoolingHttpClientConnectionManager();
fClientCm.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
fClientCm.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE);
this.fClient = createDefaultClient(fClientCm);
this.fConnectionSweeper = Executors.newSingleThreadScheduledExecutor();
this.fConnectionSweeper.scheduleAtFixedRate(
new SAConnectionMonitorThread(fClientCm, DEFAULT_CONN_TIMEOUT_IN_SECS, TimeUnit.SECONDS),
DEFAULT_SWEEP_PERIOD_IN_SECS,
DEFAULT_SWEEP_PERIOD_IN_SECS,
TimeUnit.SECONDS
);
}
示例8: 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();
}
示例9: 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());
}
}
示例10: AntiochClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
public AntiochClient(final URI antiochURI, SSLContext sslContext) {
this.antiochURI = antiochURI;
final ObjectMapper objectMapper = new ObjectMapper()//
.registerModule(new Jdk8Module())//
.registerModule(new JavaTimeModule());
final JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider();
jacksonProvider.setMapper(objectMapper);
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(50);
cm.setDefaultMaxPerRoute(50);
ApacheConnectorProvider connectorProvider = new ApacheConnectorProvider();
ClientConfig clientConfig = new ClientConfig(jacksonProvider)//
.connectorProvider(connectorProvider)//
.property(ApacheClientProperties.CONNECTION_MANAGER, cm)//
.property(ClientProperties.CONNECT_TIMEOUT, 60000)//
.property(ClientProperties.READ_TIMEOUT, 60000);
if (sslContext == null) {
if ("https".equals(antiochURI.getScheme())) {
throw new RuntimeException("SSL connections need an SSLContext, use: new AntiochClient(uri, sslContext) instead.");
}
client = ClientBuilder.newClient(clientConfig);
} else {
client = ClientBuilder.newBuilder()//
.sslContext(sslContext)//
.withConfig(clientConfig)//
.build();
}
rootTarget = client.target(antiochURI);
}
示例11: 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();
}
示例12: ExternalItemRecommendationAlgorithm
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Autowired
public ExternalItemRecommendationAlgorithm(ItemService itemService){
cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(100);
cm.setDefaultMaxPerRoute(20);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(DEFAULT_REQ_TIMEOUT)
.setConnectTimeout(DEFAULT_CON_TIMEOUT)
.setSocketTimeout(DEFAULT_SOCKET_TIMEOUT).build();
httpClient = HttpClients.custom()
.setConnectionManager(cm)
.setDefaultRequestConfig(requestConfig)
.build();
this.itemService = itemService;
}
示例13: ExternalPredictionServer
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
@Autowired
public ExternalPredictionServer(GlobalConfigHandler globalConfigHandler,ClientRpcStore rpcStore){
cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(150);
cm.setDefaultMaxPerRoute(150);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(DEFAULT_REQ_TIMEOUT)
.setConnectTimeout(DEFAULT_CON_TIMEOUT)
.setSocketTimeout(DEFAULT_SOCKET_TIMEOUT).build();
httpClient = HttpClients.custom()
.setConnectionManager(cm)
.setDefaultRequestConfig(requestConfig)
.build();
globalConfigHandler.addSubscriber(ZK_CONFIG_TEMP, this);
this.rpcStore = rpcStore;
}
示例14: makeConnectionManager
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
* Makes a pooled httpclient connection manager, which uses a freely trusting ssl socket factory registry.
*/
private HttpClientConnectionManager makeConnectionManager()
{
Registry<ConnectionSocketFactory> socketFactoryRegistry = makeConnectionSocketFactoryRegistry();
PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
poolingHttpClientConnectionManager.setDefaultMaxPerRoute(50);
poolingHttpClientConnectionManager.setMaxTotal(200);
return poolingHttpClientConnectionManager;
}
示例15: initHttpClient
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; //導入方法依賴的package包/類
/**
* 描述:創建httpClient連接池,並初始化httpclient
*/
private void initHttpClient() throws ConfigurationException {
Configuration configuration = new PropertiesConfiguration(CONFIG_FILE);
//創建httpclient連接池
PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager();
httpClientConnectionManager.setMaxTotal(configuration.getInt("http.max.total")); //設置連接池線程最大數量
httpClientConnectionManager.setDefaultMaxPerRoute(configuration.getInt("http.max.route")); //設置單個路由最大的連接線程數量
//創建http request的配置信息
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(configuration.getInt("http.request.timeout"))
.setSocketTimeout(configuration.getInt("http.socket.timeout"))
.setCookieSpec(CookieSpecs.DEFAULT).build();
//設置重定向策略
LaxRedirectStrategy redirectStrategy = new LaxRedirectStrategy() {
/**
* false 禁止重定向 true 允許
*/
@Override
public boolean isRedirected(HttpRequest request,
HttpResponse response, HttpContext context)
throws ProtocolException {
// TODO Auto-generated method stub
return isRediect ? super.isRedirected(request, response, context) : isRediect;
}
};
//初始化httpclient客戶端
httpClient = HttpClients.custom().setConnectionManager(httpClientConnectionManager)
.setDefaultRequestConfig(requestConfig)
//.setUserAgent(NewsConstant.USER_AGENT)
.setRedirectStrategy(redirectStrategy)
.build();
}