org.apache.http.impl.nio
Class NHttpConnectionBase

java.lang.Object
  extended by org.apache.http.impl.nio.NHttpConnectionBase
All Implemented Interfaces:
HttpConnection, HttpInetConnection, IOControl, NHttpConnection, SessionBufferStatus
Direct Known Subclasses:
DefaultNHttpClientConnection, DefaultNHttpServerConnection

public class NHttpConnectionBase
extends java.lang.Object
implements NHttpConnection, HttpInetConnection, SessionBufferStatus


Field Summary
protected  HttpConnectionMetricsImpl connMetrics
           
protected  ContentDecoder contentDecoder
           
protected  ContentEncoder contentEncoder
           
protected  HttpContext context
           
protected  boolean hasBufferedInput
           
protected  boolean hasBufferedOutput
           
protected  SessionInputBufferImpl inbuf
           
protected  ContentLengthStrategy incomingContentStrategy
           
protected  HttpTransportMetricsImpl inTransportMetrics
           
protected  SessionOutputBufferImpl outbuf
           
protected  ContentLengthStrategy outgoingContentStrategy
           
protected  HttpTransportMetricsImpl outTransportMetrics
           
protected  HttpRequest request
           
protected  HttpResponse response
           
protected  IOSession session
           
protected  int status
           
 
Fields inherited from interface org.apache.http.nio.NHttpConnection
ACTIVE, CLOSED, CLOSING
 
Constructor Summary
NHttpConnectionBase(IOSession session, ByteBufferAllocator allocator, HttpParams params)
           
 
Method Summary
protected  void assertNotClosed()
           
 void close()
          Closes this connection gracefully.
 HttpContext getContext()
          Returns an HTTP execution context associated with this connection.
 HttpRequest getHttpRequest()
          Returns the current HTTP request if one is being received / transmitted.
 HttpResponse getHttpResponse()
          Returns the current HTTP response if one is being received / transmitted.
 java.net.InetAddress getLocalAddress()
           
 int getLocalPort()
           
 HttpConnectionMetrics getMetrics()
          Returns a collection of connection metrcis
 java.net.InetAddress getRemoteAddress()
           
 int getRemotePort()
           
 int getSocketTimeout()
          Returns the socket timeout value.
 int getStatus()
           
 boolean hasBufferedInput()
           
 boolean hasBufferedOutput()
           
 boolean isOpen()
          Checks if this connection is open.
 boolean isStale()
          Checks whether this connection has gone down.
protected  HttpEntity prepareDecoder(HttpMessage message)
           
protected  void prepareEncoder(HttpMessage message)
           
 void requestInput()
          Requests event notifications to be triggered when the underlying channel is ready for input oprtations.
 void requestOutput()
          Requests event notifications to be triggered when the underlying channel is ready for output oprtations.
 void setSocketTimeout(int timeout)
          Sets the socket timeout value.
 void shutdown()
          Force-closes this connection.
 void suspendInput()
          Suspends event notifications about the underlying channel being ready for input operations.
 void suspendOutput()
          Suspends event notifications about the underlying channel being ready for output operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected final HttpContext context

incomingContentStrategy

protected final ContentLengthStrategy incomingContentStrategy

outgoingContentStrategy

protected final ContentLengthStrategy outgoingContentStrategy

inbuf

protected final SessionInputBufferImpl inbuf

outbuf

protected final SessionOutputBufferImpl outbuf

inTransportMetrics

protected final HttpTransportMetricsImpl inTransportMetrics

outTransportMetrics

protected final HttpTransportMetricsImpl outTransportMetrics

connMetrics

protected final HttpConnectionMetricsImpl connMetrics

session

protected IOSession session

contentDecoder

protected volatile ContentDecoder contentDecoder

hasBufferedInput

protected volatile boolean hasBufferedInput

contentEncoder

protected volatile ContentEncoder contentEncoder

hasBufferedOutput

protected volatile boolean hasBufferedOutput

request

protected volatile HttpRequest request

response

protected volatile HttpResponse response

status

protected volatile int status
Constructor Detail

NHttpConnectionBase

public NHttpConnectionBase(IOSession session,
                           ByteBufferAllocator allocator,
                           HttpParams params)
Method Detail

getStatus

public int getStatus()
Specified by:
getStatus in interface NHttpConnection

getContext

public HttpContext getContext()
Description copied from interface: NHttpConnection
Returns an HTTP execution context associated with this connection.

Specified by:
getContext in interface NHttpConnection
Returns:
HTTP context

