当前位置: 首页>>代码示例>>Java>>正文


Java PoolingNHttpClientConnectionManager.setMaxTotal方法代码示例

本文整理汇总了Java中org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.setMaxTotal方法的典型用法代码示例。如果您正苦于以下问题:Java PoolingNHttpClientConnectionManager.setMaxTotal方法的具体用法?Java PoolingNHttpClientConnectionManager.setMaxTotal怎么用?Java PoolingNHttpClientConnectionManager.setMaxTotal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager的用法示例。


在下文中一共展示了PoolingNHttpClientConnectionManager.setMaxTotal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:yunpian,项目名称:yunpian-java-sdk,代码行数:19,代码来源:YunpianClient.java

示例2: FiberApacheHttpClientRequestExecutor

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
public FiberApacheHttpClientRequestExecutor(final Validator<CloseableHttpResponse> resValidator, final int maxConnections, final int timeout, final int parallelism) throws IOReactorException {
  final DefaultConnectingIOReactor ioreactor = new DefaultConnectingIOReactor(IOReactorConfig.custom().
    setConnectTimeout(timeout).
    setIoThreadCount(parallelism).
    setSoTimeout(timeout).
    build());

  final PoolingNHttpClientConnectionManager mngr = new PoolingNHttpClientConnectionManager(ioreactor);
  mngr.setDefaultMaxPerRoute(maxConnections);
  mngr.setMaxTotal(maxConnections);

  final CloseableHttpAsyncClient ahc = HttpAsyncClientBuilder.create().
    setConnectionManager(mngr).
    setDefaultRequestConfig(RequestConfig.custom().setLocalAddress(null).build()).build();

  client = new FiberHttpClient(ahc);
  validator = resValidator;
}
 
开发者ID:pinterest,项目名称:jbender,代码行数:19,代码来源:FiberApacheHttpClientRequestExecutor.java

示例3: initDashboard

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
private DashboardSetupStatus initDashboard(final String hostAddress, final int port) {
  final String dashboardURL = String.format("http://%s:%d/", hostAddress, port);
  try {
    // Create a pool of http client connection, which allow up to Integer.MAX_VALUE connections.
    final PoolingNHttpClientConnectionManager connectionManager
        = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor());
    connectionManager.setMaxTotal(Integer.MAX_VALUE);
    final CloseableHttpAsyncClient reusableHttpClient =
        HttpAsyncClients.custom().setConnectionManager(connectionManager).build();
    reusableHttpClient.start();

    // run another thread to send metrics.
    runMetricsSenderThread();

    return DashboardSetupStatus.getSuccessful(dashboardURL, reusableHttpClient);
  } catch (IOReactorException e) {
    LOG.log(Level.WARNING, "Dashboard: Fail on initializing connection to the dashboard server.", e);
    return DashboardSetupStatus.getFailed();
  }
}
 
开发者ID:snuspl,项目名称:cruise,代码行数:21,代码来源:DashboardConnector.java

示例4: defaultClientBuilder

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
/**
 * Used internally to initialize the internal HTTP client used by all
 * instances of a client.
 * <p>
 * This method can be overriden to provide a client with different options.
 * The client built gets an extra interceptor to add the credentials headers.
 *
 * @return HTTP default async client builder
 */
protected static HttpAsyncClientBuilder defaultClientBuilder() {
  
  try {
    DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
    connMgr = new PoolingNHttpClientConnectionManager(ioReactor);
    connMgr.setMaxTotal(maxConnections);
    connMgr.setDefaultMaxPerRoute(maxConnections);
  } catch (IOReactorException e) {
  }
  
  return HttpAsyncClients
      .custom()
      .addInterceptorLast(new GzipInterceptors.GzipRequestInterceptor())
      .setConnectionManager(connMgr)
      .setDefaultRequestConfig(
          RequestConfig.custom()
          .setSocketTimeout(3600 * 1000) // 1 hour
              .build())
      .setKeepAliveStrategy(keepAliveStrategy);
}
 
开发者ID:Idilia,项目名称:idilia-java-sdk,代码行数:30,代码来源:AsyncClientBase.java

