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


Java ConnPerRoute类代码示例

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


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

示例1: ConnPoolByRoute

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
/**
 * @since 4.1
 */
public ConnPoolByRoute(
        final ClientConnectionOperator operator,
        final ConnPerRoute connPerRoute,
        int maxTotalConnections,
        long connTTL,
        final TimeUnit connTTLTimeUnit) {
    super();
    if (operator == null) {
        throw new IllegalArgumentException("Connection operator may not be null");
    }
    if (connPerRoute == null) {
        throw new IllegalArgumentException("Connections per route may not be null");
    }
    this.poolLock = super.poolLock;
    this.leasedConnections = super.leasedConnections;
    this.operator = operator;
    this.connPerRoute = connPerRoute;
    this.maxTotalConnections = maxTotalConnections;
    this.freeConnections = createFreeConnQueue();
    this.waitingThreads  = createWaitingThreadQueue();
    this.routeToPool     = createRouteToPoolMap();
    this.connTTL = connTTL;
    this.connTTLTimeUnit = connTTLTimeUnit;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:ConnPoolByRoute.java

示例2: ConnPoolByRoute

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
/**
 * @since 4.1
 */
public ConnPoolByRoute(
        final ClientConnectionOperator operator,
        final ConnPerRoute connPerRoute,
        final int maxTotalConnections,
        final long connTTL,
        final TimeUnit connTTLTimeUnit) {
    super();
    Args.notNull(operator, "Connection operator");
    Args.notNull(connPerRoute, "Connections per route");
    this.poolLock = super.poolLock;
    this.leasedConnections = super.leasedConnections;
    this.operator = operator;
    this.connPerRoute = connPerRoute;
    this.maxTotalConnections = maxTotalConnections;
    this.freeConnections = createFreeConnQueue();
    this.waitingThreads  = createWaitingThreadQueue();
    this.routeToPool     = createRouteToPoolMap();
    this.connTTL = connTTL;
    this.connTTLTimeUnit = connTTLTimeUnit;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:ConnPoolByRoute.java

示例3: generateHttpClient

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的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

示例4: generateHttpClient

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的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

示例5: generateHttpClient

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的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

示例6: RouteSpecificPool

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
/**
 * Creates a new route-specific pool.
 *
 * @param route the route for which to pool
 * @param connPerRoute the connections per route configuration
 */
public RouteSpecificPool(HttpRoute route, ConnPerRoute connPerRoute) {
    this.route = route;
    this.connPerRoute = connPerRoute;
    this.maxEntries = connPerRoute.getMaxForRoute(route);
    this.freeEntries = new LinkedList<BasicPoolEntry>();
    this.waitingThreads = new LinkedList<WaitingThread>();
    this.numEntries = 0;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:RouteSpecificPool.java

示例7: RouteSpecificPool

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
/**
 * @deprecated (4.1)  use {@link RouteSpecificPool#RouteSpecificPool(HttpRoute, ConnPerRoute)}
 */
@Deprecated
public RouteSpecificPool(final HttpRoute route, final int maxEntries) {
    this.route = route;
    this.maxEntries = maxEntries;
    this.connPerRoute = new ConnPerRoute() {
        @Override
        public int getMaxForRoute(final HttpRoute unused) {
            return RouteSpecificPool.this.maxEntries;
        }
    };
    this.freeEntries = new LinkedList<BasicPoolEntry>();
    this.waitingThreads = new LinkedList<WaitingThread>();
    this.numEntries = 0;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:RouteSpecificPool.java

示例8: createClientConnectionManager

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
private static ClientConnectionManager createClientConnectionManager() {
    HttpParams params = new BasicHttpParams();
    params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, MAX_CONNECTIONS);
    params.setParameter(ConnManagerParams.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRoute() {
        @Override
        public int getMaxForRoute(HttpRoute httpRoute) {
            return MAX_CONNECTIONS_PER_ROUTE;
        }
    });
    return new ThreadSafeClientConnManager(params, prepareSchemeRegistry());
}
 
开发者ID:danieloeh,项目名称:AntennaPodSP,代码行数:12,代码来源:AntennapodHttpClient.java

示例9: getParams

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
/**
 * @return the default HttpParams
 * @see <a href="http://developer.android.com/reference/android/net/http/AndroidHttpClient.html#newInstance(java.lang.String, android.content.Context)">
 *      android.net.http.AndroidHttpClient#newInstance(String, Context)</a>
 */
protected HttpParams getParams() {
    final HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, TIMEOUT);
    HttpConnectionParams.setSocketBufferSize(params, BUFFER_SIZE);
    ConnManagerParams.setMaxTotalConnections(params, MAX_TOTAL_CONNECTIONS);

    // 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);

    // fix contributed by Bjorn Roche XXX check if still needed
    params.setBooleanParameter("http.protocol.expect-continue", false);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRoute() {
        @Override
        public int getMaxForRoute(HttpRoute httpRoute) {
            if (env.isApiHost(httpRoute.getTargetHost())) {
                // there will be a lot of concurrent request to the API host
                return MAX_TOTAL_CONNECTIONS;
            } else {
                return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE;
            }
        }
    });
    // apply system proxy settings
    final String proxyHost = System.getProperty("http.proxyHost");
    final String proxyPort = System.getProperty("http.proxyPort");
    if (proxyHost != null) {
        int port = 80;
        try {
            port = Integer.parseInt(proxyPort);
        } catch (NumberFormatException ignored) {
        }
        params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, port));
    }
    return params;
}
 
