本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}