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


Java PoolingClientConnectionManager类代码示例

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


PoolingClientConnectionManager类属于org.apache.http.impl.conn包,在下文中一共展示了PoolingClientConnectionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHttpClient

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
/**
 * 每次返回一个新的HttpClient实例
 * @author nan.li
 * @return
 */
public static DefaultHttpClient getHttpClient()
{
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
    cm.setMaxTotal(500);
    cm.setDefaultMaxPerRoute(200);
    
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.connection.timeout", Integer.valueOf(CON_TIMEOUT));
    params.setParameter("http.socket.timeout", Integer.valueOf(SO_TIMEOUT));
    params.setParameter("http.useragent", UA_WINDOW7_CHROME);
    
    DefaultHttpClient client = new DefaultHttpClient(cm, params);
    return client;
}
 
开发者ID:lnwazg,项目名称:kit,代码行数:24,代码来源:HttpConnectionManager.java

示例2: pooledConnectionHttpClient

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
/**
 * Creates an HttpClient with a Pooling Client connection manager.
 *
 * @param maxConnections the max number of connections
 * @param connectionTimeoutInMs the connection timeout in ms.
 * @param socketTimeoutInMs the socket timeout in ms.
 * @return an HttpClient with a Pooling Client connection manager.
 */
public static HttpClient pooledConnectionHttpClient(int maxConnections, int connectionTimeoutInMs, int socketTimeoutInMs) {

    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    cm.setDefaultMaxPerRoute(maxConnections);
    cm.setMaxTotal(maxConnections);

    HttpClient httpClient = new DefaultHttpClient(cm);
    HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, connectionTimeoutInMs);
    HttpConnectionParams.setSoTimeout(params, socketTimeoutInMs);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Created Pooled HTTP Client. Max Connections per route=" + maxConnections +
                ", Max Connections=" + maxConnections + ", Connection Timeout in ms=" + connectionTimeoutInMs + ", Socket Timeout in ms=" + socketTimeoutInMs);
    }

    return httpClient;
}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:27,代码来源:HttpClientFactory.java

示例3: start

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
@Override
public boolean start() {
    try {
        httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
        bulkUri = makeURI(elasticSearchBaseUrl, "_bulk");

        /* only for debugging */
        if (deleteAllIndexWhenStart) {
            try {
                deleteIndex(null);
            } catch (Exception ex) {
                logger.warn(String.format("Failed to delete all index"), ex);
            }
        }

        populateExtensions();
        populateTriggerVOs();
        populateInventoryIndexer();
        dumpInventoryIndexer();
        createIndexIfNotExists();
        bus.registerService(this);
    } catch (Exception e) {
        throw new CloudRuntimeException(e);
    }
    return true;
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:27,代码来源:InventoryIndexManagerImpl.java

示例4: HttpClientFactory

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
/**
 * Constructor.
 * @param ssl True if SSL connections are desired. False otherwise.
 */
public HttpClientFactory(boolean ssl) {
    // create the logger
    logger = Logger.getLogger(HttpClientFactory.class);
    
    if (ssl) {
        sslConnectionsManager = new PoolingClientConnectionManager(getSchemeRegistry());
        sslConnectionsManager.setMaxTotal(Constants.MAX_CONNS);
        sslConnectionsManager.setDefaultMaxPerRoute(Constants.MAX_CONNS_PER_ROUTE);
    } else {
        connectionsManager = new PoolingClientConnectionManager();
        connectionsManager.setMaxTotal(Constants.MAX_CONNS);
        connectionsManager.setDefaultMaxPerRoute(Constants.MAX_CONNS_PER_ROUTE);
    } // if else
    
    logger.info("Setting max total connections (" + Constants.MAX_CONNS + ")");
    logger.info("Setting default max connections per route (" + Constants.MAX_CONNS_PER_ROUTE + ")");
}
 
开发者ID:telefonicaid,项目名称:fiware-tidoop,代码行数:22,代码来源:HttpClientFactory.java

示例5: testSetParams

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
@Test
public void testSetParams() {
  ModifiableSolrParams params = new ModifiableSolrParams();
  params.set(HttpClientUtil.PROP_ALLOW_COMPRESSION, true);
  params.set(HttpClientUtil.PROP_BASIC_AUTH_PASS, "pass");
  params.set(HttpClientUtil.PROP_BASIC_AUTH_USER, "user");
  params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 12345);
  params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, true);
  params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 22345);
  params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32345);
  params.set(HttpClientUtil.PROP_SO_TIMEOUT, 42345);
  params.set(HttpClientUtil.PROP_USE_RETRY, false);
  DefaultHttpClient client = (DefaultHttpClient) HttpClientUtil.createClient(params);
  assertEquals(12345, HttpConnectionParams.getConnectionTimeout(client.getParams()));
  assertEquals(PoolingClientConnectionManager.class, client.getConnectionManager().getClass());
  assertEquals(22345, ((PoolingClientConnectionManager)client.getConnectionManager()).getMaxTotal());
  assertEquals(32345, ((PoolingClientConnectionManager)client.getConnectionManager()).getDefaultMaxPerRoute());
  assertEquals(42345, HttpConnectionParams.getSoTimeout(client.getParams()));
  assertEquals(HttpClientUtil.NO_RETRY, client.getHttpRequestRetryHandler());
  assertEquals("pass", client.getCredentialsProvider().getCredentials(new AuthScope("127.0.0.1", 1234)).getPassword());
  assertEquals("user", client.getCredentialsProvider().getCredentials(new AuthScope("127.0.0.1", 1234)).getUserPrincipal().getName());
  assertEquals(true, client.getParams().getParameter(ClientPNames.HANDLE_REDIRECTS));
  client.getConnectionManager().shutdown();
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:HttpClientUtilTest.java

