Fields Summary |
---|
private final Thread | executionThreadThread that requested this connection. |
private volatile ClientConnectionManager | connManagerThe connection manager, if any.
This attribute MUST NOT be final, so the adapter can be detached
from the connection manager without keeping a hard reference there. |
private volatile OperatedClientConnection | wrappedConnectionThe wrapped connection. |
private volatile boolean | markedReusableThe reusability marker. |
private volatile boolean | abortedTrue if the connection has been aborted. |
private volatile long | durationThe duration this is valid for while idle (in ms). |
Methods Summary |
---|
public void | abortConnection()
if (aborted) {
return;
}
aborted = true;
unmarkReusable();
try {
shutdown();
} catch (IOException ignore) {
}
// Usually #abortConnection() is expected to be called from
// a helper thread in order to unblock the main execution thread
// blocked in an I/O operation. It may be unsafe to call
// #releaseConnection() from the helper thread, so we have to rely
// on an IOException thrown by the closed socket on the main thread
// to trigger the release of the connection back to the
// connection manager.
//
// However, if this method is called from the main execution thread
// it should be safe to release the connection immediately. Besides,
// this also helps ensure the connection gets released back to the
// manager if #abortConnection() is called from the main execution
// thread while there is no blocking I/O operation.
if (executionThread.equals(Thread.currentThread())) {
releaseConnection();
}
|
protected final void | assertNotAborted()Asserts that the connection has not been aborted.
if (aborted) {
throw new InterruptedIOException("Connection has been shut down.");
}
|
protected final void | assertValid(org.apache.http.conn.OperatedClientConnection wrappedConn)Asserts that there is a wrapped connection to delegate to.
if (wrappedConn == null) {
throw new IllegalStateException("No wrapped connection.");
}
|
protected void | detach()Detaches this adapter from the wrapped connection.
This adapter becomes useless.
wrappedConnection = null;
connManager = null; // base class attribute
duration = Long.MAX_VALUE;
|
public void | flush()
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
conn.flush();
|
public java.net.InetAddress | getLocalAddress()
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
return conn.getLocalAddress();
|
public int | getLocalPort()
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
return conn.getLocalPort();
|
protected org.apache.http.conn.ClientConnectionManager | getManager()
return connManager;
|
public org.apache.http.HttpConnectionMetrics | getMetrics()
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
return conn.getMetrics();
|
public java.net.InetAddress | getRemoteAddress()
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
return conn.getRemoteAddress();
|
public int | getRemotePort()
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
return conn.getRemotePort();
|
public javax.net.ssl.SSLSession | getSSLSession()
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
if (!isOpen())
return null;
SSLSession result = null;
Socket sock = conn.getSocket();
if (sock instanceof SSLSocket) {
result = ((SSLSocket)sock).getSession();
}
return result;
|
public int | getSocketTimeout()
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
return conn.getSocketTimeout();
|
protected org.apache.http.conn.OperatedClientConnection | getWrappedConnection()
return wrappedConnection;
|
public boolean | isMarkedReusable()
return markedReusable;
|
public boolean | isOpen()
OperatedClientConnection conn = getWrappedConnection();
if (conn == null)
return false;
return conn.isOpen();
|
public boolean | isResponseAvailable(int timeout)
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
return conn.isResponseAvailable(timeout);
|
public boolean | isSecure()
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
return conn.isSecure();
|
public boolean | isStale()
if (aborted)
return true;
OperatedClientConnection conn = getWrappedConnection();
if (conn == null)
return true;
return conn.isStale();
|
public void | markReusable()
markedReusable = true;
|
public void | receiveResponseEntity(org.apache.http.HttpResponse response)
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
unmarkReusable();
conn.receiveResponseEntity(response);
|
public org.apache.http.HttpResponse | receiveResponseHeader()
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
unmarkReusable();
return conn.receiveResponseHeader();
|
public void | releaseConnection()
if (connManager != null) {
connManager.releaseConnection(this, duration, TimeUnit.MILLISECONDS);
}
|
public void | sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest request)
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
unmarkReusable();
conn.sendRequestEntity(request);
|
public void | sendRequestHeader(org.apache.http.HttpRequest request)
assertNotAborted();
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
unmarkReusable();
conn.sendRequestHeader(request);
|
public void | setIdleDuration(long duration, java.util.concurrent.TimeUnit unit)
if(duration > 0) {
this.duration = unit.toMillis(duration);
} else {
this.duration = -1;
}
|
public void | setSocketTimeout(int timeout)
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
conn.setSocketTimeout(timeout);
|
public void | unmarkReusable()
markedReusable = false;
|