示例5: asyncHttpClient

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
@Bean
public CloseableHttpAsyncClient asyncHttpClient() {
    try {
        PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager(
                new DefaultConnectingIOReactor(IOReactorConfig.DEFAULT));
        connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
        connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);
        RequestConfig config = RequestConfig.custom()
                .setConnectTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS)
                .build();

        return HttpAsyncClientBuilder.create()
                .setConnectionManager(connectionManager)
                .setDefaultRequestConfig(config)
                .build();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:grassrootza,项目名称:grassroot-platform,代码行数:20,代码来源:GrassrootIntegrationConfig.java

示例6: SleepServerApiClient

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
public SleepServerApiClient() throws Exception {
	connectionManager = new PoolingNHttpClientConnectionManager(
			new DefaultConnectingIOReactor(IOReactorConfig.DEFAULT));
	connectionManager.setMaxTotal(20000);
	connectionManager.setDefaultMaxPerRoute(20000);

	RequestConfig config = RequestConfig.custom().setConnectTimeout(120000)
			.build();

	CloseableHttpAsyncClient httpClient = HttpAsyncClientBuilder.create()
			.setConnectionManager(connectionManager)
			.setDefaultRequestConfig(config).build();

	HttpComponentsAsyncClientHttpRequestFactory requestFactory = new HttpComponentsAsyncClientHttpRequestFactory(
			httpClient);
	client = new AsyncRestTemplate(requestFactory);
}
 
开发者ID:henriklundahl,项目名称:async-servlet-examples,代码行数:18,代码来源:SleepServerApiClient.java

示例7: getNHttpConnManager

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
private NHttpClientConnectionManager getNHttpConnManager(Config config) throws IOException {
  NHttpClientConnectionManager httpConnManager;

  String connMgrStr = config.getString(HTTP_CONN_MANAGER);
  switch (ApacheHttpClient.ConnManager.valueOf(connMgrStr.toUpperCase())) {
    case POOLING:
      ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
      PoolingNHttpClientConnectionManager poolingConnMgr = new PoolingNHttpClientConnectionManager(ioReactor);
      poolingConnMgr.setMaxTotal(config.getInt(POOLING_CONN_MANAGER_MAX_TOTAL_CONN));
      poolingConnMgr.setDefaultMaxPerRoute(config.getInt(POOLING_CONN_MANAGER_MAX_PER_CONN));
      httpConnManager = poolingConnMgr;
      break;
    default:
      throw new IllegalArgumentException(connMgrStr + " is not supported");
  }

  LOG.info("Using " + httpConnManager.getClass().getSimpleName());
  return httpConnManager;
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:20,代码来源:ApacheHttpAsyncClient.java

示例8: AsyncServiceClient

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
public AsyncServiceClient(ClientConfiguration config) {
    super(config);
    try {
        IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
                .setIoThreadCount(config.getIoThreadCount()).build();
        ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(
                ioReactorConfig);
        PoolingNHttpClientConnectionManager cm = new PoolingNHttpClientConnectionManager(
                ioReactor);
        cm.setMaxTotal(config.getMaxConnections());
        cm.setDefaultMaxPerRoute(config.getMaxConnections());
        httpClient = new HttpFactory().createHttpAsyncClient(config, cm);

        /*
         * socketTimeout的值限制了closeIdleConnections执行的周期。
         * 如果周期相对socketTimeout的值过长,有可能一个请求分配到一个即将socketTimeout的连接,
         * 在请求发送之前即抛出SocketTimeoutException。
         * 现在让closeIdleConnections的执行周期为socketTimeout / 2.5。
         */
        long closePeriod = 5000;
        if (config.getSocketTimeoutInMillisecond() > 0) {
            closePeriod = (long) (config.getSocketTimeoutInMillisecond() / 2.5);
        }
        closePeriod = closePeriod < 5000 ? closePeriod : 5000;
        connEvictor = new IdleConnectionEvictor(cm, closePeriod);
        httpClient.start();
        connEvictor.start();
    } catch (IOReactorException ex) {
        throw new ClientException(String.format("IOReactorError: %s",
                ex.getMessage()), ex);
    }
}
 
开发者ID:aliyun,项目名称:aliyun-tablestore-java-sdk,代码行数:33,代码来源:AsyncServiceClient.java

示例9: poolingNHttpClientConnectionManager

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
@Bean
PoolingNHttpClientConnectionManager poolingNHttpClientConnectionManager() throws IOReactorException {
    PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager(
            new DefaultConnectingIOReactor(IOReactorConfig.DEFAULT));
    connectionManager.setMaxTotal(maxTotalConnections);
    connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);
    return connectionManager;
}
 