示例6: UpdateShardHandler

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
public UpdateShardHandler(ConfigSolr cfg) {
  
  clientConnectionManager = new PoolingClientConnectionManager(SchemeRegistryFactory.createSystemDefault());
  if (cfg != null ) {
    clientConnectionManager.setMaxTotal(cfg.getMaxUpdateConnections());
    clientConnectionManager.setDefaultMaxPerRoute(cfg.getMaxUpdateConnectionsPerHost());
  }
  
  
  ModifiableSolrParams params = new ModifiableSolrParams();
  if (cfg != null) {
    params.set(HttpClientUtil.PROP_SO_TIMEOUT,
        cfg.getDistributedSocketTimeout());
    params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT,
        cfg.getDistributedConnectionTimeout());
  }
  // in the update case, we want to do retries, and to use
  // the default Solr retry handler that createClient will 
  // give us
  params.set(HttpClientUtil.PROP_USE_RETRY, true);
  log.info("Creating UpdateShardHandler HTTP client with params: {}", params);
  client = HttpClientUtil.createClient(params, clientConnectionManager);
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:UpdateShardHandler.java

示例7: execute

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
/** Method to execute a request */
public HttpResponse execute(HttpRequestBase request) throws Exception {
    if (processQueue.tryAcquire()) {
        HttpResponse response;
        try {
            // Inject timestamp in milliseconds just before sending request on wire.
            // This will help in measuring latencies between client and server.
            if (request.getHeaders(TIMESTAMP_HEADER).length == 0) {
                request.addHeader(TIMESTAMP_HEADER, String.valueOf(System.currentTimeMillis()));
            }
            response = client.execute(request);
        } catch (Exception e) {
            logger.error("Connections: {} AvailableRequests: {}", ((PoolingClientConnectionManager) this.client.getConnectionManager()).getTotalStats(), processQueue.availablePermits());
            throw e;
        } finally {
            processQueue.release();
        }
        return response;
    } else {
        throw new Exception("PROCESS_QUEUE_FULL POOL:"+name);
    }
}
 
开发者ID:flipkart-incubator,项目名称:Poseidon,代码行数:23,代码来源:HttpConnectionPool.java

