@NotThreadSafe public class NHttpConnectionBase extends java.lang.Object implements NHttpConnection, HttpInetConnection, SessionBufferStatus, SocketAccessor
NHttpConnection implementations and provides
functionality common to both client and server HTTP connections.| 限定符和类型 | 字段和说明 |
|---|---|
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 java.net.SocketAddress |
remote |
protected HttpRequest |
request |
protected HttpResponse |
response |
protected IOSession |
session |
protected int |
status |
ACTIVE, CLOSED, CLOSING| 限定符 | 构造器和说明 |
|---|---|
|
NHttpConnectionBase(IOSession session,
ByteBufferAllocator allocator,
HttpParams params)
|
protected |
NHttpConnectionBase(IOSession session,
int buffersize,
int fragmentSizeHint,
ByteBufferAllocator allocator,
java.nio.charset.CharsetDecoder chardecoder,
java.nio.charset.CharsetEncoder charencoder,
ContentLengthStrategy incomingContentStrategy,
ContentLengthStrategy outgoingContentStrategy)
Creates new instance NHttpConnectionBase given the underlying I/O session.
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
assertNotClosed()
Assets if the connection is still open.
|
protected void |
bind(IOSession session)
Binds the connection to a different
IOSession. |
void |
close()
Closes this connection gracefully.
|
protected HttpConnectionMetricsImpl |
createConnectionMetrics(HttpTransportMetrics inTransportMetric,
HttpTransportMetrics outTransportMetric)
已过时。
(4.3) use decorator to add additional metrics.
|
protected ContentDecoder |
createContentDecoder(long len,
java.nio.channels.ReadableByteChannel channel,
SessionInputBuffer buffer,
HttpTransportMetricsImpl metrics)
Factory method for
ContentDecoder instances. |
protected ContentEncoder |
createContentEncoder(long len,
java.nio.channels.WritableByteChannel channel,
SessionOutputBuffer buffer,
HttpTransportMetricsImpl metrics)
Factory method for
ContentEncoder instances. |
protected ContentLengthStrategy |
createIncomingContentStrategy()
已过时。
(4.3) use constructor.
|
protected ContentLengthStrategy |
createOutgoingContentStrategy()
已过时。
(4.3) use constructor.
|
protected HttpTransportMetricsImpl |
createTransportMetrics()
已过时。
(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.
|
java.net.InetAddress |
getLocalAddress() |
int |
getLocalPort() |
HttpConnectionMetrics |
getMetrics()
Returns a collection of connection metrics.
|
java.net.InetAddress |
getRemoteAddress() |
int |
getRemotePort() |
java.net.Socket |
getSocket()
Return the underlying socket
|
int |
getSocketTimeout()
Returns the socket timeout value.
|
int |
getStatus()
Returns status of the connection:
NHttpConnection.ACTIVE: connection is active. |
boolean |
hasBufferedInput()
Determines if the session input buffer contains data.
|
boolean |
hasBufferedOutput()
Determines if the session output buffer contains data.
|
boolean |
isOpen()
Checks if this connection is open.
|
boolean |
isStale()
Checks whether this connection has gone down.
|
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)
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.
|
java.lang.String |
toString() |
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 java.net.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
@Deprecated public NHttpConnectionBase(IOSession session, ByteBufferAllocator allocator, HttpParams params)
session - the underlying I/O session.allocator - byte buffer allocator.params - HTTP parameters.protected NHttpConnectionBase(IOSession session, int buffersize, int fragmentSizeHint, ByteBufferAllocator allocator, java.nio.charset.CharsetDecoder chardecoder, java.nio.charset.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 category cast will be used for byte to char conversion.charencoder - encoder to be used for encoding HTTP protocol elements.
If null simple category 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.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 在接口中 NHttpConnectionpublic HttpContext getContext()
NHttpConnectiongetContext 在接口中 NHttpConnectionpublic HttpRequest getHttpRequest()
NHttpConnectionnull.getHttpRequest 在接口中 NHttpConnectionnull otherwise.public HttpResponse getHttpResponse()
NHttpConnectiongetHttpResponse 在接口中 NHttpConnectionnull otherwise.public void requestInput()
IOControlrequestInput 在接口中 IOControlpublic void requestOutput()
IOControlrequestOutput 在接口中 IOControlpublic void suspendInput()
IOControlsuspendInput 在接口中 IOControlpublic void suspendOutput()
IOControlsuspendOutput 在接口中 IOControlprotected 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, java.nio.channels.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, java.nio.channels.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()
SessionBufferStatushasBufferedInput 在接口中 SessionBufferStatustrue if the session input buffer contains data,
false otherwise.public boolean hasBufferedOutput()
SessionBufferStatushasBufferedOutput 在接口中 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 java.io.IOException
HttpConnectionshutdown instead.close 在接口中 HttpConnectionclose 在接口中 java.io.Closeableclose 在接口中 java.lang.AutoCloseablejava.io.IOExceptionpublic boolean isOpen()
HttpConnectionisOpen 在接口中 HttpConnectionpublic boolean isStale()
HttpConnectionisStale 在接口中 HttpConnectiontrue if attempts to use this connection are
likely to succeed, or false if they are likely
to fail and this connection should be closedpublic java.net.InetAddress getLocalAddress()
getLocalAddress 在接口中 HttpInetConnectionpublic int getLocalPort()
getLocalPort 在接口中 HttpInetConnectionpublic java.net.InetAddress getRemoteAddress()
getRemoteAddress 在接口中 HttpInetConnectionpublic int getRemotePort()
getRemotePort 在接口中 HttpInetConnectionpublic void setSocketTimeout(int timeout)
HttpConnectionsetSocketTimeout 在接口中 HttpConnectiontimeout - timeout value in millisecondspublic int getSocketTimeout()
HttpConnectiongetSocketTimeout 在接口中 HttpConnection0 if timeout is disabled or -1 if
timeout is undefined.public void shutdown()
throws java.io.IOException
HttpConnectionshutdown 在接口中 HttpConnectionshutdown 在接口中 IOControljava.io.IOExceptionpublic HttpConnectionMetrics getMetrics()
HttpConnectiongetMetrics 在接口中 HttpConnectionpublic java.lang.String toString()
toString 在类中 java.lang.Objectpublic java.net.Socket getSocket()
SocketAccessorgetSocket 在接口中 SocketAccessornull.