You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2008/04/16 23:05:58 UTC
svn commit: r648848 - in
/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm:
AbstractConnPool.java ConnPoolByRoute.java
Author: olegk
Date: Wed Apr 16 14:05:54 2008
New Revision: 648848
URL: http://svn.apache.org/viewvc?rev=648848&view=rev
Log:
Fixed the use of the Lock interface in AbstractConnPool and ConnPoolByRoute
Modified:
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java?rev=648848&r1=648847&r2=648848&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java Wed Apr 16 14:05:54 2008
@@ -171,8 +171,8 @@
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 @@
// 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 @@
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 void shutdown() {
+ poolLock.lock();
try {
- poolLock.lock();
if (isShutDown)
return;
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java?rev=648848&r1=648847&r2=648848&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java Wed Apr 16 14:05:54 2008
@@ -173,9 +173,8 @@
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 @@
//@@@ 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 @@
return new PoolEntryRequest() {
public void abortRequest() {
+ poolLock.lock();
try {
- poolLock.lock();
aborter.abort();
} finally {
poolLock.unlock();
@@ -278,8 +276,8 @@
}
BasicPoolEntry entry = null;
+ poolLock.lock();
try {
- poolLock.lock();
RouteSpecificPool rospl = getRoutePool(route, true);
WaitingThread waitingThread = null;
@@ -297,7 +295,7 @@
// - 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 @@
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 @@
* @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 @@
BasicPoolEntry entry =
new BasicPoolEntry(op, rospl.getRoute(), refQueue);
+ poolLock.lock();
try {
- poolLock.lock();
rospl.createdEntry(entry);
numConnections++;
@@ -503,8 +500,8 @@
LOG.debug("Deleting connection. " + route);
}
+ poolLock.lock();
try {
- poolLock.lock();
closeConnection(entry.getConnection());
@@ -552,8 +549,8 @@
@Override
protected void handleLostEntry(HttpRoute route) {
+ poolLock.lock();
try {
- poolLock.lock();
RouteSpecificPool rospl = getRoutePool(route, true);
rospl.dropEntry();
@@ -587,8 +584,8 @@
// 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 @@
@Override
public void deleteClosedConnections() {
+ poolLock.lock();
try {
- poolLock.lock();
Iterator<BasicPoolEntry> iter = freeConnections.iterator();
while (iter.hasNext()) {
@@ -647,8 +644,8 @@
@Override
public void shutdown() {
+ poolLock.lock();
try {
- poolLock.lock();
super.shutdown();