示例8: init

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
private void init(String host, int port, String userName, String password) {
    this.host = host;
    this.port = port;
    this.userName = userName;
    this.password = password;
    this.baseUrl = SCHEME_HTTP + host + ":" + port + KYLIN_API_PATH;

    final HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setSoTimeout(httpParams, httpSocketTimeoutMs);
    HttpConnectionParams.setConnectionTimeout(httpParams, httpConnectionTimeoutMs);

    final PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    KylinConfig config = KylinConfig.getInstanceFromEnv();
    cm.setDefaultMaxPerRoute(config.getRestClientDefaultMaxPerRoute());
    cm.setMaxTotal(config.getRestClientMaxTotal());

    client = new DefaultHttpClient(cm, httpParams);

    if (userName != null && password != null) {
        CredentialsProvider provider = new BasicCredentialsProvider();
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password);
        provider.setCredentials(AuthScope.ANY, credentials);
        client.setCredentialsProvider(provider);
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:26,代码来源:RestClient.java

示例9: createProxyClient

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
/**
 * create a proxy client
 * 
 * @return either a client or null if none is configured
 * @throws KeyManagementException
 * @throws NumberFormatException
 *           if that port could not be parsed.
 * @throws NoSuchAlgorithmException
 */
private static HttpClient createProxyClient(PlayProfile profile)
		throws KeyManagementException, NoSuchAlgorithmException {
	if (profile.getProxyAddress() == null) {
		return null;
	}

	PoolingClientConnectionManager connManager = new PoolingClientConnectionManager(
			SchemeRegistryFactory.createDefault());
	connManager.setMaxTotal(100);
	connManager.setDefaultMaxPerRoute(30);

	DefaultHttpClient client = new DefaultHttpClient(connManager);
	client.getConnectionManager().getSchemeRegistry()
			.register(Utils.getMockedScheme());
	HttpHost proxy = new HttpHost(profile.getProxyAddress(),
			profile.getProxyPort());
	client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
	if (profile.getProxyUser() != null && profile.getProxyPassword() != null) {
		client.getCredentialsProvider().setCredentials(
				new AuthScope(proxy),
				new UsernamePasswordCredentials(profile.getProxyUser(), profile
						.getProxyPassword()));
	}
	return client;
}
 
开发者ID:onyxbits,项目名称:raccoon4,代码行数:35,代码来源:PlayManager.java

示例10: getHttpClient

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
@Override
public HttpClient getHttpClient(AccountConfig accountConfig, HasProxySettings proxySettings) {
   	
       PoolingClientConnectionManager connectionManager = initConnectionManager();
       
       if(accountConfig.isDisableSslValidation()) {
           disableSslValidation(connectionManager);
       }
       
       org.apache.http.client.HttpClient httpClient = newHttpClient (connectionManager) ;
       
       int socketTimeout = accountConfig.getSocketTimeout() ;
       if (socketTimeout != -1) {
       	logger.info("Set socket timeout on HttpClient: " + socketTimeout);
           HttpParams params = httpClient.getParams();
           HttpConnectionParams.setSoTimeout(params, socketTimeout);
       }
       
       // proxy setting
       if (proxySettings != null)
        setProxySettings (httpClient, proxySettings, "http") ;
       
       return httpClient ;
}
 
开发者ID:roikku,项目名称:swift-explorer,代码行数:25,代码来源:HttpClientFactoryImpl.java

示例11: SparqlPersistance

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
@Inject
public SparqlPersistance(@Named("r2r.fusekiUrl") String sparqlQuery, SparqlPostClient sparqlClient) throws Exception {
	this.sparqlQuery = new SparqlQueryClient(sparqlQuery + "/query");
	this.sparqlClient = sparqlClient;
	
	// putting this here for now 
	HttpParams params = new BasicHttpParams();		
	HttpConnectionParams.setConnectionTimeout(params, 10000);
	HttpConnectionParams.setSoTimeout(params, 40000);
	PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
	cm.setDefaultMaxPerRoute(20);
	cm.setMaxTotal(200);
	HttpOp.setDefaultHttpClient(new DefaultHttpClient(cm, params));

	// make sure we have the latest model
	// for some reason we need to do post to capture the prefixes
	sparqlClient.post(R2ROntology.createR2ROntModel());
	sparqlClient.update("CREATE GRAPH <" + R2R_DERIVED_GRAPH + ">");
	// by loading these now, we make sure that we do not collide with calls to upsertAffiliation
	knownAffiliations = loadAffiliations();
}
 
开发者ID:CTSIatUCSF,项目名称:Crosslinks,代码行数:22,代码来源:SparqlPersistance.java

示例12: buildClient

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
private static HttpClient buildClient(final String fedoraUsername,
                                      final String fedoraPassword,
                                      final String repositoryURL) {
    final PoolingClientConnectionManager connMann = new PoolingClientConnectionManager();
    connMann.setMaxTotal(MAX_VALUE);
    connMann.setDefaultMaxPerRoute(MAX_VALUE);

    final DefaultHttpClient httpClient = new DefaultHttpClient(connMann);
    httpClient.setRedirectStrategy(new DefaultRedirectStrategy());
    httpClient.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler(0, false));

    // If the Fedora instance requires authentication, set it up here
    if (!isBlank(fedoraUsername) && !isBlank(fedoraPassword)) {
        LOGGER.debug("Adding BASIC credentials to client for repo requests.");

        final URI fedoraUri = URI.create(repositoryURL);
        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(fedoraUri.getHost(), fedoraUri.getPort()),
                                     new UsernamePasswordCredentials(fedoraUsername, fedoraPassword));

        httpClient.setCredentialsProvider(credsProvider);
    }
    return httpClient;
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo4-client,代码行数:25,代码来源:HttpHelper.java

