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 2009/10/16 18:52:31 UTC
svn commit: r825999 - in
/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn:
AbstractClientConnAdapter.java AbstractPooledConnAdapter.java
tsccm/BasicPooledConnAdapter.java tsccm/ThreadSafeClientConnManager.java
Author: olegk
Date: Fri Oct 16 16:52:30 2009
New Revision: 825999
URL: http://svn.apache.org/viewvc?rev=825999&view=rev
Log:
HTTPCLIENT-881: Methods mutating the internal state of the AbstractClientConnAdapter class and its subclasses made synchronized; ThreadSafeClientConnManager#releaseConnection method now synchronizes access to the BasicPooledConnAdapter instance
Modified:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/BasicPooledConnAdapter.java
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java?rev=825999&r1=825998&r2=825999&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java Fri Oct 16 16:52:30 2009
@@ -108,7 +108,7 @@
* Detaches this adapter from the wrapped connection.
* This adapter becomes useless.
*/
- protected void detach() {
+ protected synchronized void detach() {
wrappedConnection = null;
connManager = null; // base class attribute
duration = Long.MAX_VALUE;
@@ -310,7 +310,7 @@
}
}
- public void releaseConnection() {
+ public synchronized void releaseConnection() {
if (shutdown) {
return;
}
@@ -320,7 +320,7 @@
}
}
- public void abortConnection() {
+ public synchronized void abortConnection() {
if (shutdown) {
return;
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java?rev=825999&r1=825998&r2=825999&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java Fri Oct 16 16:52:30 2009
@@ -81,9 +81,9 @@
* This adapter becomes useless.
*/
@Override
- protected void detach() {
- super.detach();
+ protected synchronized void detach() {
poolEntry = null;
+ super.detach();
}
public HttpRoute getRoute() {
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/BasicPooledConnAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/BasicPooledConnAdapter.java?rev=825999&r1=825998&r2=825999&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/BasicPooledConnAdapter.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/BasicPooledConnAdapter.java Fri Oct 16 16:52:30 2009
@@ -26,13 +26,10 @@
package org.apache.http.impl.conn.tsccm;
-
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.conn.AbstractPoolEntry;
import org.apache.http.impl.conn.AbstractPooledConnAdapter;
-
-
/**
* A connection wrapper and callback handler.
* All connections given out by the manager are wrappers which
@@ -72,7 +69,6 @@
}
- // non-javadoc, see base class
@Override
protected void detach() {
// override needed only to make method visible in this package
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java?rev=825999&r1=825998&r2=825999&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java Fri Oct 16 16:52:30 2009
@@ -220,37 +220,38 @@
throw new IllegalArgumentException
("Connection not obtained from this manager.");
}
-
- try {
- // make sure that the response has been read completely
- if (hca.isOpen() && !hca.isMarkedReusable()) {
- // In MTHCM, there would be a call to
- // SimpleHttpConnectionManager.finishLastResponse(conn);
- // Consuming the response is handled outside in 4.0.
-
- // make sure this connection will not be re-used
- // Shut down rather than close, we might have gotten here
- // because of a shutdown trigger.
- // Shutdown of the adapter also clears the tracked route.
- hca.shutdown();
- }
- } catch (IOException iox) {
- //@@@ log as warning? let pass?
- if (log.isDebugEnabled())
- log.debug("Exception shutting down released connection.",
- iox);
- } finally {
+ synchronized (hca) {
BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
- boolean reusable = hca.isMarkedReusable();
- if (log.isDebugEnabled()) {
- if (reusable) {
- log.debug("Released connection is reusable.");
- } else {
- log.debug("Released connection is not reusable.");
- }
+ if (entry == null) {
+ return;
}
- hca.detach();
- if (entry != null) {
+ try {
+ // make sure that the response has been read completely
+ if (hca.isOpen() && !hca.isMarkedReusable()) {
+ // In MTHCM, there would be a call to
+ // SimpleHttpConnectionManager.finishLastResponse(conn);
+ // Consuming the response is handled outside in 4.0.
+
+ // make sure this connection will not be re-used
+ // Shut down rather than close, we might have gotten here
+ // because of a shutdown trigger.
+ // Shutdown of the adapter also clears the tracked route.
+ hca.shutdown();
+ }
+ } catch (IOException iox) {
+ if (log.isDebugEnabled())
+ log.debug("Exception shutting down released connection.",
+ iox);
+ } finally {
+ boolean reusable = hca.isMarkedReusable();
+ if (log.isDebugEnabled()) {
+ if (reusable) {
+ log.debug("Released connection is reusable.");
+ } else {
+ log.debug("Released connection is not reusable.");
+ }
+ }
+ hca.detach();
pool.freeEntry(entry, reusable, validDuration, timeUnit);
}
}