|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.http.impl.nio.NHttpConnectionBase
public class NHttpConnectionBase
This class serves as a base for all NHttpConnection implementations and provides
functionality common to both client and server HTTP connections.
| 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 SocketAddress |
remote
|
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)
Deprecated. (4.3) use NHttpConnectionBase(IOSession, int, int, ByteBufferAllocator,
CharsetDecoder, CharsetEncoder, ContentLengthStrategy, ContentLengthStrategy) |
protected |
NHttpConnectionBase(IOSession session,
int buffersize,
int fragmentSizeHint,
ByteBufferAllocator allocator,
CharsetDecoder chardecoder,
CharsetEncoder charencoder,
ContentLengthStrategy incomingContentStrategy,
ContentLengthStrategy outgoingContentStrategy)
Creates new instance NHttpConnectionBase given the underlying I/O session. |
protected |
NHttpConnectionBase(IOSession session,
int buffersize,
int fragmentSizeHint,
ByteBufferAllocator allocator,
CharsetDecoder chardecoder,
CharsetEncoder charencoder,
MessageConstraints constraints,
ContentLengthStrategy incomingContentStrategy,
ContentLengthStrategy outgoingContentStrategy)
Creates new instance NHttpConnectionBase given the underlying I/O session. |
| Method Summary | |
|---|---|
protected void |
assertNotClosed()
Assets if the connection is still open. |
protected void |
bind(IOSession session)
Binds the connection to a different IOSession. |
void |
close()
|
protected HttpConnectionMetricsImpl |
createConnectionMetrics(HttpTransportMetrics inTransportMetric,
HttpTransportMetrics outTransportMetric)
Deprecated. (4.3) use decorator to add additional metrics. |
protected ContentDecoder |
createContentDecoder(long len,
ReadableByteChannel channel,
SessionInputBuffer buffer,
HttpTransportMetricsImpl metrics)
Factory method for ContentDecoder instances. |
protected ContentEncoder |
createContentEncoder(long len,
WritableByteChannel channel,
SessionOutputBuffer buffer,
HttpTransportMetricsImpl metrics)
Factory method for ContentEncoder instances. |
protected ContentLengthStrategy |
createIncomingContentStrategy()
Deprecated. (4.3) use constructor. |
protected ContentLengthStrategy |
createOutgoingContentStrategy()
Deprecated. (4.3) use constructor. |
protected HttpTransportMetricsImpl |
createTransportMetrics()
Deprecated. (4.3) no longer used. |
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. |
InetAddress |
getLocalAddress()
|
int |
getLocalPort()
|
HttpConnectionMetrics |
getMetrics()
|
InetAddress |
getRemoteAddress()
|
int |
getRemotePort()
|
Socket |
getSocket()
Return the underlying socket |
int |
getSocketTimeout()
|
int |
getStatus()
Returns status of the connection: |
boolean |
hasBufferedInput()
Determines if the session input buffer contains data. |
boolean |
hasBufferedOutput()
Determines if the session output buffer contains data. |
boolean |
isOpen()
|
boolean |
isStale()
|
protected HttpEntity |
prepareDecoder(HttpMessage message)
Initializes a specific ContentDecoder implementation based on the
properties of the given HttpMessage and generates an instance of
HttpEntity matching the properties of the content decoder. |
protected void |
prepareEncoder(HttpMessage message)
Initializes a specific ContentEncoder implementation based on the
properties of the given HttpMessage. |
void |
requestInput()
Requests event notifications to be triggered when the underlying channel is ready for input operations. |
void |
requestOutput()
Requests event notifications to be triggered when the underlying channel is ready for output operations. |
void |
setSocketTimeout(int timeout)
|
void |
shutdown()
Shuts down the underlying channel. |
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. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected final ContentLengthStrategy incomingContentStrategy
protected final ContentLengthStrategy outgoingContentStrategy
protected final SessionInputBufferImpl inbuf
protected final SessionOutputBufferImpl outbuf
protected final HttpTransportMetricsImpl inTransportMetrics
protected final HttpTransportMetricsImpl outTransportMetrics
protected final HttpConnectionMetricsImpl connMetrics
protected HttpContext context
protected IOSession session
protected SocketAddress remote
protected volatile ContentDecoder contentDecoder
protected volatile boolean hasBufferedInput
protected volatile ContentEncoder contentEncoder
protected volatile boolean hasBufferedOutput
protected volatile HttpRequest request
protected volatile HttpResponse response
protected volatile int status
| Constructor Detail |
|---|
@Deprecated
public NHttpConnectionBase(IOSession session,
ByteBufferAllocator allocator,
HttpParams params)
NHttpConnectionBase(IOSession, int, int, ByteBufferAllocator,
CharsetDecoder, CharsetEncoder, ContentLengthStrategy, ContentLengthStrategy)
session - the underlying I/O session.allocator - byte buffer allocator.params - HTTP parameters.
protected NHttpConnectionBase(IOSession session,
int buffersize,
int fragmentSizeHint,
ByteBufferAllocator allocator,
CharsetDecoder chardecoder,
CharsetEncoder charencoder,
MessageConstraints constraints,
ContentLengthStrategy incomingContentStrategy,
ContentLengthStrategy outgoingContentStrategy)
session - the underlying I/O session.buffersize - buffer size. Must be a positive number.fragmentSizeHint - fragment size hint.allocator - memory allocator.
If null HeapByteBufferAllocator.INSTANCE
will be used.chardecoder - decoder to be used for decoding HTTP protocol elements.
If null simple type cast will be used for byte to char conversion.charencoder - encoder to be used for encoding HTTP protocol elements.
If null simple type cast will be used for char to byte conversion.constraints - Message constraints. If null
MessageConstraints.DEFAULT will be used.incomingContentStrategy - incoming content length strategy. If null
LaxContentLengthStrategy.INSTANCE will be used.outgoingContentStrategy - outgoing content length strategy. If null
StrictContentLengthStrategy.INSTANCE will be used.
protected NHttpConnectionBase(IOSession session,
int buffersize,
int fragmentSizeHint,
ByteBufferAllocator allocator,
CharsetDecoder chardecoder,
CharsetEncoder charencoder,
ContentLengthStrategy incomingContentStrategy,
ContentLengthStrategy outgoingContentStrategy)
session - the underlying I/O session.buffersize - buffer size. Must be a positive number.fragmentSizeHint - fragment size hint.allocator - memory allocator.
If null HeapByteBufferAllocator.INSTANCE
will be used.chardecoder - decoder to be used for decoding HTTP protocol elements.
If null simple type cast will be used for byte to char conversion.charencoder - encoder to be used for encoding HTTP protocol elements.
If null simple type cast will be used for char to byte conversion.incomingContentStrategy - incoming content length strategy. If null
LaxContentLengthStrategy.INSTANCE will be used.outgoingContentStrategy - outgoing content length strategy. If null
StrictContentLengthStrategy.INSTANCE will be used.| Method Detail |
|---|
protected void bind(IOSession session)
IOSession. This may be necessary
when the underlying I/O session gets upgraded with SSL/TLS encryption.
@Deprecated protected ContentLengthStrategy createIncomingContentStrategy()
@Deprecated protected ContentLengthStrategy createOutgoingContentStrategy()
@Deprecated protected HttpTransportMetricsImpl createTransportMetrics()
@Deprecated
protected HttpConnectionMetricsImpl createConnectionMetrics(HttpTransportMetrics inTransportMetric,
HttpTransportMetrics outTransportMetric)
public int getStatus()
NHttpConnection
NHttpConnection.ACTIVE: connection is active.
NHttpConnection.CLOSING: connection is being closed.
NHttpConnection.CLOSED: connection has been closed.
getStatus in interface NHttpConnectionpublic HttpContext getContext()
NHttpConnection
getContext in interface NHttpConnectionpublic HttpRequest getHttpRequest()
NHttpConnectionnull.
getHttpRequest in interface NHttpConnectionnull otherwise.public HttpResponse getHttpResponse()
NHttpConnectionnull.
getHttpResponse in interface NHttpConnectionnull otherwise.public void requestInput()
IOControl
requestInput in interface IOControlpublic void requestOutput()
IOControl
requestOutput in interface IOControlpublic void suspendInput()
IOControl
suspendInput in interface IOControlpublic void suspendOutput()
IOControl
suspendOutput in interface IOControl
protected HttpEntity prepareDecoder(HttpMessage message)
throws HttpException
ContentDecoder implementation based on the
properties of the given HttpMessage and generates an instance of
HttpEntity matching the properties of the content decoder.
message - the HTTP message.
HttpException - in case of an HTTP protocol violation.
protected ContentDecoder createContentDecoder(long len,
ReadableByteChannel channel,
SessionInputBuffer buffer,
HttpTransportMetricsImpl metrics)
ContentDecoder instances.
len - content length, if known, ContentLengthStrategy.CHUNKED or
ContentLengthStrategy.IDENTITY, if unknown.channel - the session channel.buffer - the session buffer.metrics - transport metrics.
protected void prepareEncoder(HttpMessage message)
throws HttpException
ContentEncoder implementation based on the
properties of the given HttpMessage.
message - the HTTP message.
HttpException - in case of an HTTP protocol violation.
protected ContentEncoder createContentEncoder(long len,
WritableByteChannel channel,
SessionOutputBuffer buffer,
HttpTransportMetricsImpl metrics)
ContentEncoder instances.
len - content length, if known, ContentLengthStrategy.CHUNKED or
ContentLengthStrategy.IDENTITY, if unknown.channel - the session channel.buffer - the session buffer.metrics - transport metrics.
public boolean hasBufferedInput()
SessionBufferStatus
hasBufferedInput in interface SessionBufferStatustrue if the session input buffer contains data,
false otherwise.public boolean hasBufferedOutput()
SessionBufferStatus
hasBufferedOutput in interface SessionBufferStatustrue if the session output buffer contains data,
false otherwise.
protected void assertNotClosed()
throws ConnectionClosedException
ConnectionClosedException - in case the connection has already
been closed.
public void close()
throws IOException
close in interface Closeableclose in interface HttpConnectionIOExceptionpublic boolean isOpen()
isOpen in interface HttpConnectionpublic boolean isStale()
isStale in interface HttpConnectionpublic InetAddress getLocalAddress()
getLocalAddress in interface HttpInetConnectionpublic int getLocalPort()
getLocalPort in interface HttpInetConnectionpublic InetAddress getRemoteAddress()
getRemoteAddress in interface HttpInetConnectionpublic int getRemotePort()
getRemotePort in interface HttpInetConnectionpublic void setSocketTimeout(int timeout)
setSocketTimeout in interface HttpConnectionpublic int getSocketTimeout()
getSocketTimeout in interface HttpConnection
public void shutdown()
throws IOException
IOControl
shutdown in interface HttpConnectionshutdown in interface IOControlIOException - in an error occurspublic HttpConnectionMetrics getMetrics()
getMetrics in interface HttpConnectionpublic String toString()
toString in class Objectpublic Socket getSocket()
SocketAccessor
getSocket in interface SocketAccessornull.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||