示例13: afterPropertiesSet

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
	SchemeRegistry schemeRegistry = new SchemeRegistry();
	schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
	schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
	taobaoHttpManager = new PoolingClientConnectionManager(schemeRegistry);
	taobaoHttpManager.setMaxTotal(taobaoMaxConnection);
	taobaoHttpManager.setDefaultMaxPerRoute(taobaoMaxConnection); // 每条通道最大并发连接数
	log.info("Feedback http connection pool has start up..., max total is:" + taobaoMaxConnection);
	
	
	verifyReceiptDataHttpManager = new PoolingClientConnectionManager(schemeRegistry);;
	verifyReceiptDataHttpManager.setMaxTotal(verifyReceiptMaxConnection);
	verifyReceiptDataHttpManager.setDefaultMaxPerRoute(verifyReceiptMaxConnection);
	log.info("Feedback http connection pool has start up..., max total is:" + verifyReceiptDataHttpManager);
	
	commonHttpManager = new PoolingClientConnectionManager(schemeRegistry);;
	commonHttpManager.setMaxTotal(commonMaxConnection);
	commonHttpManager.setDefaultMaxPerRoute(commonMaxConnection);
	
	
	log.info("Feedback http connection pool has start up..., max total is:" + commonHttpManager);
}
 
开发者ID:Tassemble,项目名称:delicious,代码行数:24,代码来源:HttpClientUtils.java

示例14: getHttpsClientTrustAll

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
public HttpClient getHttpsClientTrustAll() {
    try {
        SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy(){
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return true;
            }
        }, new AllowAllHostnameVerifier());

        PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", 80, psf));
        registry.register(new Scheme("https", 443, sf));
        ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
        return new DefaultHttpClient(ccm);
    } catch (Exception ex) {
    	log.error("Failed to create TrustAll https client", ex);
        return new DefaultHttpClient();
    }
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:22,代码来源:HttpService.java

示例15: getHttpsClientDefaulTrustStore

import org.apache.http.impl.conn.PoolingClientConnectionManager; //导入依赖的package包/类
@Deprecated
public HttpClient getHttpsClientDefaulTrustStore() {
    try {
        PlainSocketFactory psf = PlainSocketFactory.getSocketFactory();

        SSLContext ctx = SSLContext.getInstance("TLS");
           SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", 80, psf));
        registry.register(new Scheme("https", 443, ssf));

        ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);

        return new DefaultHttpClient(ccm);
    } catch (Exception ex) {
    	log.error("Failed to create https client", ex);
        return new DefaultHttpClient();
    }
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:21,代码来源:HttpService.java


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