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


Java ConnManagerParams.setMaxConnectionsPerRoute方法代碼示例

本文整理匯總了Java中org.apache.http.conn.params.ConnManagerParams.setMaxConnectionsPerRoute方法的典型用法代碼示例。如果您正苦於以下問題:Java ConnManagerParams.setMaxConnectionsPerRoute方法的具體用法?Java ConnManagerParams.setMaxConnectionsPerRoute怎麽用?Java ConnManagerParams.setMaxConnectionsPerRoute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.conn.params.ConnManagerParams的用法示例。


在下文中一共展示了ConnManagerParams.setMaxConnectionsPerRoute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public static HttpClient get() {
    HttpParams httpParams = new BasicHttpParams();
    ConnManagerParams.setTimeout(httpParams, 3000);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(30));
    ConnManagerParams.setMaxTotalConnections(httpParams, 30);
    HttpClientParams.setRedirecting(httpParams, true);
    HttpProtocolParams.setUseExpectContinue(httpParams, true);
    HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
    HttpConnectionParams.setSoTimeout(httpParams, 2000);
    HttpConnectionParams.setConnectionTimeout(httpParams, 2000);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);
    HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTP_TAG, PlainSocketFactory.getSocketFactory(), 80));
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, sf, 443));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:26,代碼來源:PoolingClientConnectionManager.java

示例2: a

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public static b a(String str) {
    HttpParams basicHttpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
    HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
    HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
    HttpConnectionParams.setSocketBufferSize(basicHttpParams, 8192);
    HttpClientParams.setRedirecting(basicHttpParams, true);
    HttpClientParams.setAuthenticating(basicHttpParams, false);
    HttpProtocolParams.setUserAgent(basicHttpParams, str);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme(com.alipay.sdk.cons.b.a, SSLCertificateSocketFactory.getHttpSocketFactory(30000, null), WebSocket.DEFAULT_WSS_PORT));
    ClientConnectionManager threadSafeClientConnManager = new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry);
    ConnManagerParams.setTimeout(basicHttpParams, 60000);
    ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(10));
    ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
    Security.setProperty("networkaddress.cache.ttl", "-1");
    HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
    return new b(threadSafeClientConnManager, basicHttpParams);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:b.java

示例3: createHttpParams

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private HttpParams createHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUseExpectContinue(params, false);
    ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(3));
    ConnManagerParams.setMaxTotalConnections(params, 3);
    ConnManagerParams.setTimeout(params, 1000);
    HttpConnectionParams.setConnectionTimeout(params, 30000);
    HttpConnectionParams.setSoTimeout(params, 30000);
    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    HttpClientParams.setRedirecting(params, false);
    return params;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:17,代碼來源:HttpEngine.java

示例4: createHttpParams

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private static HttpParams createHttpParams() {
	final HttpParams params = new BasicHttpParams();
	// 設置是否啟用舊連接檢查,默認是開啟的。關閉這個舊連接檢查可以提高一點點性能,但是增加了I/O錯誤的風險(當服務端關閉連接時)。
	// 開啟這個選項則在每次使用老的連接之前都會檢查連接是否可用,這個耗時大概在15-30ms之間
	HttpConnectionParams.setStaleCheckingEnabled(params, false);
	HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);// 設置鏈接超時時間
	HttpConnectionParams.setSoTimeout(params, TIMEOUT);// 設置socket超時時間
	HttpConnectionParams.setSocketBufferSize(params, SOCKET_BUFFER_SIZE);// 設置緩存大小
	HttpConnectionParams.setTcpNoDelay(params, true);// 是否不使用延遲發送(true為不延遲)
	HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // 設置協議版本
	HttpProtocolParams.setUseExpectContinue(params, true);// 設置異常處理機製
	HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);// 設置編碼
	HttpClientParams.setRedirecting(params, false);// 設置是否采用重定向

	ConnManagerParams.setTimeout(params, TIMEOUT);// 設置超時
	ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(MAX_CONNECTIONS));// 多線程最大連接數
	ConnManagerParams.setMaxTotalConnections(params, 10); // 多線程總連接數
	return params;
}
 
開發者ID:cuilitang,項目名稱:CuiMarket,代碼行數:20,代碼來源:HttpClientFactory.java

示例5: getClient

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private static DefaultHttpClient getClient()
{
	if (client == null || !REUSE_CLIENT)
	{
		AQUtility.debug("creating http client");
		HttpParams httpParams = new BasicHttpParams();
		//httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
		HttpConnectionParams.setConnectionTimeout(httpParams, NET_TIMEOUT);
		HttpConnectionParams.setSoTimeout(httpParams, NET_TIMEOUT);
		//ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(NETWORK_POOL));
		ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(25));
		//Added this line to avoid issue at: http://stackoverflow.com/questions/5358014/android-httpclient-oom-on-4g-lte-htc-thunderbolt
		HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
		SchemeRegistry registry = new SchemeRegistry();
		registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
		registry.register(new Scheme("https", ssf == null ? SSLSocketFactory.getSocketFactory() : ssf, 443));
		ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, registry);
		client = new DefaultHttpClient(cm, httpParams);
	}
	return client;
}
 
