Simplified configuration of connection managers. Total connection maximum and maximum connection per route limits can be set using methods of the class instead of HTTP parameters
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@820971 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
91662f97ad
commit
30b38eb6e4
|
@ -1,6 +1,11 @@
|
||||||
Changes since 4.0
|
Changes since 4.0
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
* Simplified configuration of connection managers. Total connection maximum
|
||||||
|
and maximum connection per route limits can be set using methods of
|
||||||
|
the class instead of HTTP parameters.
|
||||||
|
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||||
|
|
||||||
* Added parameters to define the order of preference for supported auth
|
* Added parameters to define the order of preference for supported auth
|
||||||
schemes for target host and proxy authentication.
|
schemes for target host and proxy authentication.
|
||||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||||
|
|
|
@ -30,19 +30,14 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpVersion;
|
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example demonstrating how to evict expired and idle connections
|
* Example demonstrating how to evict expired and idle connections
|
||||||
|
@ -51,18 +46,15 @@ import org.apache.http.params.HttpProtocolParams;
|
||||||
public class ClientEvictExpiredConnections {
|
public class ClientEvictExpiredConnections {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Create and initialize HTTP parameters
|
|
||||||
HttpParams params = new BasicHttpParams();
|
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 100);
|
|
||||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
|
||||||
|
|
||||||
// Create and initialize scheme registry
|
// Create and initialize scheme registry
|
||||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
schemeRegistry.register(
|
schemeRegistry.register(
|
||||||
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||||
|
|
||||||
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
|
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
|
||||||
HttpClient httpclient = new DefaultHttpClient(cm, params);
|
cm.setMaxTotalConnections(100);
|
||||||
|
|
||||||
|
HttpClient httpclient = new DefaultHttpClient(cm);
|
||||||
|
|
||||||
// create an array of URIs to perform GETs on
|
// create an array of URIs to perform GETs on
|
||||||
String[] urisToGet = {
|
String[] urisToGet = {
|
||||||
|
|
|
@ -28,21 +28,15 @@ package org.apache.http.examples.client;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpVersion;
|
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
|
||||||
import org.apache.http.protocol.HttpContext;
|
|
||||||
import org.apache.http.protocol.BasicHttpContext;
|
import org.apache.http.protocol.BasicHttpContext;
|
||||||
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,11 +46,6 @@ import org.apache.http.util.EntityUtils;
|
||||||
public class ClientMultiThreadedExecution {
|
public class ClientMultiThreadedExecution {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Create and initialize HTTP parameters
|
|
||||||
HttpParams params = new BasicHttpParams();
|
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 100);
|
|
||||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
|
||||||
|
|
||||||
// Create and initialize scheme registry
|
// Create and initialize scheme registry
|
||||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
schemeRegistry.register(
|
schemeRegistry.register(
|
||||||
|
@ -65,8 +54,10 @@ public class ClientMultiThreadedExecution {
|
||||||
// Create an HttpClient with the ThreadSafeClientConnManager.
|
// Create an HttpClient with the ThreadSafeClientConnManager.
|
||||||
// This connection manager must be used if more than one thread will
|
// This connection manager must be used if more than one thread will
|
||||||
// be using the HttpClient.
|
// be using the HttpClient.
|
||||||
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
|
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
|
||||||
HttpClient httpClient = new DefaultHttpClient(cm, params);
|
cm.setMaxTotalConnections(100);
|
||||||
|
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(cm);
|
||||||
|
|
||||||
// create an array of URIs to perform GETs on
|
// create an array of URIs to perform GETs on
|
||||||
String[] urisToGet = {
|
String[] urisToGet = {
|
||||||
|
|
|
@ -145,7 +145,7 @@ public class ManagerConnectDirect {
|
||||||
|
|
||||||
private final static ClientConnectionManager createManager() {
|
private final static ClientConnectionManager createManager() {
|
||||||
|
|
||||||
return new ThreadSafeClientConnManager(getParams(), supportedSchemes);
|
return new ThreadSafeClientConnManager(supportedSchemes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class ManagerConnectProxy {
|
||||||
|
|
||||||
private final static ClientConnectionManager createManager() {
|
private final static ClientConnectionManager createManager() {
|
||||||
|
|
||||||
return new ThreadSafeClientConnManager(getParams(), supportedSchemes);
|
return new ThreadSafeClientConnManager(supportedSchemes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ public interface ConnManagerPNames {
|
||||||
* This parameter expects a value of type {@link ConnPerRoute}.
|
* This parameter expects a value of type {@link ConnPerRoute}.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final String MAX_CONNECTIONS_PER_ROUTE = "http.conn-manager.max-per-route";
|
public static final String MAX_CONNECTIONS_PER_ROUTE = "http.conn-manager.max-per-route";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,6 +62,7 @@ public interface ConnManagerPNames {
|
||||||
* This parameter expects a value of type {@link Integer}.
|
* This parameter expects a value of type {@link Integer}.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final String MAX_TOTAL_CONNECTIONS = "http.conn-manager.max-total";
|
public static final String MAX_TOTAL_CONNECTIONS = "http.conn-manager.max-total";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,13 @@ public class ConnManagerParamBean extends HttpAbstractParamBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS */
|
/** @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS */
|
||||||
|
@Deprecated
|
||||||
public void setMaxTotalConnections (final int maxConnections) {
|
public void setMaxTotalConnections (final int maxConnections) {
|
||||||
params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, maxConnections);
|
params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, maxConnections);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE */
|
/** @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE */
|
||||||
|
@Deprecated
|
||||||
public void setConnectionsPerRoute(final ConnPerRouteBean connPerRoute) {
|
public void setConnectionsPerRoute(final ConnPerRouteBean connPerRoute) {
|
||||||
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, connPerRoute);
|
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, connPerRoute);
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ public final class ConnManagerParams implements ConnManagerPNames {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The default maximum number of connections allowed per host */
|
/** The default maximum number of connections allowed per host */
|
||||||
|
@Deprecated
|
||||||
private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() {
|
private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() {
|
||||||
|
|
||||||
public int getMaxForRoute(HttpRoute route) {
|
public int getMaxForRoute(HttpRoute route) {
|
||||||
|
@ -89,8 +90,11 @@ public final class ConnManagerParams implements ConnManagerPNames {
|
||||||
* @param connPerRoute lookup interface for maximum number of connections allowed
|
* @param connPerRoute lookup interface for maximum number of connections allowed
|
||||||
* per route
|
* per route
|
||||||
*
|
*
|
||||||
|
* @deprecated do not use
|
||||||
|
*
|
||||||
* @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE
|
* @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static void setMaxConnectionsPerRoute(final HttpParams params,
|
public static void setMaxConnectionsPerRoute(final HttpParams params,
|
||||||
final ConnPerRoute connPerRoute) {
|
final ConnPerRoute connPerRoute) {
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
|
@ -107,8 +111,11 @@ public final class ConnManagerParams implements ConnManagerPNames {
|
||||||
*
|
*
|
||||||
* @return lookup interface for maximum number of connections allowed per route.
|
* @return lookup interface for maximum number of connections allowed per route.
|
||||||
*
|
*
|
||||||
|
* @deprecated do not use
|
||||||
|
*
|
||||||
* @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE
|
* @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) {
|
public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) {
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
|
@ -128,8 +135,11 @@ public final class ConnManagerParams implements ConnManagerPNames {
|
||||||
* @param params HTTP parameters
|
* @param params HTTP parameters
|
||||||
* @param maxTotalConnections The maximum number of connections allowed.
|
* @param maxTotalConnections The maximum number of connections allowed.
|
||||||
*
|
*
|
||||||
|
* @deprecated do not use
|
||||||
|
*
|
||||||
* @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS
|
* @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static void setMaxTotalConnections(
|
public static void setMaxTotalConnections(
|
||||||
final HttpParams params,
|
final HttpParams params,
|
||||||
int maxTotalConnections) {
|
int maxTotalConnections) {
|
||||||
|
@ -147,8 +157,11 @@ public final class ConnManagerParams implements ConnManagerPNames {
|
||||||
*
|
*
|
||||||
* @return The maximum number of connections allowed.
|
* @return The maximum number of connections allowed.
|
||||||
*
|
*
|
||||||
|
* @deprecated do not use
|
||||||
|
*
|
||||||
* @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS
|
* @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static int getMaxTotalConnections(
|
public static int getMaxTotalConnections(
|
||||||
final HttpParams params) {
|
final HttpParams params) {
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
|
|
|
@ -29,7 +29,8 @@ package org.apache.http.conn.params;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.http.annotation.NotThreadSafe;
|
import org.apache.http.annotation.GuardedBy;
|
||||||
|
import org.apache.http.annotation.ThreadSafe;
|
||||||
|
|
||||||
import org.apache.http.conn.routing.HttpRoute;
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
|
|
||||||
|
@ -41,14 +42,16 @@ import org.apache.http.conn.routing.HttpRoute;
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
@NotThreadSafe // maxPerHostMap and defaultMax
|
@ThreadSafe
|
||||||
public final class ConnPerRouteBean implements ConnPerRoute {
|
public final class ConnPerRouteBean implements ConnPerRoute {
|
||||||
|
|
||||||
/** The default maximum number of connections allowed per host */
|
/** The default maximum number of connections allowed per host */
|
||||||
public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 2; // Per RFC 2616 sec 8.1.4
|
public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 2; // Per RFC 2616 sec 8.1.4
|
||||||
|
|
||||||
|
@GuardedBy("this")
|
||||||
private final Map<HttpRoute, Integer> maxPerHostMap;
|
private final Map<HttpRoute, Integer> maxPerHostMap;
|
||||||
|
|
||||||
|
@GuardedBy("this")
|
||||||
private int defaultMax;
|
private int defaultMax;
|
||||||
|
|
||||||
public ConnPerRouteBean(int defaultMax) {
|
public ConnPerRouteBean(int defaultMax) {
|
||||||
|
@ -61,11 +64,19 @@ public final class ConnPerRouteBean implements ConnPerRoute {
|
||||||
this(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);
|
this(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDefaultMax() {
|
@Deprecated
|
||||||
|
public synchronized int getDefaultMax() {
|
||||||
return this.defaultMax;
|
return this.defaultMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultMaxPerRoute(int max) {
|
/**
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
public synchronized int getDefaultMaxPerRoute() {
|
||||||
|
return this.defaultMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setDefaultMaxPerRoute(int max) {
|
||||||
if (max < 1) {
|
if (max < 1) {
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("The maximum must be greater than 0.");
|
("The maximum must be greater than 0.");
|
||||||
|
@ -73,7 +84,7 @@ public final class ConnPerRouteBean implements ConnPerRoute {
|
||||||
this.defaultMax = max;
|
this.defaultMax = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxForRoute(final HttpRoute route, int max) {
|
public synchronized void setMaxForRoute(final HttpRoute route, int max) {
|
||||||
if (route == null) {
|
if (route == null) {
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("HTTP route may not be null.");
|
("HTTP route may not be null.");
|
||||||
|
@ -85,7 +96,7 @@ public final class ConnPerRouteBean implements ConnPerRoute {
|
||||||
this.maxPerHostMap.put(route, Integer.valueOf(max));
|
this.maxPerHostMap.put(route, Integer.valueOf(max));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxForRoute(final HttpRoute route) {
|
public synchronized int getMaxForRoute(final HttpRoute route) {
|
||||||
if (route == null) {
|
if (route == null) {
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("HTTP route may not be null.");
|
("HTTP route may not be null.");
|
||||||
|
@ -98,7 +109,7 @@ public final class ConnPerRouteBean implements ConnPerRoute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxForRoutes(final Map<HttpRoute, Integer> map) {
|
public synchronized void setMaxForRoutes(final Map<HttpRoute, Integer> map) {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -106,9 +117,9 @@ public final class ConnPerRouteBean implements ConnPerRoute {
|
||||||
this.maxPerHostMap.putAll(map);
|
this.maxPerHostMap.putAll(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public synchronized String toString() {
|
||||||
return this.maxPerHostMap.toString();
|
return this.maxPerHostMap.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,8 +134,6 @@ import org.apache.http.util.VersionInfo;
|
||||||
* <li>{@link org.apache.http.conn.params.ConnRoutePNames#LOCAL_ADDRESS}</li>
|
* <li>{@link org.apache.http.conn.params.ConnRoutePNames#LOCAL_ADDRESS}</li>
|
||||||
* <li>{@link org.apache.http.conn.params.ConnRoutePNames#DEFAULT_PROXY}</li>
|
* <li>{@link org.apache.http.conn.params.ConnRoutePNames#DEFAULT_PROXY}</li>
|
||||||
* <li>{@link org.apache.http.conn.params.ConnManagerPNames#TIMEOUT}</li>
|
* <li>{@link org.apache.http.conn.params.ConnManagerPNames#TIMEOUT}</li>
|
||||||
* <li>{@link org.apache.http.conn.params.ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE}</li>
|
|
||||||
* <li>{@link org.apache.http.conn.params.ConnManagerPNames#MAX_TOTAL_CONNECTIONS}</li>
|
|
||||||
* <li>{@link org.apache.http.cookie.params.CookieSpecPNames#DATE_PATTERNS}</li>
|
* <li>{@link org.apache.http.cookie.params.CookieSpecPNames#DATE_PATTERNS}</li>
|
||||||
* <li>{@link org.apache.http.cookie.params.CookieSpecPNames#SINGLE_COOKIE_HEADER}</li>
|
* <li>{@link org.apache.http.cookie.params.CookieSpecPNames#SINGLE_COOKIE_HEADER}</li>
|
||||||
* <li>{@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}</li>
|
* <li>{@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}</li>
|
||||||
|
@ -155,7 +153,6 @@ import org.apache.http.util.VersionInfo;
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
public class DefaultHttpClient extends AbstractHttpClient {
|
public class DefaultHttpClient extends AbstractHttpClient {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new HTTP client from parameters and a connection manager.
|
* Creates a new HTTP client from parameters and a connection manager.
|
||||||
*
|
*
|
||||||
|
@ -168,6 +165,15 @@ public class DefaultHttpClient extends AbstractHttpClient {
|
||||||
super(conman, params);
|
super(conman, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
public DefaultHttpClient(
|
||||||
|
final ClientConnectionManager conman) {
|
||||||
|
super(conman, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public DefaultHttpClient(final HttpParams params) {
|
public DefaultHttpClient(final HttpParams params) {
|
||||||
super(null, params);
|
super(null, params);
|
||||||
|
@ -241,7 +247,7 @@ public class DefaultHttpClient extends AbstractHttpClient {
|
||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
connManager = factory.newInstance(params, registry);
|
connManager = factory.newInstance(params, registry);
|
||||||
} else {
|
} else {
|
||||||
connManager = new SingleClientConnManager(getParams(), registry);
|
connManager = new SingleClientConnManager(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return connManager;
|
return connManager;
|
||||||
|
|
|
@ -102,9 +102,21 @@ public class SingleClientConnManager implements ClientConnectionManager {
|
||||||
* @param params the parameters for this manager
|
* @param params the parameters for this manager
|
||||||
* @param schreg the scheme registry, or
|
* @param schreg the scheme registry, or
|
||||||
* <code>null</code> for the default registry
|
* <code>null</code> for the default registry
|
||||||
|
*
|
||||||
|
* @deprecated use {@link SingleClientConnManager#SingleClientConnManager(SchemeRegistry)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public SingleClientConnManager(HttpParams params,
|
public SingleClientConnManager(HttpParams params,
|
||||||
SchemeRegistry schreg) {
|
SchemeRegistry schreg) {
|
||||||
|
this(schreg);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Creates a new simple connection manager.
|
||||||
|
*
|
||||||
|
* @param schreg the scheme registry, or
|
||||||
|
* <code>null</code> for the default registry
|
||||||
|
*/
|
||||||
|
public SingleClientConnManager(final SchemeRegistry schreg) {
|
||||||
if (schreg == null) {
|
if (schreg == null) {
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("Scheme registry must not be null.");
|
("Scheme registry must not be null.");
|
||||||
|
@ -236,8 +248,8 @@ public class SingleClientConnManager implements ClientConnectionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void releaseConnection(
|
public synchronized void releaseConnection(
|
||||||
ManagedClientConnection conn,
|
ManagedClientConnection conn,
|
||||||
long validDuration, TimeUnit timeUnit) {
|
long validDuration, TimeUnit timeUnit) {
|
||||||
assertStillUp();
|
assertStillUp();
|
||||||
|
|
||||||
if (!(conn instanceof ConnAdapter)) {
|
if (!(conn instanceof ConnAdapter)) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ import org.apache.http.impl.conn.IdleConnectionHandler;
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public abstract class AbstractConnPool implements RefQueueHandler {
|
public abstract class AbstractConnPool implements RefQueueHandler {
|
||||||
|
|
||||||
private final Log log = LogFactory.getLog(getClass());
|
private final Log log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global lock for this pool.
|
* The global lock for this pool.
|
||||||
|
@ -95,11 +95,11 @@ public abstract class AbstractConnPool implements RefQueueHandler {
|
||||||
* Creates a new connection pool.
|
* Creates a new connection pool.
|
||||||
*/
|
*/
|
||||||
protected AbstractConnPool() {
|
protected AbstractConnPool() {
|
||||||
leasedConnections = new HashSet<BasicPoolEntry>();
|
super();
|
||||||
idleConnHandler = new IdleConnectionHandler();
|
this.log = LogFactory.getLog(getClass());
|
||||||
|
this.leasedConnections = new HashSet<BasicPoolEntry>();
|
||||||
boolean fair = false; //@@@ check parameters to decide
|
this.idleConnHandler = new IdleConnectionHandler();
|
||||||
poolLock = new ReentrantLock(fair);
|
this.poolLock = new ReentrantLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,6 +37,8 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.annotation.GuardedBy;
|
||||||
|
import org.apache.http.annotation.ThreadSafe;
|
||||||
import org.apache.http.conn.routing.HttpRoute;
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
import org.apache.http.conn.ClientConnectionOperator;
|
import org.apache.http.conn.ClientConnectionOperator;
|
||||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||||
|
@ -60,14 +62,16 @@ import org.apache.http.params.HttpParams;
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
@ThreadSafe
|
||||||
public class ConnPoolByRoute extends AbstractConnPool {
|
public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
|
|
||||||
private final Log log = LogFactory.getLog(getClass());
|
private final Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private final HttpParams params;
|
|
||||||
|
|
||||||
/** Connection operator for this pool */
|
/** Connection operator for this pool */
|
||||||
protected final ClientConnectionOperator operator;
|
protected final ClientConnectionOperator operator;
|
||||||
|
|
||||||
|
/** Connections per route lookup */
|
||||||
|
protected final ConnPerRoute connPerRoute;
|
||||||
|
|
||||||
/** The list of free connections */
|
/** The list of free connections */
|
||||||
protected final Queue<BasicPoolEntry> freeConnections;
|
protected final Queue<BasicPoolEntry> freeConnections;
|
||||||
|
@ -80,24 +84,47 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
* Keys are of class {@link HttpRoute},
|
* Keys are of class {@link HttpRoute},
|
||||||
* values of class {@link RouteSpecificPool}.
|
* values of class {@link RouteSpecificPool}.
|
||||||
*/
|
*/
|
||||||
|
@GuardedBy("poolLock")
|
||||||
protected final Map<HttpRoute, RouteSpecificPool> routeToPool;
|
protected final Map<HttpRoute, RouteSpecificPool> routeToPool;
|
||||||
|
|
||||||
|
@GuardedBy("poolLock")
|
||||||
|
protected volatile int maxTotalConnections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new connection pool, managed by route.
|
* Creates a new connection pool, managed by route.
|
||||||
|
*
|
||||||
|
* @since 4.1
|
||||||
*/
|
*/
|
||||||
public ConnPoolByRoute(final ClientConnectionOperator operator, final HttpParams params) {
|
public ConnPoolByRoute(
|
||||||
|
final ClientConnectionOperator operator,
|
||||||
|
final ConnPerRoute connPerRoute,
|
||||||
|
int maxTotalConnections) {
|
||||||
super();
|
super();
|
||||||
if (operator == null) {
|
if (operator == null) {
|
||||||
throw new IllegalArgumentException("Connection operator may not be null");
|
throw new IllegalArgumentException("Connection operator may not be null");
|
||||||
}
|
}
|
||||||
|
if (connPerRoute == null) {
|
||||||
|
throw new IllegalArgumentException("Connections per route may not be null");
|
||||||
|
}
|
||||||
this.operator = operator;
|
this.operator = operator;
|
||||||
this.params = params;
|
this.connPerRoute = connPerRoute;
|
||||||
|
this.maxTotalConnections = maxTotalConnections;
|
||||||
freeConnections = createFreeConnQueue();
|
this.freeConnections = createFreeConnQueue();
|
||||||
waitingThreads = createWaitingThreadQueue();
|
this.waitingThreads = createWaitingThreadQueue();
|
||||||
routeToPool = createRouteToPoolMap();
|
this.routeToPool = createRouteToPoolMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new connection pool, managed by route.
|
||||||
|
*
|
||||||
|
* @deprecated use {@link ConnPoolByRoute#ConnPoolByRoute(ClientConnectionOperator, ConnPerRoute)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public ConnPoolByRoute(final ClientConnectionOperator operator, final HttpParams params) {
|
||||||
|
this(operator,
|
||||||
|
ConnManagerParams.getMaxConnectionsPerRoute(params),
|
||||||
|
ConnManagerParams.getMaxTotalConnections(params));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the queue for {@link #freeConnections}.
|
* Creates the queue for {@link #freeConnections}.
|
||||||
|
@ -139,8 +166,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
* @return the new pool
|
* @return the new pool
|
||||||
*/
|
*/
|
||||||
protected RouteSpecificPool newRouteSpecificPool(HttpRoute route) {
|
protected RouteSpecificPool newRouteSpecificPool(HttpRoute route) {
|
||||||
ConnPerRoute connPerRoute = ConnManagerParams.getMaxConnectionsPerRoute(params);
|
return new RouteSpecificPool(route, this.connPerRoute.getMaxForRoute(route));
|
||||||
return new RouteSpecificPool(route, connPerRoute.getMaxForRoute(route));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -255,8 +281,6 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
WaitingThreadAborter aborter)
|
WaitingThreadAborter aborter)
|
||||||
throws ConnectionPoolTimeoutException, InterruptedException {
|
throws ConnectionPoolTimeoutException, InterruptedException {
|
||||||
|
|
||||||
int maxTotalConnections = ConnManagerParams.getMaxTotalConnections(params);
|
|
||||||
|
|
||||||
Date deadline = null;
|
Date deadline = null;
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
deadline = new Date
|
deadline = new Date
|
||||||
|
@ -685,6 +709,26 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* since 4.1
|
||||||
|
*/
|
||||||
|
public void setMaxTotalConnections(int max) {
|
||||||
|
poolLock.lock();
|
||||||
|
try {
|
||||||
|
maxTotalConnections = max;
|
||||||
|
} finally {
|
||||||
|
poolLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* since 4.1
|
||||||
|
*/
|
||||||
|
public int getMaxTotalConnections() {
|
||||||
|
return maxTotalConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // class ConnPoolByRoute
|
} // class ConnPoolByRoute
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.annotation.ThreadSafe;
|
||||||
|
import org.apache.http.conn.params.ConnPerRouteBean;
|
||||||
import org.apache.http.conn.routing.HttpRoute;
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
|
@ -57,53 +59,69 @@ import org.apache.http.impl.conn.DefaultClientConnectionOperator;
|
||||||
* these limits may prove too constraining, especially if they use HTTP
|
* these limits may prove too constraining, especially if they use HTTP
|
||||||
* as a transport protocol for their services. Connection limits, however,
|
* as a transport protocol for their services. Connection limits, however,
|
||||||
* can be adjusted using HTTP parameters.
|
* can be adjusted using HTTP parameters.
|
||||||
* <p>
|
|
||||||
* The following parameters can be used to customize the behavior of this
|
|
||||||
* class:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@link org.apache.http.conn.params.ConnManagerPNames#MAX_TOTAL_CONNECTIONS}</li>
|
|
||||||
* <li>{@link org.apache.http.conn.params.ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE}</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @see org.apache.http.conn.params.ConnPerRoute
|
|
||||||
* @see org.apache.http.conn.params.ConnPerRouteBean
|
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
|
@ThreadSafe
|
||||||
public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
||||||
|
|
||||||
private final Log log = LogFactory.getLog(getClass());
|
private final Log log;
|
||||||
|
|
||||||
/** The schemes supported by this connection manager. */
|
/** The schemes supported by this connection manager. */
|
||||||
protected final SchemeRegistry schemeRegistry; // @ThreadSafe
|
protected final SchemeRegistry schemeRegistry; // @ThreadSafe
|
||||||
|
|
||||||
/** The pool of connections being managed. */
|
@Deprecated
|
||||||
protected final AbstractConnPool connectionPool;
|
protected final AbstractConnPool connectionPool;
|
||||||
|
|
||||||
|
/** The pool of connections being managed. */
|
||||||
|
protected final ConnPoolByRoute pool;
|
||||||
|
|
||||||
/** The operator for opening and updating connections. */
|
/** The operator for opening and updating connections. */
|
||||||
protected final ClientConnectionOperator connOperator; // DefaultClientConnectionOperator is @ThreadSafe
|
protected final ClientConnectionOperator connOperator; // DefaultClientConnectionOperator is @ThreadSafe
|
||||||
|
|
||||||
|
protected final ConnPerRouteBean connPerRoute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new thread safe connection manager.
|
* Creates a new thread safe connection manager.
|
||||||
*
|
*
|
||||||
* @param params the parameters for this manager.
|
* @param params the parameters for this manager.
|
||||||
* @param schreg the scheme registry.
|
* @param schreg the scheme registry.
|
||||||
*/
|
*/
|
||||||
public ThreadSafeClientConnManager(HttpParams params,
|
public ThreadSafeClientConnManager(final SchemeRegistry schreg) {
|
||||||
SchemeRegistry schreg) {
|
super();
|
||||||
|
|
||||||
if (params == null) {
|
|
||||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
|
||||||
}
|
|
||||||
if (schreg == null) {
|
if (schreg == null) {
|
||||||
throw new IllegalArgumentException("Scheme registry may not be null");
|
throw new IllegalArgumentException("Scheme registry may not be null");
|
||||||
}
|
}
|
||||||
|
this.log = LogFactory.getLog(getClass());
|
||||||
this.schemeRegistry = schreg;
|
this.schemeRegistry = schreg;
|
||||||
this.connOperator = createConnectionOperator(schreg);
|
this.connPerRoute = new ConnPerRouteBean();
|
||||||
this.connectionPool = createConnectionPool(params);
|
this.connOperator = createConnectionOperator(schreg);
|
||||||
|
this.pool = createConnectionPool() ;
|
||||||
|
this.connectionPool = this.pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new thread safe connection manager.
|
||||||
|
*
|
||||||
|
* @param params the parameters for this manager.
|
||||||
|
* @param schreg the scheme registry.
|
||||||
|
*
|
||||||
|
* @deprecated use {@link ThreadSafeClientConnManager#ThreadSafeClientConnManager(SchemeRegistry)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public ThreadSafeClientConnManager(HttpParams params,
|
||||||
|
SchemeRegistry schreg) {
|
||||||
|
if (schreg == null) {
|
||||||
|
throw new IllegalArgumentException("Scheme registry may not be null");
|
||||||
|
}
|
||||||
|
this.log = LogFactory.getLog(getClass());
|
||||||
|
this.schemeRegistry = schreg;
|
||||||
|
this.connPerRoute = new ConnPerRouteBean();
|
||||||
|
this.connOperator = createConnectionOperator(schreg);
|
||||||
|
this.pool = (ConnPoolByRoute) createConnectionPool(params) ;
|
||||||
|
this.connectionPool = this.pool;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
try {
|
try {
|
||||||
|
@ -117,11 +135,24 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
||||||
* Hook for creating the connection pool.
|
* Hook for creating the connection pool.
|
||||||
*
|
*
|
||||||
* @return the connection pool to use
|
* @return the connection pool to use
|
||||||
|
*
|
||||||
|
* @deprecated use {@link #createConnectionPool(ConnPerRouteBean)}
|
||||||
*/
|
*/
|
||||||
protected AbstractConnPool createConnectionPool(final HttpParams params) {
|
protected AbstractConnPool createConnectionPool(final HttpParams params) {
|
||||||
return new ConnPoolByRoute(connOperator, params);
|
return new ConnPoolByRoute(connOperator, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook for creating the connection pool.
|
||||||
|
*
|
||||||
|
* @return the connection pool to use
|
||||||
|
*
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
protected ConnPoolByRoute createConnectionPool() {
|
||||||
|
return new ConnPoolByRoute(connOperator, connPerRoute, 20);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook for creating the connection operator.
|
* Hook for creating the connection operator.
|
||||||
* It is called by the constructor.
|
* It is called by the constructor.
|
||||||
|
@ -148,7 +179,7 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
||||||
final HttpRoute route,
|
final HttpRoute route,
|
||||||
final Object state) {
|
final Object state) {
|
||||||
|
|
||||||
final PoolEntryRequest poolRequest = connectionPool.requestPoolEntry(
|
final PoolEntryRequest poolRequest = pool.requestPoolEntry(
|
||||||
route, state);
|
route, state);
|
||||||
|
|
||||||
return new ClientConnectionRequest() {
|
return new ClientConnectionRequest() {
|
||||||
|
@ -220,14 +251,14 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
||||||
}
|
}
|
||||||
hca.detach();
|
hca.detach();
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
connectionPool.freeEntry(entry, reusable, validDuration, timeUnit);
|
pool.freeEntry(entry, reusable, validDuration, timeUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
log.debug("Shutting down");
|
log.debug("Shutting down");
|
||||||
connectionPool.shutdown();
|
pool.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,9 +271,8 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
||||||
*
|
*
|
||||||
* @return the total number of pooled connections for that route
|
* @return the total number of pooled connections for that route
|
||||||
*/
|
*/
|
||||||
public int getConnectionsInPool(HttpRoute route) {
|
public int getConnectionsInPool(final HttpRoute route) {
|
||||||
return ((ConnPoolByRoute)connectionPool).getConnectionsInPool(
|
return pool.getConnectionsInPool(route);
|
||||||
route);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -254,25 +284,68 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
||||||
* @return the total number of pooled connections
|
* @return the total number of pooled connections
|
||||||
*/
|
*/
|
||||||
public int getConnectionsInPool() {
|
public int getConnectionsInPool() {
|
||||||
int count;
|
pool.poolLock.lock();
|
||||||
connectionPool.poolLock.lock();
|
try {
|
||||||
count = connectionPool.numConnections; //@@@
|
return pool.numConnections;
|
||||||
connectionPool.poolLock.unlock();
|
} finally {
|
||||||
return count;
|
pool.poolLock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeIdleConnections(long idleTimeout, TimeUnit tunit) {
|
public void closeIdleConnections(long idleTimeout, TimeUnit tunit) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Closing connections idle for " + idleTimeout + " " + tunit);
|
log.debug("Closing connections idle for " + idleTimeout + " " + tunit);
|
||||||
}
|
}
|
||||||
connectionPool.closeIdleConnections(idleTimeout, tunit);
|
pool.closeIdleConnections(idleTimeout, tunit);
|
||||||
connectionPool.deleteClosedConnections();
|
pool.deleteClosedConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeExpiredConnections() {
|
public void closeExpiredConnections() {
|
||||||
log.debug("Closing expired connections");
|
log.debug("Closing expired connections");
|
||||||
connectionPool.closeExpiredConnections();
|
pool.closeExpiredConnections();
|
||||||
connectionPool.deleteClosedConnections();
|
pool.deleteClosedConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* since 4.1
|
||||||
|
*/
|
||||||
|
public int getMaxTotalConnections() {
|
||||||
|
return pool.getMaxTotalConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* since 4.1
|
||||||
|
*/
|
||||||
|
public void setMaxTotalConnections(int max) {
|
||||||
|
pool.setMaxTotalConnections(max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
public int getDefaultMaxPerRoute() {
|
||||||
|
return connPerRoute.getDefaultMaxPerRoute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
public void setDefaultMaxPerRoute(int max) {
|
||||||
|
connPerRoute.setDefaultMaxPerRoute(max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
public int getMaxForRoute(final HttpRoute route) {
|
||||||
|
return connPerRoute.getMaxForRoute(route);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
public void setMaxForRoute(final HttpRoute route, int max) {
|
||||||
|
connPerRoute.setMaxForRoute(route, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,6 @@ import org.apache.http.HttpRequest;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.MalformedChunkCodingException;
|
import org.apache.http.MalformedChunkCodingException;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.conn.routing.HttpRoute;
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
import org.apache.http.entity.BasicHttpEntity;
|
import org.apache.http.entity.BasicHttpEntity;
|
||||||
|
@ -51,7 +49,6 @@ import org.apache.http.impl.DefaultHttpServerConnection;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.localserver.ServerTestBase;
|
import org.apache.http.localserver.ServerTestBase;
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
import org.apache.http.protocol.ExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpRequestHandler;
|
import org.apache.http.protocol.HttpRequestHandler;
|
||||||
|
@ -72,27 +69,21 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
||||||
return new TestSuite(TestConnectionAutoRelease.class);
|
return new TestSuite(TestConnectionAutoRelease.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThreadSafeClientConnManager createTSCCM(HttpParams params,
|
public ThreadSafeClientConnManager createTSCCM(SchemeRegistry schreg) {
|
||||||
SchemeRegistry schreg) {
|
|
||||||
if (params == null)
|
|
||||||
params = defaultParams;
|
|
||||||
if (schreg == null)
|
if (schreg == null)
|
||||||
schreg = supportedSchemes;
|
schreg = supportedSchemes;
|
||||||
return new ThreadSafeClientConnManager(params, schreg);
|
return new ThreadSafeClientConnManager(schreg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReleaseOnEntityConsumeContent() throws Exception {
|
public void testReleaseOnEntityConsumeContent() throws Exception {
|
||||||
HttpParams params = defaultParams.copy();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
(params, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute
|
|
||||||
(params, new ConnPerRouteBean(1));
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
// Zero connections in the pool
|
// Zero connections in the pool
|
||||||
assertEquals(0, mgr.getConnectionsInPool());
|
assertEquals(0, mgr.getConnectionsInPool());
|
||||||
|
|
||||||
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
DefaultHttpClient client = new DefaultHttpClient(mgr);
|
||||||
|
|
||||||
// Get some random data
|
// Get some random data
|
||||||
HttpGet httpget = new HttpGet("/random/20000");
|
HttpGet httpget = new HttpGet("/random/20000");
|
||||||
|
@ -124,17 +115,14 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReleaseOnEntityWriteTo() throws Exception {
|
public void testReleaseOnEntityWriteTo() throws Exception {
|
||||||
HttpParams params = defaultParams.copy();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
(params, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute
|
|
||||||
(params, new ConnPerRouteBean(1));
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
// Zero connections in the pool
|
// Zero connections in the pool
|
||||||
assertEquals(0, mgr.getConnectionsInPool());
|
assertEquals(0, mgr.getConnectionsInPool());
|
||||||
|
|
||||||
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
DefaultHttpClient client = new DefaultHttpClient(mgr);
|
||||||
|
|
||||||
// Get some random data
|
// Get some random data
|
||||||
HttpGet httpget = new HttpGet("/random/20000");
|
HttpGet httpget = new HttpGet("/random/20000");
|
||||||
|
@ -167,17 +155,14 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReleaseOnAbort() throws Exception {
|
public void testReleaseOnAbort() throws Exception {
|
||||||
HttpParams params = defaultParams.copy();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
(params, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute
|
|
||||||
(params, new ConnPerRouteBean(1));
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
// Zero connections in the pool
|
// Zero connections in the pool
|
||||||
assertEquals(0, mgr.getConnectionsInPool());
|
assertEquals(0, mgr.getConnectionsInPool());
|
||||||
|
|
||||||
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
DefaultHttpClient client = new DefaultHttpClient(mgr);
|
||||||
|
|
||||||
// Get some random data
|
// Get some random data
|
||||||
HttpGet httpget = new HttpGet("/random/20000");
|
HttpGet httpget = new HttpGet("/random/20000");
|
||||||
|
@ -242,17 +227,14 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
HttpParams params = defaultParams.copy();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
(params, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute
|
|
||||||
(params, new ConnPerRouteBean(1));
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
// Zero connections in the pool
|
// Zero connections in the pool
|
||||||
assertEquals(0, mgr.getConnectionsInPool());
|
assertEquals(0, mgr.getConnectionsInPool());
|
||||||
|
|
||||||
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
DefaultHttpClient client = new DefaultHttpClient(mgr);
|
||||||
|
|
||||||
// Get some random data
|
// Get some random data
|
||||||
HttpGet httpget = new HttpGet("/dropdead");
|
HttpGet httpget = new HttpGet("/dropdead");
|
||||||
|
|
|
@ -44,8 +44,6 @@ import org.apache.http.HttpResponseInterceptor;
|
||||||
import org.apache.http.HttpVersion;
|
import org.apache.http.HttpVersion;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
|
||||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
@ -110,16 +108,14 @@ public class TestConnectionReuse extends TestCase {
|
||||||
HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
|
HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
|
||||||
HttpProtocolParams.setUseExpectContinue(params, false);
|
HttpProtocolParams.setUseExpectContinue(params, false);
|
||||||
HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 5);
|
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params,
|
|
||||||
new ConnPerRouteBean(5));
|
|
||||||
|
|
||||||
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
||||||
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||||
supportedSchemes.register(new Scheme("http", sf, 80));
|
supportedSchemes.register(new Scheme("http", sf, 80));
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(
|
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||||
params, supportedSchemes);
|
mgr.setMaxTotalConnections(5);
|
||||||
|
mgr.setDefaultMaxPerRoute(5);
|
||||||
|
|
||||||
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
||||||
|
|
||||||
|
@ -182,16 +178,14 @@ public class TestConnectionReuse extends TestCase {
|
||||||
HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
|
HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
|
||||||
HttpProtocolParams.setUseExpectContinue(params, false);
|
HttpProtocolParams.setUseExpectContinue(params, false);
|
||||||
HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 5);
|
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params,
|
|
||||||
new ConnPerRouteBean(5));
|
|
||||||
|
|
||||||
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
||||||
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||||
supportedSchemes.register(new Scheme("http", sf, 80));
|
supportedSchemes.register(new Scheme("http", sf, 80));
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(
|
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||||
params, supportedSchemes);
|
mgr.setMaxTotalConnections(5);
|
||||||
|
mgr.setDefaultMaxPerRoute(5);
|
||||||
|
|
||||||
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
||||||
|
|
||||||
|
@ -244,16 +238,14 @@ public class TestConnectionReuse extends TestCase {
|
||||||
HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
|
HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
|
||||||
HttpProtocolParams.setUseExpectContinue(params, false);
|
HttpProtocolParams.setUseExpectContinue(params, false);
|
||||||
HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 5);
|
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params,
|
|
||||||
new ConnPerRouteBean(5));
|
|
||||||
|
|
||||||
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
||||||
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||||
supportedSchemes.register(new Scheme("http", sf, 80));
|
supportedSchemes.register(new Scheme("http", sf, 80));
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(
|
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||||
params, supportedSchemes);
|
mgr.setMaxTotalConnections(5);
|
||||||
|
mgr.setDefaultMaxPerRoute(5);
|
||||||
|
|
||||||
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
||||||
|
|
||||||
|
@ -307,16 +299,14 @@ public class TestConnectionReuse extends TestCase {
|
||||||
HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
|
HttpProtocolParams.setUserAgent(params, "TestAgent/1.1");
|
||||||
HttpProtocolParams.setUseExpectContinue(params, false);
|
HttpProtocolParams.setUseExpectContinue(params, false);
|
||||||
HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
HttpConnectionParams.setStaleCheckingEnabled(params, false);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 1);
|
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params,
|
|
||||||
new ConnPerRouteBean(1));
|
|
||||||
|
|
||||||
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
||||||
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||||
supportedSchemes.register(new Scheme("http", sf, 80));
|
supportedSchemes.register(new Scheme("http", sf, 80));
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(
|
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||||
params, supportedSchemes);
|
mgr.setMaxTotalConnections(1);
|
||||||
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
|
|
||||||
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
||||||
HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
|
HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
|
||||||
|
|
|
@ -37,9 +37,6 @@ import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
|
|
||||||
/* Don't use Java 6 functionality, even in tests. */
|
|
||||||
//import java.util.zip.DeflaterInputStream;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
|
@ -51,12 +48,10 @@ import org.apache.http.HttpRequestInterceptor;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpResponseInterceptor;
|
import org.apache.http.HttpResponseInterceptor;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.HttpVersion;
|
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.entity.DeflateDecompressingEntity;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.protocol.RequestAcceptEncoding;
|
import org.apache.http.client.protocol.RequestAcceptEncoding;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
@ -64,9 +59,6 @@ import org.apache.http.entity.InputStreamEntity;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.localserver.ServerTestBase;
|
import org.apache.http.localserver.ServerTestBase;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpRequestHandler;
|
import org.apache.http.protocol.HttpRequestHandler;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
@ -192,15 +184,13 @@ public class TestContentCodings extends ServerTestBase {
|
||||||
*/
|
*/
|
||||||
int clients = 100;
|
int clients = 100;
|
||||||
|
|
||||||
HttpParams params = new BasicHttpParams();
|
|
||||||
ConnManagerParams.setMaxTotalConnections(params, clients);
|
|
||||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
|
||||||
|
|
||||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||||
|
|
||||||
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
|
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
|
||||||
final HttpClient httpClient = new DefaultHttpClient(cm, params);
|
cm.setMaxTotalConnections(clients);
|
||||||
|
|
||||||
|
final HttpClient httpClient = new DefaultHttpClient(cm);
|
||||||
|
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(clients);
|
ExecutorService executor = Executors.newFixedThreadPool(clients);
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
||||||
SchemeRegistry registry = new SchemeRegistry();
|
SchemeRegistry registry = new SchemeRegistry();
|
||||||
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||||
|
|
||||||
SingleClientConnManager conMan = new SingleClientConnManager(new BasicHttpParams(), registry);
|
SingleClientConnManager conMan = new SingleClientConnManager(registry);
|
||||||
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
|
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
|
||||||
final CountDownLatch getLatch = new CountDownLatch(1);
|
final CountDownLatch getLatch = new CountDownLatch(1);
|
||||||
final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
|
final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
|
||||||
|
@ -192,7 +192,7 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
||||||
SchemeRegistry registry = new SchemeRegistry();
|
SchemeRegistry registry = new SchemeRegistry();
|
||||||
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||||
|
|
||||||
SingleClientConnManager conMan = new SingleClientConnManager(new BasicHttpParams(), registry);
|
SingleClientConnManager conMan = new SingleClientConnManager(registry);
|
||||||
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
|
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
|
||||||
final CountDownLatch getLatch = new CountDownLatch(1);
|
final CountDownLatch getLatch = new CountDownLatch(1);
|
||||||
final CountDownLatch startLatch = new CountDownLatch(1);
|
final CountDownLatch startLatch = new CountDownLatch(1);
|
||||||
|
@ -240,7 +240,7 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
||||||
|
|
||||||
CountDownLatch connLatch = new CountDownLatch(1);
|
CountDownLatch connLatch = new CountDownLatch(1);
|
||||||
CountDownLatch awaitLatch = new CountDownLatch(1);
|
CountDownLatch awaitLatch = new CountDownLatch(1);
|
||||||
ConnMan4 conMan = new ConnMan4(new BasicHttpParams(), registry, connLatch, awaitLatch);
|
ConnMan4 conMan = new ConnMan4(registry, connLatch, awaitLatch);
|
||||||
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
|
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
|
||||||
final CountDownLatch getLatch = new CountDownLatch(1);
|
final CountDownLatch getLatch = new CountDownLatch(1);
|
||||||
final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
|
final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
|
||||||
|
@ -297,7 +297,7 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
||||||
SchemeRegistry registry = new SchemeRegistry();
|
SchemeRegistry registry = new SchemeRegistry();
|
||||||
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||||
|
|
||||||
ConnMan3 conMan = new ConnMan3(new BasicHttpParams(), registry);
|
ConnMan3 conMan = new ConnMan3(registry);
|
||||||
DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
|
DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
|
||||||
HttpGet httpget = new HttpGet("/a");
|
HttpGet httpget = new HttpGet("/a");
|
||||||
|
|
||||||
|
@ -351,9 +351,9 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
||||||
private final CountDownLatch connLatch;
|
private final CountDownLatch connLatch;
|
||||||
private final CountDownLatch awaitLatch;
|
private final CountDownLatch awaitLatch;
|
||||||
|
|
||||||
public ConnMan4(HttpParams params, SchemeRegistry schreg,
|
public ConnMan4(SchemeRegistry schreg,
|
||||||
CountDownLatch connLatch, CountDownLatch awaitLatch) {
|
CountDownLatch connLatch, CountDownLatch awaitLatch) {
|
||||||
super(params, schreg);
|
super(schreg);
|
||||||
this.connLatch = connLatch;
|
this.connLatch = connLatch;
|
||||||
this.awaitLatch = awaitLatch;
|
this.awaitLatch = awaitLatch;
|
||||||
}
|
}
|
||||||
|
@ -398,8 +398,8 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
||||||
private ManagedClientConnection allocatedConnection;
|
private ManagedClientConnection allocatedConnection;
|
||||||
private ManagedClientConnection releasedConnection;
|
private ManagedClientConnection releasedConnection;
|
||||||
|
|
||||||
public ConnMan3(HttpParams params, SchemeRegistry schreg) {
|
public ConnMan3(SchemeRegistry schreg) {
|
||||||
super(params, schreg);
|
super(schreg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -40,11 +40,11 @@ import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.UserTokenHandler;
|
import org.apache.http.client.UserTokenHandler;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.conn.ManagedClientConnection;
|
import org.apache.http.conn.ManagedClientConnection;
|
||||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
import org.apache.http.conn.params.ConnManagerParams;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.localserver.ServerTestBase;
|
import org.apache.http.localserver.ServerTestBase;
|
||||||
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.protocol.BasicHttpContext;
|
import org.apache.http.protocol.BasicHttpContext;
|
||||||
import org.apache.http.protocol.ExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
|
@ -95,14 +95,13 @@ public class TestStatefulConnManagement extends ServerTestBase {
|
||||||
|
|
||||||
HttpHost target = new HttpHost("localhost", port);
|
HttpHost target = new HttpHost("localhost", port);
|
||||||
|
|
||||||
HttpParams params = defaultParams.copy();
|
HttpParams params = new BasicHttpParams();
|
||||||
ConnManagerParams.setMaxTotalConnections(params, workerCount);
|
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params,
|
|
||||||
new ConnPerRouteBean(workerCount));
|
|
||||||
ConnManagerParams.setTimeout(params, 10L);
|
ConnManagerParams.setTimeout(params, 10L);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(
|
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||||
params, supportedSchemes);
|
mgr.setMaxTotalConnections(workerCount);
|
||||||
|
mgr.setDefaultMaxPerRoute(workerCount);
|
||||||
|
|
||||||
|
|
||||||
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
DefaultHttpClient client = new DefaultHttpClient(mgr, params);
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,10 @@ import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.HttpVersion;
|
import org.apache.http.HttpVersion;
|
||||||
import org.apache.http.conn.ManagedClientConnection;
|
import org.apache.http.conn.ManagedClientConnection;
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.conn.routing.HttpRoute;
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
import org.apache.http.localserver.ServerTestBase;
|
import org.apache.http.localserver.ServerTestBase;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
import org.apache.http.protocol.ExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
@ -72,14 +70,10 @@ public class TestSCMWithServer extends ServerTestBase {
|
||||||
*
|
*
|
||||||
* @return a connection manager to test
|
* @return a connection manager to test
|
||||||
*/
|
*/
|
||||||
public SingleClientConnManager createSCCM(HttpParams params,
|
public SingleClientConnManager createSCCM(SchemeRegistry schreg) {
|
||||||
SchemeRegistry schreg) {
|
|
||||||
if (params == null)
|
|
||||||
params = defaultParams;
|
|
||||||
if (schreg == null)
|
if (schreg == null)
|
||||||
schreg = supportedSchemes;
|
schreg = supportedSchemes;
|
||||||
|
return new SingleClientConnManager(schreg);
|
||||||
return new SingleClientConnManager(params, schreg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,10 +81,7 @@ public class TestSCMWithServer extends ServerTestBase {
|
||||||
* a connection was aborted.
|
* a connection was aborted.
|
||||||
*/
|
*/
|
||||||
public void testOpenAfterAbort() throws Exception {
|
public void testOpenAfterAbort() throws Exception {
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
SingleClientConnManager mgr = createSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
|
||||||
|
|
||||||
SingleClientConnManager mgr = createSCCM(mgrpar, null);
|
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -112,10 +103,7 @@ public class TestSCMWithServer extends ServerTestBase {
|
||||||
*/
|
*/
|
||||||
public void testReleaseConnectionWithTimeLimits() throws Exception {
|
public void testReleaseConnectionWithTimeLimits() throws Exception {
|
||||||
|
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
SingleClientConnManager mgr = createSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
|
||||||
|
|
||||||
SingleClientConnManager mgr = createSCCM(mgrpar, null);
|
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -207,10 +195,7 @@ public class TestSCMWithServer extends ServerTestBase {
|
||||||
|
|
||||||
public void testCloseExpiredConnections() throws Exception {
|
public void testCloseExpiredConnections() throws Exception {
|
||||||
|
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
SingleClientConnManager mgr = createSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
|
||||||
|
|
||||||
SingleClientConnManager mgr = createSCCM(mgrpar, null);
|
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -235,10 +220,7 @@ public class TestSCMWithServer extends ServerTestBase {
|
||||||
|
|
||||||
public void testAlreadyLeased() throws Exception {
|
public void testAlreadyLeased() throws Exception {
|
||||||
|
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
SingleClientConnManager mgr = createSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
|
||||||
|
|
||||||
SingleClientConnManager mgr = createSCCM(mgrpar, null);
|
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
|
|
@ -39,8 +39,6 @@ import org.apache.http.conn.ClientConnectionManager;
|
||||||
import org.apache.http.conn.ClientConnectionRequest;
|
import org.apache.http.conn.ClientConnectionRequest;
|
||||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||||
import org.apache.http.conn.ManagedClientConnection;
|
import org.apache.http.conn.ManagedClientConnection;
|
||||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.conn.routing.HttpRoute;
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
@ -51,7 +49,6 @@ import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
import org.apache.http.params.HttpProtocolParams;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for <code>ThreadSafeClientConnManager</code> that do not require
|
* Tests for <code>ThreadSafeClientConnManager</code> that do not require
|
||||||
* a server to communicate with.
|
* a server to communicate with.
|
||||||
|
@ -98,14 +95,10 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
*
|
*
|
||||||
* @return a connection manager to test
|
* @return a connection manager to test
|
||||||
*/
|
*/
|
||||||
public ThreadSafeClientConnManager createTSCCM(HttpParams params,
|
public ThreadSafeClientConnManager createTSCCM(SchemeRegistry schreg) {
|
||||||
SchemeRegistry schreg) {
|
|
||||||
if (params == null)
|
|
||||||
params = createDefaultParams();
|
|
||||||
if (schreg == null)
|
if (schreg == null)
|
||||||
schreg = createSchemeRegistry();
|
schreg = createSchemeRegistry();
|
||||||
|
return new ThreadSafeClientConnManager(schreg);
|
||||||
return new ThreadSafeClientConnManager(params, schreg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,37 +132,28 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
public void testConstructor() {
|
public void testConstructor() {
|
||||||
HttpParams params = createDefaultParams();
|
|
||||||
SchemeRegistry schreg = createSchemeRegistry();
|
SchemeRegistry schreg = createSchemeRegistry();
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr =
|
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(schreg);
|
||||||
new ThreadSafeClientConnManager(params, schreg);
|
|
||||||
assertNotNull(mgr);
|
assertNotNull(mgr);
|
||||||
mgr.shutdown();
|
mgr.shutdown();
|
||||||
mgr = null;
|
mgr = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mgr = new ThreadSafeClientConnManager(null, schreg);
|
mgr = new ThreadSafeClientConnManager(null);
|
||||||
fail("null parameters not detected");
|
fail("null parameter not detected");
|
||||||
} catch (IllegalArgumentException iax) {
|
} catch (IllegalArgumentException iax) {
|
||||||
// expected
|
// expected
|
||||||
} finally {
|
} finally {
|
||||||
if (mgr != null)
|
if (mgr != null)
|
||||||
mgr.shutdown();
|
mgr.shutdown();
|
||||||
}
|
}
|
||||||
mgr = null;
|
|
||||||
|
|
||||||
mgr = new ThreadSafeClientConnManager(params, schreg);
|
|
||||||
assertNotNull(mgr);
|
|
||||||
mgr.shutdown();
|
|
||||||
mgr = null;
|
|
||||||
|
|
||||||
} // testConstructor
|
} // testConstructor
|
||||||
|
|
||||||
|
|
||||||
public void testGetConnection()
|
public void testGetConnection()
|
||||||
throws InterruptedException, ConnectionPoolTimeoutException {
|
throws InterruptedException, ConnectionPoolTimeoutException {
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(null, null);
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
|
|
||||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||||
HttpRoute route = new HttpRoute(target, null, false);
|
HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -198,11 +182,9 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
public void testMaxConnTotal()
|
public void testMaxConnTotal()
|
||||||
throws InterruptedException, ConnectionPoolTimeoutException {
|
throws InterruptedException, ConnectionPoolTimeoutException {
|
||||||
|
|
||||||
HttpParams params = createDefaultParams();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(1));
|
mgr.setMaxTotalConnections(2);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 2);
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
HttpHost target1 = new HttpHost("www.test1.invalid", 80, "http");
|
HttpHost target1 = new HttpHost("www.test1.invalid", 80, "http");
|
||||||
HttpRoute route1 = new HttpRoute(target1, null, false);
|
HttpRoute route1 = new HttpRoute(target1, null, false);
|
||||||
|
@ -247,16 +229,11 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
HttpHost target3 = new HttpHost("www.test3.invalid", 80, "http");
|
HttpHost target3 = new HttpHost("www.test3.invalid", 80, "http");
|
||||||
HttpRoute route3 = new HttpRoute(target3, null, false);
|
HttpRoute route3 = new HttpRoute(target3, null, false);
|
||||||
|
|
||||||
HttpParams params = createDefaultParams();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 100);
|
mgr.setMaxTotalConnections(100);
|
||||||
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(1);
|
mgr.setMaxForRoute(route2, 2);
|
||||||
connPerRoute.setMaxForRoute(route2, 2);
|
mgr.setMaxForRoute(route3, 3);
|
||||||
connPerRoute.setMaxForRoute(route3, 3);
|
|
||||||
|
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
|
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
// route 3, limit 3
|
// route 3, limit 3
|
||||||
ManagedClientConnection conn1 =
|
ManagedClientConnection conn1 =
|
||||||
|
@ -318,11 +295,9 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
|
|
||||||
public void testReleaseConnection() throws Exception {
|
public void testReleaseConnection() throws Exception {
|
||||||
|
|
||||||
HttpParams params = createDefaultParams();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(1));
|
mgr.setMaxTotalConnections(3);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 3);
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
HttpHost target1 = new HttpHost("www.test1.invalid", 80, "http");
|
HttpHost target1 = new HttpHost("www.test1.invalid", 80, "http");
|
||||||
HttpRoute route1 = new HttpRoute(target1, null, false);
|
HttpRoute route1 = new HttpRoute(target1, null, false);
|
||||||
|
@ -389,7 +364,7 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
public void testDeleteClosedConnections()
|
public void testDeleteClosedConnections()
|
||||||
throws InterruptedException, ConnectionPoolTimeoutException {
|
throws InterruptedException, ConnectionPoolTimeoutException {
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(null, null);
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
|
|
||||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||||
HttpRoute route = new HttpRoute(target, null, false);
|
HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -421,11 +396,9 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
public void testShutdown() throws Exception {
|
public void testShutdown() throws Exception {
|
||||||
// 3.x: TestHttpConnectionManager.testShutdown
|
// 3.x: TestHttpConnectionManager.testShutdown
|
||||||
|
|
||||||
HttpParams params = createDefaultParams();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(1));
|
mgr.setMaxTotalConnections(1);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 1);
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||||
HttpRoute route = new HttpRoute(target, null, false);
|
HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -469,10 +442,8 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
public void testInterruptThread() throws Exception {
|
public void testInterruptThread() throws Exception {
|
||||||
// 3.x: TestHttpConnectionManager.testWaitingThreadInterrupted
|
// 3.x: TestHttpConnectionManager.testWaitingThreadInterrupted
|
||||||
|
|
||||||
HttpParams params = createDefaultParams();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||||
HttpRoute route = new HttpRoute(target, null, false);
|
HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -517,10 +488,8 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
public void testReusePreference() throws Exception {
|
public void testReusePreference() throws Exception {
|
||||||
// 3.x: TestHttpConnectionManager.testHostReusePreference
|
// 3.x: TestHttpConnectionManager.testHostReusePreference
|
||||||
|
|
||||||
HttpParams params = createDefaultParams();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
HttpHost target1 = new HttpHost("www.test1.invalid", 80, "http");
|
HttpHost target1 = new HttpHost("www.test1.invalid", 80, "http");
|
||||||
HttpRoute route1 = new HttpRoute(target1, null, false);
|
HttpRoute route1 = new HttpRoute(target1, null, false);
|
||||||
|
@ -557,10 +526,8 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAbortAfterRequestStarts() throws Exception {
|
public void testAbortAfterRequestStarts() throws Exception {
|
||||||
HttpParams params = createDefaultParams();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||||
HttpRoute route = new HttpRoute(target, null, false);
|
HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -598,15 +565,12 @@ public class TestTSCCMNoServer extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAbortBeforeRequestStarts() throws Exception {
|
public void testAbortBeforeRequestStarts() throws Exception {
|
||||||
HttpParams params = createDefaultParams();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(params, null);
|
|
||||||
|
|
||||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||||
HttpRoute route = new HttpRoute(target, null, false);
|
HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
|
||||||
|
|
||||||
// get the only connection, then start an extra thread
|
// get the only connection, then start an extra thread
|
||||||
ManagedClientConnection conn = getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
|
ManagedClientConnection conn = getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
|
||||||
ClientConnectionRequest request = mgr.requestConnection(route, null);
|
ClientConnectionRequest request = mgr.requestConnection(route, null);
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
package org.apache.http.impl.conn;
|
package org.apache.http.impl.conn;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
@ -53,8 +52,6 @@ import org.apache.http.conn.ConnectTimeoutException;
|
||||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||||
import org.apache.http.conn.ManagedClientConnection;
|
import org.apache.http.conn.ManagedClientConnection;
|
||||||
import org.apache.http.conn.OperatedClientConnection;
|
import org.apache.http.conn.OperatedClientConnection;
|
||||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.conn.routing.HttpRoute;
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
@ -69,7 +66,6 @@ import org.apache.http.protocol.ExecutionContext;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for <code>ThreadSafeClientConnManager</code> that do require
|
* Tests for <code>ThreadSafeClientConnManager</code> that do require
|
||||||
* a server to communicate with.
|
* a server to communicate with.
|
||||||
|
@ -114,14 +110,10 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
*
|
*
|
||||||
* @return a connection manager to test
|
* @return a connection manager to test
|
||||||
*/
|
*/
|
||||||
public ThreadSafeClientConnManager createTSCCM(HttpParams params,
|
public ThreadSafeClientConnManager createTSCCM(SchemeRegistry schreg) {
|
||||||
SchemeRegistry schreg) {
|
|
||||||
if (params == null)
|
|
||||||
params = defaultParams;
|
|
||||||
if (schreg == null)
|
if (schreg == null)
|
||||||
schreg = supportedSchemes;
|
schreg = supportedSchemes;
|
||||||
|
return new ThreadSafeClientConnManager(schreg);
|
||||||
return new ThreadSafeClientConnManager(params, schreg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,12 +126,9 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
|
|
||||||
final int COUNT = 8; // adjust to execute more requests
|
final int COUNT = 8; // adjust to execute more requests
|
||||||
|
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections
|
mgr.setMaxTotalConnections(COUNT/2);
|
||||||
(mgrpar, COUNT/2);
|
mgr.setDefaultMaxPerRoute(COUNT/2);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute
|
|
||||||
(mgrpar, new ConnPerRouteBean(COUNT/2));
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, null);
|
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -209,10 +198,8 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
*/
|
*/
|
||||||
public void testReleaseConnection() throws Exception {
|
public void testReleaseConnection() throws Exception {
|
||||||
|
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, null);
|
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -296,10 +283,8 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
*/
|
*/
|
||||||
public void testReleaseConnectionWithTimeLimits() throws Exception {
|
public void testReleaseConnectionWithTimeLimits() throws Exception {
|
||||||
|
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, null);
|
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -400,10 +385,8 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
|
|
||||||
public void testCloseExpiredConnections() throws Exception {
|
public void testCloseExpiredConnections() throws Exception {
|
||||||
|
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, null);
|
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -443,10 +426,8 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
*/
|
*/
|
||||||
public void testReleaseConnectionOnAbort() throws Exception {
|
public void testReleaseConnectionOnAbort() throws Exception {
|
||||||
|
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, null);
|
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -495,7 +476,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
public void testConnectionManagerGC() throws Exception {
|
public void testConnectionManagerGC() throws Exception {
|
||||||
// 3.x: TestHttpConnectionManager.testDroppedThread
|
// 3.x: TestHttpConnectionManager.testDroppedThread
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(null, null);
|
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -539,16 +520,14 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAbortDuringConnecting() throws Exception {
|
public void testAbortDuringConnecting() throws Exception {
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
|
||||||
|
|
||||||
final CountDownLatch connectLatch = new CountDownLatch(1);
|
final CountDownLatch connectLatch = new CountDownLatch(1);
|
||||||
final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(connectLatch, WaitPolicy.BEFORE_CONNECT, PlainSocketFactory.getSocketFactory());
|
final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(connectLatch, WaitPolicy.BEFORE_CONNECT, PlainSocketFactory.getSocketFactory());
|
||||||
Scheme scheme = new Scheme("http", stallingSocketFactory, 80);
|
Scheme scheme = new Scheme("http", stallingSocketFactory, 80);
|
||||||
SchemeRegistry registry = new SchemeRegistry();
|
SchemeRegistry registry = new SchemeRegistry();
|
||||||
registry.register(scheme);
|
registry.register(scheme);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, registry);
|
ThreadSafeClientConnManager mgr = createTSCCM(registry);
|
||||||
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -603,16 +582,14 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAbortBeforeSocketCreate() throws Exception {
|
public void testAbortBeforeSocketCreate() throws Exception {
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
|
||||||
|
|
||||||
final CountDownLatch connectLatch = new CountDownLatch(1);
|
final CountDownLatch connectLatch = new CountDownLatch(1);
|
||||||
final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(connectLatch, WaitPolicy.BEFORE_CREATE, PlainSocketFactory.getSocketFactory());
|
final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(connectLatch, WaitPolicy.BEFORE_CREATE, PlainSocketFactory.getSocketFactory());
|
||||||
Scheme scheme = new Scheme("http", stallingSocketFactory, 80);
|
Scheme scheme = new Scheme("http", stallingSocketFactory, 80);
|
||||||
SchemeRegistry registry = new SchemeRegistry();
|
SchemeRegistry registry = new SchemeRegistry();
|
||||||
registry.register(scheme);
|
registry.register(scheme);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, registry);
|
ThreadSafeClientConnManager mgr = createTSCCM(registry);
|
||||||
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -669,16 +646,14 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAbortAfterSocketConnect() throws Exception {
|
public void testAbortAfterSocketConnect() throws Exception {
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
|
||||||
|
|
||||||
final CountDownLatch connectLatch = new CountDownLatch(1);
|
final CountDownLatch connectLatch = new CountDownLatch(1);
|
||||||
final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(connectLatch, WaitPolicy.AFTER_CONNECT, PlainSocketFactory.getSocketFactory());
|
final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(connectLatch, WaitPolicy.AFTER_CONNECT, PlainSocketFactory.getSocketFactory());
|
||||||
Scheme scheme = new Scheme("http", stallingSocketFactory, 80);
|
Scheme scheme = new Scheme("http", stallingSocketFactory, 80);
|
||||||
SchemeRegistry registry = new SchemeRegistry();
|
SchemeRegistry registry = new SchemeRegistry();
|
||||||
registry.register(scheme);
|
registry.register(scheme);
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = createTSCCM(mgrpar, registry);
|
ThreadSafeClientConnManager mgr = createTSCCM(registry);
|
||||||
|
mgr.setMaxTotalConnections(1);
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
final HttpRoute route = new HttpRoute(target, null, false);
|
final HttpRoute route = new HttpRoute(target, null, false);
|
||||||
|
@ -740,13 +715,10 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAbortAfterOperatorOpen() throws Exception {
|
public void testAbortAfterOperatorOpen() throws Exception {
|
||||||
HttpParams mgrpar = defaultParams.copy();
|
|
||||||
ConnManagerParams.setMaxTotalConnections(mgrpar, 1);
|
|
||||||
|
|
||||||
final CountDownLatch connectLatch = new CountDownLatch(1);
|
final CountDownLatch connectLatch = new CountDownLatch(1);
|
||||||
final AtomicReference<StallingOperator> operatorRef = new AtomicReference<StallingOperator>();
|
final AtomicReference<StallingOperator> operatorRef = new AtomicReference<StallingOperator>();
|
||||||
|
|
||||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(mgrpar, supportedSchemes) {
|
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes) {
|
||||||
@Override
|
@Override
|
||||||
protected ClientConnectionOperator createConnectionOperator(
|
protected ClientConnectionOperator createConnectionOperator(
|
||||||
SchemeRegistry schreg) {
|
SchemeRegistry schreg) {
|
||||||
|
@ -754,6 +726,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
||||||
return operatorRef.get();
|
return operatorRef.get();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
mgr.setMaxTotalConnections(1);
|
||||||
assertNotNull(operatorRef.get());
|
assertNotNull(operatorRef.get());
|
||||||
|
|
||||||
final HttpHost target = getServerHttp();
|
final HttpHost target = getServerHttp();
|
||||||
|
|
|
@ -36,11 +36,9 @@ import org.apache.http.HttpHost;
|
||||||
import org.apache.http.conn.ClientConnectionOperator;
|
import org.apache.http.conn.ClientConnectionOperator;
|
||||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
import org.apache.http.conn.params.ConnPerRouteBean;
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.conn.routing.HttpRoute;
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
import org.apache.http.impl.conn.DefaultClientConnectionOperator;
|
import org.apache.http.impl.conn.DefaultClientConnectionOperator;
|
||||||
import org.apache.http.localserver.ServerTestBase;
|
import org.apache.http.localserver.ServerTestBase;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
|
||||||
|
|
||||||
public class TestConnPoolByRoute extends ServerTestBase {
|
public class TestConnPoolByRoute extends ServerTestBase {
|
||||||
|
|
||||||
|
@ -64,11 +62,8 @@ public class TestConnPoolByRoute extends ServerTestBase {
|
||||||
ClientConnectionOperator operator = new DefaultClientConnectionOperator(
|
ClientConnectionOperator operator = new DefaultClientConnectionOperator(
|
||||||
supportedSchemes);
|
supportedSchemes);
|
||||||
|
|
||||||
BasicHttpParams params = new BasicHttpParams();
|
|
||||||
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
|
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
|
ConnPoolByRoute connPool = new ConnPoolByRoute(operator, connPerRoute, 20);
|
||||||
|
|
||||||
ConnPoolByRoute connPool = new ConnPoolByRoute(operator, params);
|
|
||||||
try {
|
try {
|
||||||
// Allocate max possible entries
|
// Allocate max possible entries
|
||||||
PoolEntryRequest r1 = connPool.requestPoolEntry(route, null);
|
PoolEntryRequest r1 = connPool.requestPoolEntry(route, null);
|
||||||
|
@ -111,11 +106,8 @@ public class TestConnPoolByRoute extends ServerTestBase {
|
||||||
ClientConnectionOperator operator = new DefaultClientConnectionOperator(
|
ClientConnectionOperator operator = new DefaultClientConnectionOperator(
|
||||||
supportedSchemes);
|
supportedSchemes);
|
||||||
|
|
||||||
BasicHttpParams params = new BasicHttpParams();
|
|
||||||
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
|
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(3);
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
|
ConnPoolByRoute connPool = new ConnPoolByRoute(operator, connPerRoute, 20);
|
||||||
|
|
||||||
ConnPoolByRoute connPool = new ConnPoolByRoute(operator, params);
|
|
||||||
try {
|
try {
|
||||||
// Allocate max possible entries
|
// Allocate max possible entries
|
||||||
PoolEntryRequest r1 = connPool.requestPoolEntry(route, null);
|
PoolEntryRequest r1 = connPool.requestPoolEntry(route, null);
|
||||||
|
|
|
@ -35,7 +35,6 @@ import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.HttpVersion;
|
|
||||||
import org.apache.http.conn.ClientConnectionOperator;
|
import org.apache.http.conn.ClientConnectionOperator;
|
||||||
import org.apache.http.conn.ClientConnectionRequest;
|
import org.apache.http.conn.ClientConnectionRequest;
|
||||||
import org.apache.http.conn.ManagedClientConnection;
|
import org.apache.http.conn.ManagedClientConnection;
|
||||||
|
@ -44,17 +43,10 @@ import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
import org.apache.http.conn.scheme.Scheme;
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
import org.apache.http.conn.scheme.SocketFactory;
|
import org.apache.http.conn.scheme.SocketFactory;
|
||||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
import org.apache.http.conn.params.ConnPerRoute;
|
||||||
import org.apache.http.conn.params.ConnManagerParams;
|
|
||||||
import org.apache.http.params.BasicHttpParams;
|
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
|
||||||
|
|
||||||
// test imports
|
|
||||||
import org.apache.http.impl.conn.GetConnThread;
|
import org.apache.http.impl.conn.GetConnThread;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for spurious wakeups in <code>WaitingThread</code>.
|
* Tests for spurious wakeups in <code>WaitingThread</code>.
|
||||||
* Requires some wrapping code to get at the lock and condition,
|
* Requires some wrapping code to get at the lock and condition,
|
||||||
|
@ -93,8 +85,11 @@ public class TestSpuriousWakeup extends TestCase {
|
||||||
protected WaitingThread newestWT;
|
protected WaitingThread newestWT;
|
||||||
|
|
||||||
|
|
||||||
public XConnPoolByRoute(ClientConnectionOperator operator, HttpParams params) {
|
public XConnPoolByRoute(
|
||||||
super(operator, params);
|
final ClientConnectionOperator operator,
|
||||||
|
final ConnPerRoute connPerRoute,
|
||||||
|
int maxTotalConnections) {
|
||||||
|
super(operator, connPerRoute, maxTotalConnections);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,13 +113,13 @@ public class TestSpuriousWakeup extends TestCase {
|
||||||
protected XConnPoolByRoute extendedCPBR;
|
protected XConnPoolByRoute extendedCPBR;
|
||||||
|
|
||||||
|
|
||||||
public XTSCCM(HttpParams params, SchemeRegistry schreg) {
|
public XTSCCM(SchemeRegistry schreg) {
|
||||||
super(params, schreg);
|
super(schreg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractConnPool createConnectionPool(HttpParams params) {
|
protected ConnPoolByRoute createConnectionPool() {
|
||||||
extendedCPBR = new XConnPoolByRoute(connOperator, params);
|
extendedCPBR = new XConnPoolByRoute(connOperator, connPerRoute, 20);
|
||||||
// no connection GC required
|
// no connection GC required
|
||||||
return extendedCPBR;
|
return extendedCPBR;
|
||||||
}
|
}
|
||||||
|
@ -134,21 +129,15 @@ public class TestSpuriousWakeup extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
public void testSpuriousWakeup() throws Exception {
|
public void testSpuriousWakeup() throws Exception {
|
||||||
|
|
||||||
// parameters with connection limit 1
|
|
||||||
HttpParams params = new BasicHttpParams();
|
|
||||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
|
||||||
HttpProtocolParams.setUseExpectContinue(params, false);
|
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(1));
|
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 1);
|
|
||||||
|
|
||||||
SchemeRegistry schreg = new SchemeRegistry();
|
SchemeRegistry schreg = new SchemeRegistry();
|
||||||
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
SocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||||
schreg.register(new Scheme("http", sf, 80));
|
schreg.register(new Scheme("http", sf, 80));
|
||||||
|
|
||||||
XTSCCM mgr = new XTSCCM(params, schreg);
|
XTSCCM mgr = new XTSCCM(schreg);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
mgr.setMaxTotalConnections(1);
|
||||||
|
mgr.setDefaultMaxPerRoute(1);
|
||||||
|
|
||||||
// take out the only connection
|
// take out the only connection
|
||||||
ClientConnectionRequest connRequest = mgr.requestConnection(ROUTE, null);
|
ClientConnectionRequest connRequest = mgr.requestConnection(ROUTE, null);
|
||||||
ManagedClientConnection conn = connRequest.getConnection(0, null);
|
ManagedClientConnection conn = connRequest.getConnection(0, null);
|
||||||
|
|
|
@ -459,12 +459,10 @@ httpclient.setRoutePlanner(new HttpRoutePlanner() {
|
||||||
unintentionally.</para>
|
unintentionally.</para>
|
||||||
<para>This is an example of acquiring a connection from a connection manager:</para>
|
<para>This is an example of acquiring a connection from a connection manager:</para>
|
||||||
<programlisting><![CDATA[
|
<programlisting><![CDATA[
|
||||||
HttpParams params = new BasicHttpParams();
|
|
||||||
Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
|
Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
|
||||||
SchemeRegistry sr = new SchemeRegistry();
|
SchemeRegistry sr = new SchemeRegistry();
|
||||||
sr.register(http);
|
sr.register(http);
|
||||||
|
ClientConnectionManager connMrg = new SingleClientConnManager(sr);
|
||||||
ClientConnectionManager connMrg = new SingleClientConnManager(params, sr);
|
|
||||||
|
|
||||||
// Request new connection. This can be a long process
|
// Request new connection. This can be a long process
|
||||||
ClientConnectionRequest connRequest = connMrg.requestConnection(
|
ClientConnectionRequest connRequest = connMrg.requestConnection(
|
||||||
|
@ -546,24 +544,22 @@ try {
|
||||||
services. Connection limits, however, can be adjusted using HTTP parameters.</para>
|
services. Connection limits, however, can be adjusted using HTTP parameters.</para>
|
||||||
<para>This example shows how the connection pool parameters can be adjusted:</para>
|
<para>This example shows how the connection pool parameters can be adjusted:</para>
|
||||||
<programlisting><![CDATA[
|
<programlisting><![CDATA[
|
||||||
HttpParams params = new BasicHttpParams();
|
|
||||||
// Increase max total connection to 200
|
|
||||||
ConnManagerParams.setMaxTotalConnections(params, 200);
|
|
||||||
// Increase default max connection per route to 20
|
|
||||||
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(20);
|
|
||||||
// Increase max connections for localhost:80 to 50
|
|
||||||
HttpHost localhost = new HttpHost("locahost", 80);
|
|
||||||
connPerRoute.setMaxForRoute(new HttpRoute(localhost), 50);
|
|
||||||
ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
|
|
||||||
|
|
||||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
schemeRegistry.register(
|
schemeRegistry.register(
|
||||||
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||||
schemeRegistry.register(
|
schemeRegistry.register(
|
||||||
new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
||||||
|
|
||||||
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
|
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
|
||||||
HttpClient httpClient = new DefaultHttpClient(cm, params);
|
// Increase max total connection to 200
|
||||||
|
cm.setMaxTotalConnections(200);
|
||||||
|
// Increase default max connection per route to 20
|
||||||
|
cm.setDefaultMaxPerRoute(20);
|
||||||
|
// Increase max connections for localhost:80 to 50
|
||||||
|
HttpHost localhost = new HttpHost("locahost", 80);
|
||||||
|
cm.setMaxForRoute(new HttpRoute(localhost), 50);
|
||||||
|
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(cm);
|
||||||
]]></programlisting>
|
]]></programlisting>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
|
@ -601,24 +597,6 @@ httpclient.getConnectionManager().shutdown();
|
||||||
timeout).</para>
|
timeout).</para>
|
||||||
</formalpara>
|
</formalpara>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
|
||||||
<formalpara>
|
|
||||||
<title>'http.conn-manager.max-per-route':</title>
|
|
||||||
<para>defines the maximum number of connections per route. This limit is
|
|
||||||
interpreted by client connection managers and applies to individual manager
|
|
||||||
instances. This parameter expects a value of type
|
|
||||||
<interfacename>ConnPerRoute</interfacename>.</para>
|
|
||||||
</formalpara>
|
|
||||||
</listitem>
|
|
||||||
<listitem>
|
|
||||||
<formalpara>
|
|
||||||
<title>'http.conn-manager.max-total':</title>
|
|
||||||
<para>defines the maximum number of connections in total. This limit is
|
|
||||||
interpreted by client connection managers and applies to individual manager
|
|
||||||
instances. This parameter expects a value of type
|
|
||||||
<classname>java.lang.Integer</classname>.</para>
|
|
||||||
</formalpara>
|
|
||||||
</listitem>
|
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
|
@ -634,13 +612,12 @@ httpclient.getConnectionManager().shutdown();
|
||||||
If the connection request cannot be serviced within the given time period
|
If the connection request cannot be serviced within the given time period
|
||||||
<exceptionname>ConnectionPoolTimeoutException</exceptionname> will be thrown.</para>
|
<exceptionname>ConnectionPoolTimeoutException</exceptionname> will be thrown.</para>
|
||||||
<programlisting><![CDATA[
|
<programlisting><![CDATA[
|
||||||
HttpParams params = new BasicHttpParams();
|
|
||||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
schemeRegistry.register(
|
schemeRegistry.register(
|
||||||
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||||
|
|
||||||
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
|
ClientConnectionManager cm = new ThreadSafeClientConnManager(schemeRegistry);
|
||||||
HttpClient httpClient = new DefaultHttpClient(cm, params);
|
HttpClient httpClient = new DefaultHttpClient(cm);
|
||||||
|
|
||||||
// URIs to perform GETs on
|
// URIs to perform GETs on
|
||||||
String[] urisToGet = {
|
String[] urisToGet = {
|
||||||
|
|
Loading…
Reference in New Issue