當前位置: 首頁>>代碼示例>>Java>>正文


Java PoolingHttpClientConnectionManager.setMaxTotal方法代碼示例

本文整理匯總了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();
}
 
開發者ID:adealjason,項目名稱:dtsopensource,代碼行數:17,代碼來源:HttpProtocolParent.java

示例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;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:23,代碼來源:HttpComponent.java

示例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;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:22,代碼來源:ApacheConnectionManagerFactory.java

示例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();
}
 
開發者ID:VKCOM,項目名稱:vk-java-sdk,代碼行數:25,代碼來源:HttpTransportClient.java

示例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();
}
 
開發者ID:Netflix,項目名稱:metacat,代碼行數:30,代碼來源:DruidHttpClientConfig.java

示例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();
}
 
開發者ID:JanStrauss,項目名稱:cathode,代碼行數:17,代碼來源:Dispatcher.java

示例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
	);
}
 
開發者ID:att,項目名稱:dmaap-framework,代碼行數:18,代碼來源:SAClient.java

示例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();
}
 
開發者ID:bwssytems,項目名稱:ha-bridge,代碼行數:17,代碼來源:HttpClientPool.java

示例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());
    }
}
 
開發者ID:dasein-cloud,項目名稱:dasein-cloud-azurepack,代碼行數:20,代碼來源:AzurePackCloud.java

示例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);
}
 
開發者ID:HuygensING,項目名稱:antioch,代碼行數:35,代碼來源:AntiochClient.java

示例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();
}
 
開發者ID:petalmd,項目名稱:armor,代碼行數:22,代碼來源:HeaderAwareJestClientFactory.java

示例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;
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:19,代碼來源:ExternalItemRecommendationAlgorithm.java

示例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;
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:19,代碼來源:ExternalPredictionServer.java

示例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;
}
 
開發者ID:Nike-Inc,項目名稱:bluegreen-manager,代碼行數:12,代碼來源:HttpClientSSLFactory.java

示例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();
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:35,代碼來源:HttpHelper.java


注:本文中的org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setMaxTotal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。