org.apache.http.impl.conn
Class AbstractClientConnAdapter

java.lang.Object
  extended by org.apache.http.impl.conn.AbstractClientConnAdapter
All Implemented Interfaces:
ConnectionReleaseTrigger, ManagedClientConnection, org.apache.http.HttpClientConnection, org.apache.http.HttpConnection, org.apache.http.HttpInetConnection
Direct Known Subclasses:
AbstractPooledConnAdapter

public abstract class AbstractClientConnAdapter
extends java.lang.Object
implements ManagedClientConnection

Abstract adapter from operated to managed client connections. Read and write methods are delegated to the wrapped connection. Operations affecting the connection state have to be implemented by derived classes. Operations for querying the connection state are delegated to the wrapped connection if there is one, or return a default value if there is none.
This adapter tracks the checkpoints for reusable communication states, as indicated by markReusable and queried by isMarkedReusable. All send and receive operations will automatically clear the mark.
Connection release calls are delegated to the connection manager, if there is one. abortConnection will clear the reusability mark first. The connection manager is expected to tolerate multiple calls to the release method.

Since:
4.0
Version:
$Revision: 580608 $ $Date: 2007-09-29 19:25:18 +0200 (Sat, 29 Sep 2007) $
Author:
Roland Weber

Field Summary
protected  ClientConnectionManager connManager
          The connection manager, if any.
protected  boolean markedReusable
          The reusability marker.
protected  OperatedClientConnection wrappedConnection
          The wrapped connection.
 
Constructor Summary
protected AbstractClientConnAdapter(ClientConnectionManager mgr, OperatedClientConnection conn)
          Creates a new connection adapter.
 
Method Summary
 void abortConnection()
          Releases the connection without the option of keep-alive.
protected  void assertWrappedConn()
          Asserts that there is a wrapped connection to delegate to.
 void flush()
           
 java.net.InetAddress getLocalAddress()
           
 int getLocalPort()
           
 org.apache.http.HttpConnectionMetrics getMetrics()
           
 java.net.InetAddress getRemoteAddress()
           
 int getRemotePort()
           
 int getSocketTimeout()
           
 javax.net.ssl.SSLSession getSSLSession()
          Obtains the SSL session of the underlying connection, if any.
 boolean isMarkedReusable()
          Indicates whether this connection is in a reusable communication state.
 boolean isOpen()
           
 boolean isResponseAvailable(int timeout)
           
 boolean isSecure()
          Indicates whether this connection is secure.
 boolean isStale()
           
 void markReusable()
          Marks this connection as being in a reusable communication state.
 void receiveResponseEntity(org.apache.http.HttpResponse response)
           
 org.apache.http.HttpResponse receiveResponseHeader()
           
 void releaseConnection()
          Releases the connection with the option of keep-alive.
 void sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest request)
           
 void sendRequestHeader(org.apache.http.HttpRequest request)
           
 void setSocketTimeout(int timeout)
           
 void unmarkReusable()
          Marks this connection as not being in a reusable state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.http.conn.ManagedClientConnection
getRoute, layerProtocol, open, tunnelProxy, tunnelTarget
 
Methods inherited from interface org.apache.http.HttpConnection
close, shutdown
 
Methods inherited from interface org.apache.http.HttpConnection
close, shutdown
 

Field Detail

connManager

protected ClientConnectionManager connManager
The 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.


wrappedConnection

protected OperatedClientConnection wrappedConnection
The wrapped connection.


markedReusable

protected boolean markedReusable
The reusability marker.

Constructor Detail

AbstractClientConnAdapter

protected AbstractClientConnAdapter(ClientConnectionManager mgr,
                                    OperatedClientConnection conn)
Creates a new connection adapter. The adapter is initially not marked as reusable.

Parameters:
mgr - the connection manager, or null
conn - the connection to wrap, or null
Method Detail

assertWrappedConn

protected final void assertWrappedConn()
Asserts that there is a wrapped connection to delegate to.

Throws:
java.lang.IllegalStateException - if there is no wrapped connection

isOpen

public boolean isOpen()
Specified by:
isOpen in interface org.apache.http.HttpConnection

isStale

public boolean isStale()
Specified by:
isStale in interface org.apache.http.HttpConnection

setSocketTimeout

public void setSocketTimeout(int timeout)
Specified by:
setSocketTimeout in interface org.apache.http.HttpConnection

getSocketTimeout

public int getSocketTimeout()
Specified by:
getSocketTimeout in interface org.apache.http.HttpConnection

getMetrics

public org.apache.http.HttpConnectionMetrics getMetrics()
Specified by:
getMetrics in interface org.apache.http.HttpConnection

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface org.apache.http.HttpClientConnection
Throws:
java.io.IOException

isResponseAvailable

public boolean isResponseAvailable(int timeout)
                            throws java.io.IOException