开发者ID:Orange-OpenSource,项目名称:fiware-ngsi-api,代码行数:9,代码来源:HttpConfiguration.java

示例10: RmendRequestAdapter

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
public RmendRequestAdapter(String _targetHost, String _endpointTemplate) throws IOReactorException {
    ioReactor = new DefaultConnectingIOReactor();
    cm = new PoolingNHttpClientConnectionManager(ioReactor);
    cm.setMaxTotal(20);

    httpclient = HttpAsyncClients.createPipelining();
    this.targetHost = _targetHost;
    this.endpointTemplate = _endpointTemplate;
}
 
开发者ID:balarj,项目名称:rmend-commons,代码行数:10,代码来源:RmendRequestAdapter.java

示例11: asyncHttpClient

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
@Bean
public CloseableHttpAsyncClient asyncHttpClient() throws Exception {
    PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor(
            IOReactorConfig.DEFAULT));
    connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);
    connectionManager.setMaxPerRoute(new HttpRoute(new HttpHost("localhost")), 20);
    RequestConfig config = RequestConfig.custom().setConnectTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS).build();

    CloseableHttpAsyncClient httpclient = HttpAsyncClientBuilder.create().setConnectionManager(connectionManager).setDefaultRequestConfig(config)
            .build();
    return httpclient;
}
 
开发者ID:gustavoorsi,项目名称:searchahouse.com,代码行数:14,代码来源:RestTemplateConfiguration.java

示例12: initialize

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
private HttpAsyncClientBuilder initialize() {
    try {
        final PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(
            new DefaultConnectingIOReactor( IOReactorConfig.custom()
                .setConnectTimeout( connectTimeout )
                .setSoTimeout( readTimeout )
                .build() ),
            RegistryBuilder.<SchemeIOSessionStrategy>create()
                .register( "http", NoopIOSessionStrategy.INSTANCE )
                .register( "https",
                    new SSLIOSessionStrategy( certificateLocation != null ?
                        createSSLContext( certificateLocation, certificatePassword )
                        : SSLContexts.createDefault(),
                        split( System.getProperty( "https.protocols" ) ),
                        split( System.getProperty( "https.cipherSuites" ) ),
                        new DefaultHostnameVerifier( PublicSuffixMatcherLoader.getDefault() ) ) )
                .build() );

        connManager.setMaxTotal( maxConnTotal );
        connManager.setDefaultMaxPerRoute( maxConnPerRoute );

        return ( certificateLocation != null ?
            HttpAsyncClients.custom()
                .setSSLContext( createSSLContext( certificateLocation, certificatePassword ) )
            : HttpAsyncClients.custom() )
            .setMaxConnPerRoute( maxConnPerRoute )
            .setConnectionManager( connManager )
            .setMaxConnTotal( maxConnTotal )
            .setKeepAliveStrategy( DefaultConnectionKeepAliveStrategy.INSTANCE )
            .setDefaultRequestConfig( RequestConfig
                .custom()
                .setRedirectsEnabled( redirectsEnabled )
                .setCookieSpec( cookieSpec )
                .build() )
            .setDefaultCookieStore( basicCookieStore );
    } catch( IOReactorException e ) {
        throw new UncheckedIOException( e );
    }
}
 
开发者ID:oaplatform,项目名称:oap,代码行数:40,代码来源:Client.java

示例13: createNHttpClientConnectionManager

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
/**
 * Create connection manager for asynchronous http client.
 *
 * @return Connection manager for asynchronous http client.
 * @throws IOReactorException in case if a non-recoverable I/O error.
 */
protected NHttpClientConnectionManager createNHttpClientConnectionManager() throws IOReactorException {
    ConnectingIOReactor ioReactor =
            new DefaultConnectingIOReactor(IOReactorConfig.custom()
                    .setSoTimeout(this.config.getSocketTimeoutInMillis()).setTcpNoDelay(true).build());
    PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager(ioReactor);
    connectionManager.setDefaultMaxPerRoute(this.config.getMaxConnections());
    connectionManager.setMaxTotal(this.config.getMaxConnections());
    return connectionManager;
}
 
