HTTPCLIENT-741: AbstractClientConnAdapter#abortConnection() no longer releases the wrapped connection back to the connection manager. The wrapped connection gets shut down, but remains attached to the adapter. The connection is expected to be released back to the connection manager by the request execution thread.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@617839 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2008-02-02 17:38:07 +00:00
parent 6d1391a332
commit 0f561bdf2b
1 changed files with 41 additions and 28 deletions

View File

@ -130,19 +130,14 @@ public abstract class AbstractClientConnAdapter
} }
/** /**
* Asserts that there is a wrapped connection to delegate to. * Asserts that the connection has not been aborted.
* *
* @throws IllegalStateException if there is no wrapped connection
* @throws InterruptedIOException if the connection has been aborted * @throws InterruptedIOException if the connection has been aborted
*/ */
protected final void assertIOState( protected final void assertNotAborted() throws InterruptedIOException {
final OperatedClientConnection wrappedConn) throws InterruptedIOException {
if (aborted) { if (aborted) {
throw new InterruptedIOException("Connection has been shut down"); throw new InterruptedIOException("Connection has been shut down");
} }
if (wrappedConn == null) {
throw new IllegalStateException("No wrapped connection.");
}
} }
/** /**
@ -151,11 +146,8 @@ public abstract class AbstractClientConnAdapter
* @throws IllegalStateException if there is no wrapped connection * @throws IllegalStateException if there is no wrapped connection
* or connection has been aborted * or connection has been aborted
*/ */
protected final void assertState( protected final void assertValid(
final OperatedClientConnection wrappedConn) { final OperatedClientConnection wrappedConn) {
if (aborted) {
throw new IllegalStateException("Connection has been shut down");
}
if (wrappedConn == null) { if (wrappedConn == null) {
throw new IllegalStateException("No wrapped connection."); throw new IllegalStateException("No wrapped connection.");
} }
@ -184,7 +176,7 @@ public abstract class AbstractClientConnAdapter
// non-javadoc, see interface HttpConnection // non-javadoc, see interface HttpConnection
public void setSocketTimeout(int timeout) { public void setSocketTimeout(int timeout) {
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertState(conn); assertValid(conn);
conn.setSocketTimeout(timeout); conn.setSocketTimeout(timeout);
} }
@ -192,7 +184,7 @@ public abstract class AbstractClientConnAdapter
// non-javadoc, see interface HttpConnection // non-javadoc, see interface HttpConnection
public int getSocketTimeout() { public int getSocketTimeout() {
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertState(conn); assertValid(conn);
return conn.getSocketTimeout(); return conn.getSocketTimeout();
} }
@ -200,7 +192,7 @@ public abstract class AbstractClientConnAdapter
// non-javadoc, see interface HttpConnection // non-javadoc, see interface HttpConnection
public HttpConnectionMetrics getMetrics() { public HttpConnectionMetrics getMetrics() {
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertState(conn); assertValid(conn);
return conn.getMetrics(); return conn.getMetrics();
} }
@ -209,8 +201,10 @@ public abstract class AbstractClientConnAdapter
public void flush() public void flush()
throws IOException { throws IOException {
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertIOState(conn); assertValid(conn);
conn.flush(); conn.flush();
} }
@ -219,8 +213,10 @@ public abstract class AbstractClientConnAdapter
public boolean isResponseAvailable(int timeout) public boolean isResponseAvailable(int timeout)
throws IOException { throws IOException {
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertIOState(conn); assertValid(conn);
return conn.isResponseAvailable(timeout); return conn.isResponseAvailable(timeout);
} }
@ -229,8 +225,10 @@ public abstract class AbstractClientConnAdapter
public void receiveResponseEntity(HttpResponse response) public void receiveResponseEntity(HttpResponse response)
throws HttpException, IOException { throws HttpException, IOException {
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertIOState(conn); assertValid(conn);
unmarkReusable(); unmarkReusable();
conn.receiveResponseEntity(response); conn.receiveResponseEntity(response);
} }
@ -240,8 +238,10 @@ public abstract class AbstractClientConnAdapter
public HttpResponse receiveResponseHeader() public HttpResponse receiveResponseHeader()
throws HttpException, IOException { throws HttpException, IOException {
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertIOState(conn); assertValid(conn);
unmarkReusable(); unmarkReusable();
return conn.receiveResponseHeader(); return conn.receiveResponseHeader();
} }
@ -251,8 +251,10 @@ public abstract class AbstractClientConnAdapter
public void sendRequestEntity(HttpEntityEnclosingRequest request) public void sendRequestEntity(HttpEntityEnclosingRequest request)
throws HttpException, IOException { throws HttpException, IOException {
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertIOState(conn); assertValid(conn);
unmarkReusable(); unmarkReusable();
conn.sendRequestEntity(request); conn.sendRequestEntity(request);
} }
@ -262,8 +264,10 @@ public abstract class AbstractClientConnAdapter
public void sendRequestHeader(HttpRequest request) public void sendRequestHeader(HttpRequest request)
throws HttpException, IOException { throws HttpException, IOException {
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertIOState(conn); assertValid(conn);
unmarkReusable(); unmarkReusable();
conn.sendRequestHeader(request); conn.sendRequestHeader(request);
} }
@ -272,14 +276,14 @@ public abstract class AbstractClientConnAdapter
// non-javadoc, see interface HttpInetConnection // non-javadoc, see interface HttpInetConnection
public InetAddress getLocalAddress() { public InetAddress getLocalAddress() {
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertState(conn); assertValid(conn);
return conn.getLocalAddress(); return conn.getLocalAddress();
} }
// non-javadoc, see interface HttpInetConnection // non-javadoc, see interface HttpInetConnection
public int getLocalPort() { public int getLocalPort() {
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertState(conn); assertValid(conn);
return conn.getLocalPort(); return conn.getLocalPort();
} }
@ -287,28 +291,28 @@ public abstract class AbstractClientConnAdapter
// non-javadoc, see interface HttpInetConnection // non-javadoc, see interface HttpInetConnection
public InetAddress getRemoteAddress() { public InetAddress getRemoteAddress() {
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertState(conn); assertValid(conn);
return conn.getRemoteAddress(); return conn.getRemoteAddress();
} }
// non-javadoc, see interface HttpInetConnection // non-javadoc, see interface HttpInetConnection
public int getRemotePort() { public int getRemotePort() {
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertState(conn); assertValid(conn);
return conn.getRemotePort(); return conn.getRemotePort();
} }
// non-javadoc, see interface ManagedClientConnection // non-javadoc, see interface ManagedClientConnection
public boolean isSecure() { public boolean isSecure() {
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertState(conn); assertValid(conn);
return conn.isSecure(); return conn.isSecure();
} }
// non-javadoc, see interface ManagedClientConnection // non-javadoc, see interface ManagedClientConnection
public SSLSession getSSLSession() { public SSLSession getSSLSession() {
OperatedClientConnection conn = getWrappedConnection(); OperatedClientConnection conn = getWrappedConnection();
assertState(conn); assertValid(conn);
if (!isOpen()) if (!isOpen())
return null; return null;
@ -343,11 +347,20 @@ public abstract class AbstractClientConnAdapter
// non-javadoc, see interface ConnectionReleaseTrigger // non-javadoc, see interface ConnectionReleaseTrigger
public void abortConnection() { public void abortConnection() {
if (aborted) {
return;
}
aborted = true; aborted = true;
unmarkReusable(); unmarkReusable();
if (connManager != null) OperatedClientConnection conn = getWrappedConnection();
connManager.releaseConnection(this);
if (conn != null) {
try {
conn.shutdown();
} catch (IOException ignore) {
}
}
} }
} // class AbstractClientConnAdapter } // class AbstractClientConnAdapter