开发者ID:triveous,项目名称:SoundcloudAPI,代码行数:43,代码来源:ApiWrapper.java

示例10: getParams

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
/**
 * @return the default HttpParams
 * @see <a href="http://developer.android.com/reference/android/net/http/AndroidHttpClient.html#newInstance(java.lang.String, android.content.Context)">
 *      android.net.http.AndroidHttpClient#newInstance(String, Context)</a>
 */
protected HttpParams getParams() {
	final HttpParams params = new BasicHttpParams();
	HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
	HttpConnectionParams.setSoTimeout(params, TIMEOUT);
	HttpConnectionParams.setSocketBufferSize(params, BUFFER_SIZE);
	ConnManagerParams.setMaxTotalConnections(params, MAX_TOTAL_CONNECTIONS);

	// 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);

	// fix contributed by Bjorn Roche XXX check if still needed
	params.setBooleanParameter("http.protocol.expect-continue", false);
	params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRoute() {
		@Override
		public int getMaxForRoute(HttpRoute httpRoute) {
			if (env.isApiHost(httpRoute.getTargetHost())) {
				// there will be a lot of concurrent request to the API host
				return MAX_TOTAL_CONNECTIONS;
			} else {
				return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE;
			}
		}
	});
	// apply system proxy settings
	final String proxyHost = System.getProperty("http.proxyHost");
	final String proxyPort = System.getProperty("http.proxyPort");
	if (proxyHost != null) {
		int port = 80;
		try {
			port = Integer.parseInt(proxyPort);
		} catch (NumberFormatException ignored) {
		}
		params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, port));
	}
	return params;
}
 
开发者ID:EnteriseToolkit,项目名称:paperchains,代码行数:43,代码来源:ApiWrapper.java

