more code cleanup
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@561043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
76c21530ee
commit
782fd75b1e
|
@ -225,25 +225,22 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
// - need to wait for one of the things above to come true
|
// - need to wait for one of the things above to come true
|
||||||
|
|
||||||
if (routePool.freeConnections.size() > 0) {
|
if (routePool.freeConnections.size() > 0) {
|
||||||
//@@@ why pass the route, we already have the pool?
|
entry = getFreeEntry(routePool);
|
||||||
entry = getFreeEntry(route);
|
|
||||||
|
|
||||||
} else if ((routePool.numConnections < maxHostConnections) &&
|
} else if ((routePool.numConnections < maxHostConnections) &&
|
||||||
(numConnections < maxTotalConnections)) {
|
(numConnections < maxTotalConnections)) {
|
||||||
|
|
||||||
//@@@ why pass the route, we already have the pool?
|
entry = createEntry(routePool, operator);
|
||||||
entry = createEntry(route, operator);
|
|
||||||
|
|
||||||
} else if ((routePool.numConnections < maxHostConnections) &&
|
} else if ((routePool.numConnections < maxHostConnections) &&
|
||||||
(freeConnections.size() > 0)) {
|
(freeConnections.size() > 0)) {
|
||||||
|
|
||||||
deleteLeastUsedEntry();
|
deleteLeastUsedEntry();
|
||||||
//@@@ why pass the route, we already have the pool?
|
entry = createEntry(routePool, operator);
|
||||||
entry = createEntry(route, operator);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: keep track of which routes have waiting
|
// TODO: keep track of which routes have waiting threads,
|
||||||
// threads, so they avoid being sacrificed before necessary
|
// so they avoid being sacrificed before necessary
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (useTimeout && timeToWait <= 0) {
|
if (useTimeout && timeToWait <= 0) {
|
||||||
|
@ -352,21 +349,19 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
/**
|
/**
|
||||||
* If available, get a free pool entry for a route.
|
* If available, get a free pool entry for a route.
|
||||||
*
|
*
|
||||||
* @param route the planned route
|
* @param rcp the route-specific pool from which to get an entry
|
||||||
*
|
*
|
||||||
* @return an available pool entry for the given route
|
* @return an available pool entry for the given route
|
||||||
*/
|
*/
|
||||||
protected synchronized BasicPoolEntry getFreeEntry(HttpRoute route) {
|
protected synchronized BasicPoolEntry getFreeEntry(RouteConnPool rcp) {
|
||||||
|
|
||||||
BasicPoolEntry entry = null;
|
BasicPoolEntry entry = null;
|
||||||
|
|
||||||
RouteConnPool routePool = getRoutePool(route);
|
if (rcp.freeConnections.size() > 0) {
|
||||||
|
|
||||||
if (routePool.freeConnections.size() > 0) {
|
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Getting free connection. " + route);
|
LOG.debug("Getting free connection. " + rcp.route);
|
||||||
}
|
}
|
||||||
entry = (BasicPoolEntry) routePool.freeConnections.removeLast();
|
entry = (BasicPoolEntry) rcp.freeConnections.removeLast();
|
||||||
freeConnections.remove(entry);
|
freeConnections.remove(entry);
|
||||||
idleConnHandler.remove(entry.getConnection()); // no longer idle
|
idleConnHandler.remove(entry.getConnection()); // no longer idle
|
||||||
|
|
||||||
|
@ -374,7 +369,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("No free connections. " + route);
|
LOG.debug("No free connections. " + rcp.route);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return entry;
|
return entry;
|
||||||
|
@ -386,24 +381,23 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
* This method assumes that the new connection will be handed
|
* This method assumes that the new connection will be handed
|
||||||
* out immediately.
|
* out immediately.
|
||||||
*
|
*
|
||||||
* @param route the route associated with the new entry
|
* @param rcp the route-specific pool for which to create the entry
|
||||||
* @param op the operator for creating a connection
|
* @param op the operator for creating a connection
|
||||||
*
|
*
|
||||||
* @return the new pool entry, holding a new connection
|
* @return the new pool entry for a new connection
|
||||||
*/
|
*/
|
||||||
protected synchronized
|
protected synchronized
|
||||||
BasicPoolEntry createEntry(HttpRoute route,
|
BasicPoolEntry createEntry(RouteConnPool rcp,
|
||||||
ClientConnectionOperator op) {
|
ClientConnectionOperator op) {
|
||||||
|
|
||||||
RouteConnPool routePool = getRoutePool(route);
|
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Creating new connection. " + route);
|
LOG.debug("Creating new connection. " + rcp.route);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the entry will create the connection when needed
|
// the entry will create the connection when needed
|
||||||
BasicPoolEntry entry = new BasicPoolEntry(this, op, route, refQueue);
|
BasicPoolEntry entry =
|
||||||
|
new BasicPoolEntry(this, op, rcp.route, refQueue);
|
||||||
numConnections++;
|
numConnections++;
|
||||||
routePool.numConnections++;
|
rcp.numConnections++;
|
||||||
|
|
||||||
issuedConnections.add(entry.getWeakRef());
|
issuedConnections.add(entry.getWeakRef());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue