diff --git a/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java b/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java
index de31f35ca..e6b357f29 100644
--- a/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java
+++ b/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java
@@ -34,13 +34,9 @@ package org.apache.http.conn;
import java.util.concurrent.TimeUnit;
-import org.apache.http.params.HttpParams;
-
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.scheme.SchemeRegistry;
-
-
/**
* Management interface for {@link ManagedClientConnection client connections}.
*
@@ -57,15 +53,6 @@ import org.apache.http.conn.scheme.SchemeRegistry;
*/
public interface ClientConnectionManager {
- /**
- * Obtains the parameters of this manager.
- *
- * @return the parameters, never null
- */
- HttpParams getParams()
- ;
-
-
/**
* Obtains the scheme registry used by this manager.
*
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java b/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
index 1b45f21a2..b32414c3d 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
@@ -81,9 +81,6 @@ public class SingleClientConnManager implements ClientConnectionManager {
/** The schemes supported by this connection manager. */
protected SchemeRegistry schemeRegistry;
- /** The parameters of this connection manager. */
- protected HttpParams params;
-
/** The operator for opening and updating connections. */
protected ClientConnectionOperator connOperator;
@@ -115,15 +112,10 @@ public class SingleClientConnManager implements ClientConnectionManager {
public SingleClientConnManager(HttpParams params,
SchemeRegistry schreg) {
- if (params == null) {
- throw new IllegalArgumentException
- ("Parameters must not be null.");
- }
if (schreg == null) {
throw new IllegalArgumentException
("Scheme registry must not be null.");
}
- this.params = params;
this.schemeRegistry = schreg;
this.connOperator = createConnectionOperator(schreg);
this.uniquePoolEntry = new PoolEntry(connOperator.createConnection());
@@ -135,11 +127,6 @@ public class SingleClientConnManager implements ClientConnectionManager {
} //
- // non-javadoc, see interface ClientConnectionManager
- public HttpParams getParams() {
- return this.params;
- }
-
// non-javadoc, see interface ClientConnectionManager
public SchemeRegistry getSchemeRegistry() {
return this.schemeRegistry;
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
index 04f5dbea4..a0b956d74 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
@@ -48,7 +48,6 @@ import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.params.HttpParams;
import org.apache.http.impl.conn.IdleConnectionHandler;
@@ -86,12 +85,6 @@ public abstract class AbstractConnPool implements RefQueueHandler {
/** The current total number of connections. */
protected int numConnections;
- /** The parameters of this connection pool. */
- //@@@ allow get/set? synchronized?
- //@@@ currently needed for connection limits
- protected HttpParams params;
-
-
/**
* The connection manager.
* This weak reference is used only to detect garbage collection
@@ -141,9 +134,6 @@ public abstract class AbstractConnPool implements RefQueueHandler {
* @param mgr the connection manager
*/
protected AbstractConnPool(ClientConnectionManager mgr) {
-
- params = mgr.getParams();
-
issuedConnections = new HashSet();
idleConnHandler = new IdleConnectionHandler();
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
index 18ede70ee..cdc2c29d5 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
@@ -47,6 +47,7 @@ import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.params.ConnPerRoute;
import org.apache.http.conn.params.HttpConnectionManagerParams;
+import org.apache.http.params.HttpParams;
@@ -86,19 +87,24 @@ public class ConnPoolByRoute extends AbstractConnPool {
*/
protected final Map routeToPool;
-
-
+ protected final int maxTotalConnections;
+
+ private final ConnPerRoute connPerRoute;
+
/**
* Creates a new connection pool, managed by route.
*
* @param mgr the connection manager
*/
- public ConnPoolByRoute(ClientConnectionManager mgr) {
+ public ConnPoolByRoute(final ClientConnectionManager mgr, final HttpParams params) {
super(mgr);
-
freeConnections = createFreeConnQueue();
waitingThreads = createWaitingThreadQueue();
routeToPool = createRouteToPoolMap();
+ maxTotalConnections = HttpConnectionManagerParams
+ .getMaxTotalConnections(params);
+ connPerRoute = HttpConnectionManagerParams
+ .getMaxConnectionsPerRoute(params);
}
@@ -142,7 +148,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
* @return the new pool
*/
protected RouteSpecificPool newRouteSpecificPool(HttpRoute route) {
- return new RouteSpecificPool(route);
+ return new RouteSpecificPool(route, connPerRoute.getMaxForRoute(route));
}
@@ -261,14 +267,6 @@ public class ConnPoolByRoute extends AbstractConnPool {
Aborter aborter)
throws ConnectionPoolTimeoutException, InterruptedException {
- int maxTotalConnections = HttpConnectionManagerParams
- .getMaxTotalConnections(this.params);
-
- ConnPerRoute connPerRoute = HttpConnectionManagerParams
- .getMaxConnectionsPerRoute(params);
-
- int maxHostConnections = connPerRoute.getMaxForRoute(route);
-
Date deadline = null;
if (timeout > 0) {
deadline = new Date
@@ -299,12 +297,12 @@ public class ConnPoolByRoute extends AbstractConnPool {
if (entry != null) {
// we're fine
//@@@ yeah this is ugly, but historical... will be revised
- } else if ((rospl.getEntryCount() < maxHostConnections) &&
+ } else if ((rospl.getEntryCount() < rospl.getMaxEntries()) &&
(numConnections < maxTotalConnections)) {
entry = createEntry(rospl, operator);
- } else if ((rospl.getEntryCount() < maxHostConnections) &&
+ } else if ((rospl.getEntryCount() < rospl.getMaxEntries()) &&
(freeConnections.size() > 0)) {
deleteLeastUsedEntry();
@@ -419,7 +417,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
poolLock.lock();
try {
- entry = rospl.allocEntry();
+ entry = rospl.allocEntry(state);
if (entry != null) {
if (LOG.isDebugEnabled()) {
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
index a80733767..d25d6dcc8 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
@@ -46,6 +46,9 @@ public class RouteSpecificPool {
/** The route this pool is for. */
protected final HttpRoute route;
+ /** the maximum number of entries allowed for this pool */
+ protected final int maxEntries;
+
/**
* The list of free entries.
* This list is managed LIFO, to increase idle times and
@@ -63,10 +66,12 @@ public class RouteSpecificPool {
/**
* Creates a new route-specific pool.
*
- * @param r the route for which to pool
+ * @param route the route for which to pool
+ * @param maxEntries the maximum number of entries allowed for this pool
*/
- public RouteSpecificPool(HttpRoute route) {
+ public RouteSpecificPool(HttpRoute route, int maxEntries) {
this.route = route;
+ this.maxEntries = maxEntries;
this.freeEntries = new LinkedList();
this.waitingThreads = new LinkedList();
this.numEntries = 0;
@@ -82,7 +87,17 @@ public class RouteSpecificPool {
return route;
}
-
+
+ /**
+ * Obtains the maximum number of entries allowed for this pool.
+ *
+ * @return the max entry number
+ */
+ public final int getMaxEntries() {
+ return maxEntries;
+ }
+
+
/**
* Indicates whether this pool is unused.
* A pool is unused if there is neither an entry nor a waiting thread.
@@ -113,7 +128,7 @@ public class RouteSpecificPool {
*
* @return an available pool entry, or null
if there is none
*/
- public BasicPoolEntry allocEntry() {
+ public BasicPoolEntry allocEntry(final Object state) {
BasicPoolEntry entry = null;
diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
index 0a80a25e9..972e577c6 100644
--- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
+++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
@@ -74,9 +74,6 @@ public class ThreadSafeClientConnManager
/** The schemes supported by this connection manager. */
protected SchemeRegistry schemeRegistry;
- /** The parameters of this connection manager. */
- protected HttpParams params;
-
/** The pool of connections being managed. */
protected final AbstractConnPool connectionPool;
@@ -96,11 +93,10 @@ public class ThreadSafeClientConnManager
SchemeRegistry schreg) {
if (params == null) {
- throw new IllegalArgumentException("Parameters must not be null.");
+ throw new IllegalArgumentException("HTTP parameters may not be null");
}
- this.params = params;
this.schemeRegistry = schreg;
- this.connectionPool = createConnectionPool();
+ this.connectionPool = createConnectionPool(params);
this.connOperator = createConnectionOperator(schreg);
} //
@@ -111,9 +107,9 @@ public class ThreadSafeClientConnManager
*
* @return the connection pool to use
*/
- protected AbstractConnPool createConnectionPool() {
+ protected AbstractConnPool createConnectionPool(final HttpParams params) {
- AbstractConnPool acp = new ConnPoolByRoute(this);
+ AbstractConnPool acp = new ConnPoolByRoute(this, params);
boolean conngc = true; //@@@ check parameters to decide
if (conngc) {
acp.enableConnectionGC();
@@ -270,10 +266,5 @@ public class ThreadSafeClientConnManager
}
- // non-javadoc, see interface ClientConnectionManager
- public HttpParams getParams() {
- return this.params;
- }
-
} // class ThreadSafeClientConnManager
diff --git a/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java b/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java
index 791f04450..d8f7c5bdd 100644
--- a/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java
+++ b/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java
@@ -145,15 +145,9 @@ public class TestTSCCMNoServer extends TestCase {
HttpParams params = createDefaultParams();
SchemeRegistry schreg = createSchemeRegistry();
- final String paramkey = "test.parameter";
- final String paramval = "Value of the test parameter.";
- params.setParameter(paramkey, paramval);
-
ThreadSafeClientConnManager mgr =
new ThreadSafeClientConnManager(params, schreg);
assertNotNull(mgr);
- assertNotNull(mgr.getParams());
- assertEquals(paramval, mgr.getParams().getParameter(paramkey));
mgr.shutdown();
mgr = null;
@@ -170,8 +164,6 @@ public class TestTSCCMNoServer extends TestCase {
mgr = new ThreadSafeClientConnManager(params, schreg);
assertNotNull(mgr);
- assertNotNull(mgr.getParams());
- assertEquals(paramval, mgr.getParams().getParameter(paramkey));
mgr.shutdown();
mgr = null;
diff --git a/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java b/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java
index f77ee8626..87863786a 100644
--- a/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java
+++ b/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java
@@ -97,8 +97,8 @@ public class TestSpuriousWakeup extends TestCase {
protected WaitingThread newestWT;
- public XConnPoolByRoute(ClientConnectionManager mgr) {
- super(mgr);
+ public XConnPoolByRoute(ClientConnectionManager mgr, HttpParams params) {
+ super(mgr, params);
}
protected synchronized
@@ -125,8 +125,8 @@ public class TestSpuriousWakeup extends TestCase {
super(params, schreg);
}
- protected AbstractConnPool createConnectionPool() {
- extendedCPBR = new XConnPoolByRoute(this);
+ protected AbstractConnPool createConnectionPool(HttpParams params) {
+ extendedCPBR = new XConnPoolByRoute(this, params);
// no connection GC required
return extendedCPBR;
}
diff --git a/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java b/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java
index 1e24be85a..08687e4a5 100644
--- a/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java
+++ b/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestWaitingThread.java
@@ -83,7 +83,7 @@ public class TestWaitingThread extends TestCase {
assertNull ("thread from nowhere", wt.getThread());
HttpRoute route = new HttpRoute(TARGET);
- RouteSpecificPool rospl = new RouteSpecificPool(route);
+ RouteSpecificPool rospl = new RouteSpecificPool(route, 10);
wt = new WaitingThread(cnd, rospl);
assertEquals("wrong condition", cnd, wt.getCondition());
assertEquals("wrong pool", rospl, wt.getPool());