diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnConnectionPNames.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnConnectionPNames.java index f7d050f32..ad68faa20 100644 --- a/httpclient/src/main/java/org/apache/http/conn/params/ConnConnectionPNames.java +++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnConnectionPNames.java @@ -30,17 +30,13 @@ package org.apache.http.conn.params; - /** - * Parameter names for connections in HttpConn. - * - * @version $Revision$ + * Parameter names for HTTP client connections. * * @since 4.0 */ public interface ConnConnectionPNames { - /** * Defines the maximum number of ignorable lines before we expect * a HTTP response's status line. diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerPNames.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerPNames.java index 08fd92ca5..94155a05b 100644 --- a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerPNames.java +++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerPNames.java @@ -30,11 +30,8 @@ package org.apache.http.conn.params; - /** * Parameter names for connection managers in HttpConn. - * - * @version $Revision$ * * @since 4.0 */ diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParams.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParams.java index 1de36f0c6..35e0f5d7c 100644 --- a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParams.java +++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParams.java @@ -40,9 +40,6 @@ import org.apache.http.params.HttpParams; * to client-side * {@link org.apache.http.conn.ClientConnectionManager connection managers}. * - * - * @version $Revision$ - * * @since 4.0 * * @see ConnManagerPNames diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRoute.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRoute.java index 74acab731..d01a4b798 100644 --- a/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRoute.java +++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRoute.java @@ -34,13 +34,10 @@ import org.apache.http.conn.routing.HttpRoute; /** * This interface is intended for looking up maximum number of connections - * allowed for for a given route. This class can be used by pooling + * allowed for a given route. This class can be used by pooling * {@link org.apache.http.conn.ClientConnectionManager connection managers} for * a fine-grained control of connections on a per route basis. * - * - * @version $Revision$ - * * @since 4.0 */ public interface ConnPerRoute { diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java index a800566fd..f58d6188a 100644 --- a/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java +++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java @@ -43,9 +43,6 @@ import org.apache.http.conn.routing.HttpRoute; * {@link org.apache.http.conn.ClientConnectionManager connection managers} for * a fine-grained control of connections on a per route basis. * - * - * @version $Revision$ - * * @since 4.0 */ @NotThreadSafe // maxPerHostMap and defaultMax @@ -112,5 +109,10 @@ public final class ConnPerRouteBean implements ConnPerRoute { this.maxPerHostMap.clear(); this.maxPerHostMap.putAll(map); } + + @Override + public String toString() { + return this.maxPerHostMap.toString(); + } } diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java index 99cfec7b2..2ee85ba29 100644 --- a/httpclient/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java +++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java @@ -33,8 +33,6 @@ package org.apache.http.conn.params; /** * Parameter names for routing in HttpConn. * - * @version $Revision$ - * * @since 4.0 */ public interface ConnRoutePNames { @@ -50,7 +48,6 @@ public interface ConnRoutePNames { */ public static final String DEFAULT_PROXY = "http.route.default-proxy"; - /** * Parameter for the local address. * On machines with multiple network interfaces, this parameter @@ -65,7 +62,6 @@ public interface ConnRoutePNames { */ public static final String LOCAL_ADDRESS = "http.route.local-address"; - /** * Parameter for an forced route. * The forced route will be interpreted by the standard diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParams.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParams.java index 9f882a723..2a3e3790e 100644 --- a/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParams.java +++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParams.java @@ -30,7 +30,6 @@ package org.apache.http.conn.params; - import java.net.InetAddress; import net.jcip.annotations.Immutable; @@ -39,15 +38,10 @@ import org.apache.http.HttpHost; import org.apache.http.params.HttpParams; import org.apache.http.conn.routing.HttpRoute; - - /** * An adaptor for accessing route related parameters in {@link HttpParams}. * See {@link ConnRoutePNames} for parameter name definitions. * - * - * @version $Revision$ - * * @since 4.0 */ @Immutable @@ -67,13 +61,11 @@ public class ConnRouteParams implements ConnRoutePNames { */ public static final HttpRoute NO_ROUTE = new HttpRoute(NO_HOST); // Immutable - /** Disabled default constructor. */ private ConnRouteParams() { // no body } - /** * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} * parameter value. @@ -98,7 +90,6 @@ public class ConnRouteParams implements ConnRoutePNames { return proxy; } - /** * Sets the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} * parameter value. @@ -117,7 +108,6 @@ public class ConnRouteParams implements ConnRoutePNames { params.setParameter(DEFAULT_PROXY, proxy); } - /** * Obtains the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE} * parameter value. @@ -142,7 +132,6 @@ public class ConnRouteParams implements ConnRoutePNames { return route; } - /** * Sets the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE} * parameter value. @@ -161,7 +150,6 @@ public class ConnRouteParams implements ConnRoutePNames { params.setParameter(FORCED_ROUTE, route); } - /** * Obtains the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS} * parameter value. @@ -184,7 +172,6 @@ public class ConnRouteParams implements ConnRoutePNames { return local; } - /** * Sets the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS} * parameter value. diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java index 64b878f9c..47e32ab0c 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnection.java @@ -56,9 +56,11 @@ import org.apache.http.conn.OperatedClientConnection; * The following parameters can be used to customize the behavior of this * class: * * * @since 4.0 @@ -223,7 +225,10 @@ public class DefaultClientConnection extends SocketHttpClientConnection @Override public HttpResponse receiveResponseHeader() throws HttpException, IOException { - HttpResponse response = super.receiveResponseHeader(); + HttpResponse response = super.receiveResponseHeader(); + if (log.isDebugEnabled()) { + log.debug("Receiving response: " + response.getStatusLine()); + } if (headerLog.isDebugEnabled()) { headerLog.debug("<< " + response.getStatusLine().toString()); Header[] headers = response.getAllHeaders(); @@ -236,6 +241,9 @@ public class DefaultClientConnection extends SocketHttpClientConnection @Override public void sendRequestHeader(HttpRequest request) throws HttpException, IOException { + if (log.isDebugEnabled()) { + log.debug("Sending request: " + request.getRequestLine()); + } super.sendRequestHeader(request); if (headerLog.isDebugEnabled()) { headerLog.debug(">> " + request.getRequestLine().toString()); diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java b/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java index e4572fb33..c5a41fa09 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java @@ -58,18 +58,17 @@ import org.apache.http.params.HttpParams; *
  • connections are re-used only for the exact same route
  • *
  • connection limits are enforced per route rather than per host
  • * - * Note that access to the pool datastructures is synchronized via the + * Note that access to the pool data structures is synchronized via the * {@link AbstractConnPool#poolLock poolLock} in the base class, * not via synchronized methods. * - * * @since 4.0 */ public class ConnPoolByRoute extends AbstractConnPool { private final Log log = LogFactory.getLog(getClass()); - protected final HttpParams params; + private final HttpParams params; /** Connection operator for this pool */ protected final ClientConnectionOperator operator; diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java b/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java index 5a5eb7b20..367a13a58 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java @@ -46,19 +46,32 @@ import org.apache.http.conn.OperatedClientConnection; import org.apache.http.params.HttpParams; import org.apache.http.impl.conn.DefaultClientConnectionOperator; - - /** - * Manages a pool of {@link OperatedClientConnection client connections}. + * Manages a pool of {@link OperatedClientConnection client connections} and + * is able to service connection requests from multiple execution threads. + * Connections are pooled on a per route basis. A request for a route which + * already the manager has persistent connections for available in the pool + * will be services by leasing a connection from the pool rather than + * creating a brand new connection. *

    - * This class is derived from MultiThreadedHttpConnectionManager - * in HttpClient 3. See there for original authors. - *

    + * ThreadSafeClientConnManager maintains a maximum limit of connection on + * a per route basis and in total. Per default this implementation will + * create no more than than 2 concurrent connections per given route + * and no more 20 connections in total. For many real-world applications + * these limits may prove too constraining, especially if they use HTTP + * as a transport protocol for their services. Connection limits, however, + * can be adjusted using HTTP parameters. + *

    + * The following parameters can be used to customize the behavior of this + * class: + *

    * - * - * - * - * @version $Revision$ $Date$ + * @see org.apache.http.conn.params.ConnPerRoute + * @see org.apache.http.conn.params.ConnPerRouteBean * * @since 4.0 */ @@ -75,8 +88,6 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { /** The operator for opening and updating connections. */ protected final ClientConnectionOperator connOperator; - - /** * Creates a new thread safe connection manager. * @@ -94,16 +105,14 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { this.connOperator = createConnectionOperator(schreg); this.connectionPool = createConnectionPool(params); - } // + } - @Override protected void finalize() throws Throwable { shutdown(); super.finalize(); } - /** * Hook for creating the connection pool. * @@ -119,7 +128,6 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { return acp; } - /** * Hook for creating the connection operator. * It is called by the constructor. @@ -138,13 +146,10 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { return new DefaultClientConnectionOperator(schreg); } - - // non-javadoc, see interface ClientConnectionManager public SchemeRegistry getSchemeRegistry() { return this.schemeRegistry; } - public ClientConnectionRequest requestConnection( final HttpRoute route, final Object state) { @@ -178,8 +183,6 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { } - - // non-javadoc, see interface ClientConnectionManager public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) { if (!(conn instanceof BasicPooledConnAdapter)) { @@ -228,14 +231,11 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { } } - - // non-javadoc, see interface ClientConnectionManager public void shutdown() { log.debug("Shutting down"); connectionPool.shutdown(); } - /** * Gets the total number of pooled connections for the given route. * This is the total number of connections that have been created and @@ -251,7 +251,6 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { route); } - /** * Gets the total number of pooled connections. This is the total number of * connections that have been created and are still in use by this connection @@ -268,8 +267,6 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { return count; } - - // non-javadoc, see interface ClientConnectionManager public void closeIdleConnections(long idleTimeout, TimeUnit tunit) { if (log.isDebugEnabled()) { log.debug("Closing connections idle for " + idleTimeout + " " + tunit); @@ -284,6 +281,5 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { connectionPool.deleteClosedConnections(); } - -} // class ThreadSafeClientConnManager +} diff --git a/httpclient/src/test/java/org/apache/http/impl/conn/TestSCMWithServer.java b/httpclient/src/test/java/org/apache/http/impl/conn/TestSCMWithServer.java index 8fab62d98..29a109eb4 100644 --- a/httpclient/src/test/java/org/apache/http/impl/conn/TestSCMWithServer.java +++ b/httpclient/src/test/java/org/apache/http/impl/conn/TestSCMWithServer.java @@ -236,4 +236,26 @@ public class TestSCMWithServer extends ServerTestBase { mgr.shutdown(); } + public void testAlreadyLeased() throws Exception { + + HttpParams mgrpar = defaultParams.copy(); + ConnManagerParams.setMaxTotalConnections(mgrpar, 1); + + SingleClientConnManager mgr = createSCCM(mgrpar, null); + + final HttpHost target = getServerHttp(); + final HttpRoute route = new HttpRoute(target, null, false); + + ManagedClientConnection conn = mgr.getConnection(route, null); + mgr.releaseConnection(conn, 100, TimeUnit.MILLISECONDS); + + mgr.getConnection(route, null); + try { + mgr.getConnection(route, null); + fail("IllegalStateException should have been thrown"); + } catch (IllegalStateException ex) { + mgr.shutdown(); + } + } + }