當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。