开发者ID:baidubce,项目名称:bce-sdk-java,代码行数:16,代码来源:BceHttpClient.java

示例14: AsyncClient

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
public AsyncClient() throws IOException {

        // Create I/O reactor configuration
        IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
                .setIoThreadCount(Runtime.getRuntime().availableProcessors())
                .setTcpNoDelay(true)
                .build();

        // Create a custom I/O reactor
        ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);

        // Create a custom Connection Manager
        connManager = new PoolingNHttpClientConnectionManager(ioReactor);
        connManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
        connManager.setMaxTotal(defaultMaxPerRoute * MAX_CONN_MULTIPLICATION);

        // Create global request configuration
        RequestConfig defaultRequestConfig = RequestConfig.custom()
                .setCookieSpec(CookieSpecs.DEFAULT)
                .setExpectContinueEnabled(true)
                .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
                .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
                .build();

        // Update the request level configuration
        updateRequestConfig();

        // Create a custom Redirect Handler
        redirectStrategy = new RedirectHandler(requestConfig);

        httpAsyncClient = HttpAsyncClients.custom()
                .setConnectionManager(connManager)
                .setDefaultRequestConfig(defaultRequestConfig)
                .setRedirectStrategy(redirectStrategy)
                .build();
    }
 
开发者ID:adohe,项目名称:GenAsyncClient,代码行数:37,代码来源:AsyncClient.java

示例15: createPoolingHttpClient

import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; //导入方法依赖的package包/类
private static CloseableHttpAsyncClient createPoolingHttpClient(HiTSDBConfig config,PoolingNHttpClientConnectionManager cm,SemaphoreManager semaphoreManager) throws HttpClientInitException {
	int httpConnectionPool = config.getHttpConnectionPool();
	int httpConnectionLiveTime = config.getHttpConnectionLiveTime();
	int httpKeepaliveTime = config.getHttpKeepaliveTime();
	
	RequestConfig requestConfig = initRequestConfig(config);
	
	if (httpConnectionPool > 0) {
		cm.setMaxTotal(httpConnectionPool);
		cm.setDefaultMaxPerRoute(httpConnectionPool);
		cm.closeExpiredConnections();
	}

	HttpAsyncClientBuilder httpAsyncClientBuilder = HttpAsyncClients.custom();

	// 设置连接管理器
	httpAsyncClientBuilder.setConnectionManager(cm);

	// 设置RequestConfig
	if (requestConfig != null) {
		httpAsyncClientBuilder.setDefaultRequestConfig(requestConfig);
	}

	// 设置Keepalive
	if (httpKeepaliveTime > 0) {
		HiTSDBConnectionKeepAliveStrategy hiTSDBConnectionKeepAliveStrategy = new HiTSDBConnectionKeepAliveStrategy(httpConnectionLiveTime);
		httpAsyncClientBuilder.setKeepAliveStrategy(hiTSDBConnectionKeepAliveStrategy);
	} else if (httpKeepaliveTime == 0) {
		HiTSDBConnectionReuseStrategy hiTSDBConnectionReuseStrategy = new HiTSDBConnectionReuseStrategy();
		httpAsyncClientBuilder.setConnectionReuseStrategy(hiTSDBConnectionReuseStrategy);
	}

	// 设置连接自动关闭
	if(httpConnectionLiveTime > 0) {
		HiTSDBHttpAsyncCallbackExecutor httpAsyncCallbackExecutor = new HiTSDBHttpAsyncCallbackExecutor(httpConnectionLiveTime);
		httpAsyncClientBuilder.setEventHandler(httpAsyncCallbackExecutor);
	}
	
	// 启动定时调度
	initFixedCycleCloseConnection(cm);

	CloseableHttpAsyncClient client = httpAsyncClientBuilder.build();
	return client;
}
 
开发者ID:aliyun,项目名称:HiTSDB-Client,代码行数:45,代码来源:HttpClientFactory.java


注:本文中的org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.setMaxTotal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。