getHttpRequest

public HttpRequest getHttpRequest()
Description copied from interface: NHttpConnection
Returns the current HTTP request if one is being received / transmitted. Otherwise returns null.

Specified by:
getHttpRequest in interface NHttpConnection
Returns:
an HTTP request if available. Otherwise returns null.

getHttpResponse

public HttpResponse getHttpResponse()
Description copied from interface: NHttpConnection
Returns the current HTTP response if one is being received / transmitted. Otherwise returns null.

Specified by:
getHttpResponse in interface NHttpConnection
Returns:
an HTTP response if available. Otherwise returns null.

requestInput

public void requestInput()
Description copied from interface: IOControl
Requests event notifications to be triggered when the underlying channel is ready for input oprtations.

Specified by:
requestInput in interface IOControl

requestOutput

public void requestOutput()
Description copied from interface: IOControl
Requests event notifications to be triggered when the underlying channel is ready for output oprtations.

Specified by:
requestOutput in interface IOControl

suspendInput

public void suspendInput()
Description copied from interface: IOControl
Suspends event notifications about the underlying channel being ready for input operations.

Specified by:
suspendInput in interface IOControl

suspendOutput

public void suspendOutput()
Description copied from interface: IOControl
Suspends event notifications about the underlying channel being ready for output operations.

Specified by:
suspendOutput in interface IOControl

prepareDecoder

protected HttpEntity prepareDecoder(HttpMessage message)
                             throws HttpException
Throws:
HttpException

prepareEncoder

protected void prepareEncoder(HttpMessage message)
                       throws HttpException
Throws:
HttpException

hasBufferedInput

public boolean hasBufferedInput()
Specified by:
hasBufferedInput in interface SessionBufferStatus

hasBufferedOutput

public boolean hasBufferedOutput()
Specified by:
hasBufferedOutput in interface SessionBufferStatus

assertNotClosed

protected void assertNotClosed()
                        throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Description copied from interface: HttpConnection
Closes this connection gracefully. This method will attempt to flush the transmitter's internal buffer prior to closing the underlying socket. This method MUST NOT be called from a different thread to force shutdown of the connection. Use shutdown instead.

Specified by:
close in interface HttpConnection
Throws:
java.io.IOException

isOpen

public boolean isOpen()
Description copied from interface: HttpConnection
Checks if this connection is open.

Specified by:
isOpen in interface HttpConnection
Returns:
true if it is open, false if it is closed.

isStale

public boolean isStale()
Description copied from interface: HttpConnection
Checks whether this connection has gone down. Network connections may get closed during some time of inactivity for several reasons. The next time a read is attempted on such a connection it will throw an IOException. This method tries to alleviate this inconvenience by trying to find out if a connection is still usable. Implementations may do that by attempting a read with a very small timeout. Thus this method may block for a small amount of time before returning a result. It is therefore an expensive operation.

Specified by:
isStale in interface HttpConnection
Returns:
true if attempts to use this connection are likely to succeed, or false if they are likely to fail and this connection should be closed

getLocalAddress

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

getLocalPort

public int getLocalPort()
Specified by:
getLocalPort in interface HttpInetConnection

getRemoteAddress

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

getRemotePort

public int getRemotePort()
Specified by:
getRemotePort in interface HttpInetConnection

setSocketTimeout

public void setSocketTimeout(int timeout)
Description copied from interface: HttpConnection
Sets the socket timeout value.

Specified by:
setSocketTimeout in interface HttpConnection
Parameters:
timeout - timeout value in milliseconds

getSocketTimeout

public int getSocketTimeout()
Description copied from interface: HttpConnection
Returns the socket timeout value.

Specified by:
getSocketTimeout in interface HttpConnection
Returns:
positive value in milliseconds if a timeout is set, 0 if timeout is disabled or -1 if timeout is undefined.

shutdown

public void shutdown()
              throws java.io.IOException
Description copied from interface: HttpConnection
Force-closes this connection. This is the only method of a connection which may be called from a different thread to terminate the connection. This method will not attempt to flush the transmitter's internal buffer prior to closing the underlying socket.

Specified by:
shutdown in interface HttpConnection
Specified by:
shutdown in interface IOControl
Throws:
java.io.IOException

getMetrics

public HttpConnectionMetrics getMetrics()
Description copied from interface: HttpConnection
Returns a collection of connection metrcis

Specified by:
getMetrics in interface HttpConnection
Returns:
HttpConnectionMetrics


Copyright © 2005-2008 Apache Software Foundation. All Rights Reserved.