Fixed the use of the Lock interface in AbstractConnPool and ConnPoolByRoute

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@648848 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2008-04-16 21:05:54 +00:00
parent 608a6e67f3
commit bfbc2e0007
2 changed files with 18 additions and 21 deletions

View File

@ -171,8 +171,8 @@ public abstract class AbstractConnPool implements RefQueueHandler {
if (refQueue != null) {
throw new IllegalStateException("Connection GC already enabled.");
}
poolLock.lock();
try {
poolLock.lock();
if (numConnections > 0) { //@@@ is this check sufficient?
throw new IllegalStateException("Pool already in use.");
}
@ -242,8 +242,8 @@ public abstract class AbstractConnPool implements RefQueueHandler {
// non-javadoc, see interface RefQueueHandler
public void handleReference(Reference<?> ref) {
poolLock.lock();
try {
poolLock.lock();
if (ref instanceof BasicPoolEntryRef) {
// check if the GCed pool entry was still in use
@ -296,8 +296,8 @@ public abstract class AbstractConnPool implements RefQueueHandler {
throw new IllegalArgumentException("Time unit must not be null.");
}
poolLock.lock();
try {
poolLock.lock();
idleConnHandler.closeIdleConnections(tunit.toMillis(idletime));
} finally {
poolLock.unlock();
@ -319,8 +319,8 @@ public abstract class AbstractConnPool implements RefQueueHandler {
*/
public void shutdown() {
poolLock.lock();
try {
poolLock.lock();
if (isShutDown)
return;

View File

@ -173,9 +173,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
protected RouteSpecificPool getRoutePool(HttpRoute route,
boolean create) {
RouteSpecificPool rospl = null;
poolLock.lock();
try {
poolLock.lock();
rospl = routeToPool.get(route);
if ((rospl == null) && create) {
@ -195,9 +194,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
//@@@ consider alternatives for gathering statistics
public int getConnectionsInPool(HttpRoute route) {
poolLock.lock();
try {
poolLock.lock();
// don't allow a pool to be created here!
RouteSpecificPool rospl = getRoutePool(route, false);
return (rospl != null) ? rospl.getEntryCount() : 0;
@ -215,8 +213,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
return new PoolEntryRequest() {
public void abortRequest() {
poolLock.lock();
try {
poolLock.lock();
aborter.abort();
} finally {
poolLock.unlock();
@ -278,8 +276,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
}
BasicPoolEntry entry = null;
poolLock.lock();
try {
poolLock.lock();
RouteSpecificPool rospl = getRoutePool(route, true);
WaitingThread waitingThread = null;
@ -297,7 +295,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
// - can delete and replace a free connection for another route
// - need to wait for one of the things above to come true
entry = getFreeEntry(rospl);
entry = getFreeEntry(rospl, state);
if (entry != null) {
// we're fine
//@@@ yeah this is ugly, but historical... will be revised
@ -372,9 +370,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
LOG.debug("Freeing connection. " + route);
}
poolLock.lock();
try {
poolLock.lock();
if (isShutDown) {
// the pool is shut down, release the
// connection's resources and get out of here
@ -416,11 +413,11 @@ public class ConnPoolByRoute extends AbstractConnPool {
* @return an available pool entry for the given route, or
* <code>null</code> if none is available
*/
protected BasicPoolEntry getFreeEntry(RouteSpecificPool rospl) {
protected BasicPoolEntry getFreeEntry(RouteSpecificPool rospl, Object state) {
BasicPoolEntry entry = null;
poolLock.lock();
try {
poolLock.lock();
entry = rospl.allocEntry();
@ -468,8 +465,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
BasicPoolEntry entry =
new BasicPoolEntry(op, rospl.getRoute(), refQueue);
poolLock.lock();
try {
poolLock.lock();
rospl.createdEntry(entry);
numConnections++;
@ -503,8 +500,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
LOG.debug("Deleting connection. " + route);
}
poolLock.lock();
try {
poolLock.lock();
closeConnection(entry.getConnection());
@ -552,8 +549,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
@Override
protected void handleLostEntry(HttpRoute route) {
poolLock.lock();
try {
poolLock.lock();
RouteSpecificPool rospl = getRoutePool(route, true);
rospl.dropEntry();
@ -587,8 +584,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
// it from all wait queues before interrupting.
WaitingThread waitingThread = null;
poolLock.lock();
try {
poolLock.lock();
if ((rospl != null) && rospl.hasThread()) {
if (LOG.isDebugEnabled()) {
@ -625,8 +622,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
@Override
public void deleteClosedConnections() {
poolLock.lock();
try {
poolLock.lock();
Iterator<BasicPoolEntry> iter = freeConnections.iterator();
while (iter.hasNext()) {
@ -647,8 +644,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
@Override
public void shutdown() {
poolLock.lock();
try {
poolLock.lock();
super.shutdown();