示例11: NamedConnectionPool

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
public NamedConnectionPool(String name, ClientConnectionOperator operator,
        ConnPerRoute connPerRoute, int maxTotalConnections, long connTTL,
        TimeUnit connTTLTimeUnit) {
    super(operator, connPerRoute, maxTotalConnections, connTTL, connTTLTimeUnit);
    initMonitors(name);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:7,代码来源:NamedConnectionPool.java

示例12: CougarConnPoolByRoute

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
private CougarConnPoolByRoute(ClientConnectionOperator operator, ConnPerRoute connPerRoute,
                              int maxTotalConnections, long connTTL, TimeUnit connTTLTimeUnit) {
    super(operator, connPerRoute, maxTotalConnections, connTTL, connTTLTimeUnit);
}
 
开发者ID:betfair,项目名称:cougar,代码行数:5,代码来源:CougarClientConnManager.java

示例13: HttpManager

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
private HttpManager(Boolean debug, String version) {
	// Set basic data
	HttpParams params = new BasicHttpParams();
	HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
	HttpProtocolParams.setContentCharset(params, "UTF-8");
	HttpProtocolParams.setUseExpectContinue(params, true);
	HttpProtocolParams.setUserAgent(params, HttpUtils.userAgent);

	// Make pool
	ConnPerRoute connPerRoute = new ConnPerRouteBean(12);
	ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
	ConnManagerParams.setMaxTotalConnections(params, 20);

	// Set timeout
	HttpConnectionParams.setStaleCheckingEnabled(params, false);
	HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
	HttpConnectionParams.setSoTimeout(params, 20 * 1000);
	HttpConnectionParams.setSocketBufferSize(params, 8192);

	// Some client params
	HttpClientParams.setRedirecting(params, false);

	// Register http/s schemas!
	SchemeRegistry schReg = new SchemeRegistry();
	schReg.register(new Scheme("http", PlainSocketFactory
			.getSocketFactory(), 80));

	if (debug) {
		// Install the all-trusting trust manager
		// Create a trust manager that does not validate certificate chains
		TrustManager[] trustManagers = new X509TrustManager[1];
		trustManagers[0] = new TrustAllManager();

		try {
			SSLContext sc = SSLContext.getInstance("SSL");
			sc.init(null, trustManagers, null);
			schReg.register(new Scheme("https", (SocketFactory) sc
					.getSocketFactory(), 443));
		} catch (Exception e) {
			;
		}
	} else {
		schReg.register(new Scheme("https", SSLSocketFactory
				.getSocketFactory(), 443));

	}
	ClientConnectionManager conMgr = new ThreadSafeClientConnManager(
			params, schReg);
	client = new DefaultHttpClient(conMgr, params);

}
 
开发者ID:ridhishguhan,项目名称:asianet-autologin,代码行数:52,代码来源:HttpManager.java

示例14: getHttpClient

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
public HttpClient getHttpClient() {
      HttpParams params = new BasicHttpParams();
      HttpProtocolParams.setUseExpectContinue(params, false);
      HttpProtocolParams.setUserAgent(params, ConnectioinConfig.userAgent);
      ConnManagerParams.setMaxTotalConnections(params, ConnectioinConfig.maxConnections);
      ConnManagerParams.setMaxConnectionsPerRoute(params,
              new ConnPerRoute() {
                  @Override
                  public int getMaxForRoute(HttpRoute httproute) {
                      return 32;
                  }
              });

      HttpClientParams.setRedirecting(params, true);

      params.setParameter(
              CoreConnectionPNames.CONNECTION_TIMEOUT, ConnectioinConfig.connectionTimeout);
      params.setParameter(CoreConnectionPNames.SO_TIMEOUT,
              ConnectioinConfig.socketTimeout);
      params.setParameter(
              CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024);

      params.setParameter(ClientPNames.HANDLE_REDIRECTS,
              Boolean.FALSE);
      params.setParameter(
              CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); // 默认为ISO-8859-1
      params.setParameter(
              CoreProtocolPNames.HTTP_ELEMENT_CHARSET, "UTF-8"); // 默认为US-ASCII
      params.removeParameter(ConnRouteParams.DEFAULT_PROXY);

      SchemeRegistry schReg = new SchemeRegistry();
      schReg.register(new Scheme("http", PlainSocketFactory
              .getSocketFactory(), 80));
      schReg.register(new Scheme("https", SSLSocketFactory
              .getSocketFactory(), 443));
      ThreadSafeClientConnManager conMgr = new ThreadSafeClientConnManager(
              params, schReg);
      
      DefaultHttpClient client = new DefaultHttpClient(conMgr, params);
      
      
      //Auto retry.
      client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
	
	@Override
	public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
		
		if(executionCount > ConnectioinConfig.maxRetryCount)
			 return false;
		
		if(exception instanceof NoHttpResponseException)
			return true; 
		
		if(exception instanceof SocketTimeoutException)
			return true;
		
		return false;
	}
});
      
      return client;
  }
 
开发者ID:ksyun,项目名称:ks3-sdk-java,代码行数:63,代码来源:HttpFactory.java

示例15: getHttpClient

import org.apache.http.conn.params.ConnPerRoute; //导入依赖的package包/类
/**
 * Get a singleton, thread-safe HttpClient for making HTTP requests.
 */
public static synchronized HttpClient getHttpClient() {
	if (customHttpClient == null) {
		final HttpParams params = new BasicHttpParams();
		HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
		HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
		HttpProtocolParams.setUseExpectContinue(params, false);

		ConnManagerParams.setTimeout(params, 100);

		HttpConnectionParams.setConnectionTimeout(params, 10000);
		HttpConnectionParams.setSoTimeout(params, 10000);

		final SchemeRegistry schReg = new SchemeRegistry();
		schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
		schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));


		ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() {
			@Override
			public int getMaxForRoute(final HttpRoute httproute)
			{
				return 20;
			}
		});

		final ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params,schReg);

		customHttpClient = new DefaultHttpClient(conMgr, params);
		requestRetryHandler = new DefaultHttpRequestRetryHandler(5, false){

			@Override
			public boolean retryRequest(IOException ex, int count, HttpContext cx) {
				if(super.retryRequest(ex, count, cx)){
					Log.d(TAG, "Retrying request " + cx.toString());
					try {
						Thread.sleep(2000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					return true;
				}
				else{
					return false;
				}
			}
		};

		customHttpClient.setHttpRequestRetryHandler(requestRetryHandler);
	}
	return customHttpClient;
}
 
开发者ID:tristan2468,项目名称:OyVer,代码行数:55,代码来源:CustomHTTPClient.java


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