Specified by:
isResponseAvailable in interface org.apache.http.HttpClientConnection
Throws:
java.io.IOException

receiveResponseEntity

public void receiveResponseEntity(org.apache.http.HttpResponse response)
                           throws org.apache.http.HttpException,
                                  java.io.IOException
Specified by:
receiveResponseEntity in interface org.apache.http.HttpClientConnection
Throws:
org.apache.http.HttpException
java.io.IOException

receiveResponseHeader

public org.apache.http.HttpResponse receiveResponseHeader()
                                                   throws org.apache.http.HttpException,
                                                          java.io.IOException
Specified by:
receiveResponseHeader in interface org.apache.http.HttpClientConnection
Throws:
org.apache.http.HttpException
java.io.IOException

sendRequestEntity

public void sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest request)
                       throws org.apache.http.HttpException,
                              java.io.IOException
Specified by:
sendRequestEntity in interface org.apache.http.HttpClientConnection
Throws:
org.apache.http.HttpException
java.io.IOException

sendRequestHeader

public void sendRequestHeader(org.apache.http.HttpRequest request)
                       throws org.apache.http.HttpException,
                              java.io.IOException
Specified by:
sendRequestHeader in interface org.apache.http.HttpClientConnection
Throws:
org.apache.http.HttpException
java.io.IOException

getLocalAddress

public java.net.InetAddress getLocalAddress()
Specified by:
getLocalAddress in interface org.apache.http.HttpInetConnection

getLocalPort

public int getLocalPort()
Specified by:
getLocalPort in interface org.apache.http.HttpInetConnection

getRemoteAddress

public java.net.InetAddress getRemoteAddress()
Specified by:
getRemoteAddress in interface org.apache.http.HttpInetConnection

getRemotePort

public int getRemotePort()
Specified by:
getRemotePort in interface org.apache.http.HttpInetConnection

isSecure

public boolean isSecure()
Description copied from interface: ManagedClientConnection
Indicates whether this connection is secure. The return value is well-defined only while the connection is open. It may change even while the connection is open.

Specified by:
isSecure in interface ManagedClientConnection
Returns:
true if this connection is secure, false otherwise

getSSLSession

public javax.net.ssl.SSLSession getSSLSession()
Description copied from interface: ManagedClientConnection
Obtains the SSL session of the underlying connection, if any. If this connection is open, and the underlying socket is an SSLSocket, the SSL session of that socket is obtained. This is a potentially blocking operation.
Note: Whether the underlying socket is an SSL socket can not necessarily be determined via ManagedClientConnection.isSecure(). Plain sockets may be considered secure, for example if they are connected to a known host in the same network segment. On the other hand, SSL sockets may be considered insecure, for example depending on the chosen cipher suite.

Specified by:
getSSLSession in interface ManagedClientConnection
Returns:
the underlying SSL session if available, null otherwise

markReusable

public void markReusable()
Description copied from interface: ManagedClientConnection
Marks this connection as being in a reusable communication state. The checkpoints for reuseable communication states (in the absence of pipelining) are before sending a request and after receiving the response in it's entirety. The connection will automatically clear the checkpoint when used for communication. A call to this method indicates that the next checkpoint has been reached.
A reusable communication state is necessary but not sufficient for the connection to be reused. A route mismatch, the connection being closed, or other circumstances might prevent reuse.

Specified by:
markReusable in interface ManagedClientConnection

unmarkReusable

public void unmarkReusable()
Description copied from interface: ManagedClientConnection
Marks this connection as not being in a reusable state. This can be used immediately before releasing this connection to prevent it's reuse. Reasons for preventing reuse include error conditions and the evaluation of a reuse strategy.
Note: It is not necessary to call here before writing to or reading from this connection. Communication attempts will automatically unmark the state as non-reusable. It can then be switched back using markReusable.

Specified by:
unmarkReusable in interface ManagedClientConnection

isMarkedReusable

public boolean isMarkedReusable()
Description copied from interface: ManagedClientConnection
Indicates whether this connection is in a reusable communication state. See markReusable and unmarkReusable for details.

Specified by:
isMarkedReusable in interface ManagedClientConnection
Returns:
true if this connection is marked as being in a reusable communication state, false otherwise

releaseConnection

public void releaseConnection()
Description copied from interface: ConnectionReleaseTrigger
Releases the connection with the option of keep-alive. This is a "graceful" release and may cause IO operations for consuming the remainder of a response entity. Use abortConnection for a hard release.

Specified by:
releaseConnection in interface ConnectionReleaseTrigger

abortConnection

public void abortConnection()
Description copied from interface: ConnectionReleaseTrigger
Releases the connection without the option of keep-alive. This is a "hard" release that implies a shutdown of the connection. Use releaseConnection for a graceful release.

Specified by:
abortConnection in interface ConnectionReleaseTrigger


Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.