開發者ID:libit,項目名稱:lr_dialer,代碼行數:22,代碼來源:AbstractAjaxCallback.java

示例6: AsyncHttpClient

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public AsyncHttpClient(SchemeRegistry schemeregistry)
{
    a = 10;
    b = 10000;
    h = true;
    BasicHttpParams basichttpparams = new BasicHttpParams();
    ConnManagerParams.setTimeout(basichttpparams, b);
    ConnManagerParams.setMaxConnectionsPerRoute(basichttpparams, new ConnPerRouteBean(a));
    ConnManagerParams.setMaxTotalConnections(basichttpparams, 10);
    HttpConnectionParams.setSoTimeout(basichttpparams, b);
    HttpConnectionParams.setConnectionTimeout(basichttpparams, b);
    HttpConnectionParams.setTcpNoDelay(basichttpparams, true);
    HttpConnectionParams.setSocketBufferSize(basichttpparams, 8192);
    HttpProtocolParams.setVersion(basichttpparams, HttpVersion.HTTP_1_1);
    ThreadSafeClientConnManager threadsafeclientconnmanager = new ThreadSafeClientConnManager(basichttpparams, schemeregistry);
    e = getDefaultThreadPool();
    f = new WeakHashMap();
    g = new HashMap();
    d = new SyncBasicHttpContext(new BasicHttpContext());
    c = new DefaultHttpClient(threadsafeclientconnmanager, basichttpparams);
    c.addRequestInterceptor(new a(this));
    c.addResponseInterceptor(new b(this));
    c.addRequestInterceptor(new c(this), 0);
    c.setHttpRequestRetryHandler(new z(5, 1500));
}
 
開發者ID:vishnudevk,項目名稱:MiBandDecompiled,代碼行數:26,代碼來源:AsyncHttpClient.java

示例7: RESTMusicService

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public RESTMusicService() {

        // Create and initialize default HTTP parameters
        HttpParams params = new BasicHttpParams();
        ConnManagerParams.setMaxTotalConnections(params, 20);
        ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(20));
        HttpConnectionParams.setConnectionTimeout(params, SOCKET_CONNECT_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_DEFAULT);

        // Turn off stale checking.  Our connections break all the time anyway,
        // and it's not worth it to pay the penalty of checking every time.
        HttpConnectionParams.setStaleCheckingEnabled(params, false);

        // Create and initialize scheme registry
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        schemeRegistry.register(new Scheme("https", createSSLSocketFactory(), 443));

        // Create an HttpClient with the ThreadSafeClientConnManager.
        // This connection manager must be used if more than one thread will
        // be using the HttpClient.
        connManager = new ThreadSafeClientConnManager(params, schemeRegistry);
        httpClient = new DefaultHttpClient(connManager, params);
    }
 
開發者ID:MadMarty,項目名稱:madsonic-5.5,代碼行數:25,代碼來源:RESTMusicService.java

示例8: generateHttpClient

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public static HttpClient generateHttpClient(final int maxTotalConnections,
                                            final int maxTotalConnectionsPerRoute, int connTimeout) {
  HttpParams params = new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections);
  ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() {
    @Override
    public int getMaxForRoute(HttpRoute route) {
      return maxTotalConnectionsPerRoute;
    }
  });
  HttpConnectionParams
      .setConnectionTimeout(params, connTimeout);
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(
      new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
  sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
  ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry);
  return new DefaultHttpClient(conMgr, params);
}
 
開發者ID:XiaoMi,項目名稱:galaxy-sdk-java,代碼行數:22,代碼來源:ClientFactory.java

示例9: ConnectionHelper

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private ConnectionHelper() {
	HttpParams httpParams = new BasicHttpParams();
	ConnManagerParams.setMaxTotalConnections(httpParams,
			MAX_TOTAL_CONNECTIONS);
	ConnPerRouteBean connPerRoute = new ConnPerRouteBean(
			MAX_CONNECTIONS_PER_HOST);
	ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute);

	HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
	HttpProtocolParams.setUseExpectContinue(httpParams, false);
	SchemeRegistry reg = new SchemeRegistry();
	reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(),
			80));
	reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(),
			443));
	ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(
			httpParams, reg);
	HttpConnectionParams.setConnectionTimeout(httpParams, CON_TIME_OUT_MS);
	HttpConnectionParams.setSoTimeout(httpParams, SO_TIME_OUT_MS);

	HttpClientParams.setCookiePolicy(httpParams,
			CookiePolicy.BROWSER_COMPATIBILITY);
	httpClient = new DefaultHttpClient(connectionManager, httpParams);
}
 
開發者ID:shenkaige,項目名稱:AndroidHttpTools,代碼行數:25,代碼來源:ConnectionHelper.java

示例10: generateHttpClient

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public static HttpClient generateHttpClient(final int maxTotalConnections,
    final int maxTotalConnectionsPerRoute, int connTimeout) {
  HttpParams params = new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections);
  ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() {
    @Override
    public int getMaxForRoute(HttpRoute route) {
      return maxTotalConnectionsPerRoute;
    }
  });
  HttpConnectionParams
      .setConnectionTimeout(params, connTimeout);
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(
      new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
  sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
  ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry);
  return new DefaultHttpClient(conMgr, params);
}
 
開發者ID:XiaoMi,項目名稱:galaxy-sdk-java,代碼行數:22,代碼來源:MetricsClientFactory.java

示例11: generateHttpClient

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public static HttpClient generateHttpClient(final int maxTotalConnections,
    final int maxTotalConnectionsPerRoute, int connTimeout) {
  HttpParams params = new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections);
  ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() {
    @Override
    public int getMaxForRoute(HttpRoute route) {
      return maxTotalConnectionsPerRoute;
    }
  });
  HttpConnectionParams
      .setConnectionTimeout(params, connTimeout);
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(
      new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
  sslSocketFactory.setHostnameVerifier(SSLSocketFactory.
      ALLOW_ALL_HOSTNAME_VERIFIER);
  schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
  ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params,
      schemeRegistry);
  return new DefaultHttpClient(conMgr, params);
}
 
開發者ID:XiaoMi,項目名稱:galaxy-sdk-java,代碼行數:24,代碼來源:EMQClientFactory.java

示例12: createHttpParams

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
private static final HttpParams createHttpParams() {
    final HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setUseExpectContinue(params, false);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    ConnManagerParams.setTimeout(params, NetworkHelper.SOCKET_TIMEOUT_MS);
    HttpConnectionParams.setConnectionTimeout(params,
            NetworkHelper.CONNECTION_TIMEOUT_MS);
    HttpConnectionParams.setSoTimeout(params,
            NetworkHelper.SOCKET_TIMEOUT_MS);

    ConnManagerParams.setMaxConnectionsPerRoute(params,
            new ConnPerRouteBean(NetworkHelper.MAX_TOTAL_CONNECTIONS));
    ConnManagerParams.setMaxTotalConnections(params,
            NetworkHelper.MAX_TOTAL_CONNECTIONS);

    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params,
            NetworkHelper.SOCKET_BUFFER_SIZE);
    HttpClientParams.setRedirecting(params, false);
    HttpProtocolParams.setUserAgent(params, "FanFou for Android/"
            + AppContext.appVersionName);
    return params;
}
 
開發者ID:mcxiaoke,項目名稱:fanfouapp-opensource,代碼行數:26,代碼來源:NetworkHelper.java

示例13: setMaxConnections

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public void setMaxConnections(int maxConnections) {
    if (maxConnections < 1) {
        maxConnections = 10;
    }
    this.maxConnections = maxConnections;
    ConnManagerParams.setMaxConnectionsPerRoute(this.httpClient.getParams(), new
            ConnPerRouteBean(this.maxConnections));
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:9,代碼來源:AsyncHttpClient.java

示例14: a

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
public static b a() {
    if (b == null) {
        HttpParams basicHttpParams = new BasicHttpParams();
        HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
        HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, true);
        basicHttpParams.setBooleanParameter("http.protocol.expect-continue", false);
        ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
        ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(30));
        ConnManagerParams.setTimeout(basicHttpParams, 1000);
        HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
        HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
        HttpConnectionParams.setSocketBufferSize(basicHttpParams, 16384);
        HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
        HttpClientParams.setRedirecting(basicHttpParams, true);
        HttpClientParams.setAuthenticating(basicHttpParams, false);
        HttpProtocolParams.setUserAgent(basicHttpParams, a);
        try {
            SocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
            socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            Scheme scheme = new Scheme(com.alipay.sdk.cons.b.a, socketFactory, WebSocket.DEFAULT_WSS_PORT);
            Scheme scheme2 = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(scheme);
            schemeRegistry.register(scheme2);
            b = new b(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
        } catch (Exception e) {
            b = new b(basicHttpParams);
        }
    }
    return b;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:32,代碼來源:b.java

示例15: setMaxConnections

import org.apache.http.conn.params.ConnManagerParams; //導入方法依賴的package包/類
/**
 * Sets maximum limit of parallel connections
 *
 * @param maxConnections maximum parallel connections, must be at least 1
 */
public void setMaxConnections(int maxConnections) {
    if (maxConnections < 1) maxConnections = DEFAULT_MAX_CONNECTIONS;
    this.maxConnections = maxConnections;
    final HttpParams httpParams = this.httpClient.getParams();
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(this.maxConnections));
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:12,代碼來源:SyncHttpClient.java


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