public class

NHttpConnectionBase

extends Object
implements HttpInetConnection NHttpConnection SessionBufferStatus
java.lang.Object
   ↳ org.apache.http.impl.nio.NHttpConnectionBase
Known Direct Subclasses

Class Overview

This class serves as a base for all NHttpConnection implementations and implements functionality common to both client and server HTTP connections.

The following parameters can be used to customize the behavior of this class:

Summary

[Expand]
Inherited Constants
From interface org.apache.http.nio.NHttpConnection
Fields
protected final HttpConnectionMetricsImpl connMetrics
protected ContentDecoder contentDecoder
protected ContentEncoder contentEncoder
protected final HttpContext context
protected boolean hasBufferedInput
protected boolean hasBufferedOutput
protected final HttpTransportMetricsImpl inTransportMetrics
protected final SessionInputBufferImpl inbuf
protected final ContentLengthStrategy incomingContentStrategy
protected final HttpTransportMetricsImpl outTransportMetrics
protected final SessionOutputBufferImpl outbuf
protected final ContentLengthStrategy outgoingContentStrategy
protected HttpRequest request
protected HttpResponse response
protected IOSession session
protected int status
Public Constructors
NHttpConnectionBase(IOSession session, ByteBufferAllocator allocator, HttpParams params)
Creates a new instance of this class given the underlying I/O session.
Public Methods
void close()
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()
int getSocketTimeout()
int getStatus()
Returns status of the connection:

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()
boolean isStale()
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.
Protected Methods
void assertNotClosed()
Assets if the connection is still open.
HttpConnectionMetricsImpl createConnectionMetrics(HttpTransportMetrics inTransportMetric, HttpTransportMetrics outTransportMetric)
ContentDecoder createContentDecoder(long len, ReadableByteChannel channel, SessionInputBuffer buffer, HttpTransportMetricsImpl metrics)
Factory method for ContentDecoder instances.
ContentEncoder createContentEncoder(long len, WritableByteChannel channel, SessionOutputBuffer buffer, HttpTransportMetricsImpl metrics)
Factory method for ContentEncoder instances.
HttpTransportMetricsImpl createTransportMetrics()
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.
void prepareEncoder(HttpMessage message)
Initializes a specific ContentEncoder implementation based on the properties of the given HttpMessage.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.http.HttpConnection
From interface org.apache.http.HttpInetConnection
From interface org.apache.http.nio.IOControl
From interface org.apache.http.nio.NHttpConnection
From interface org.apache.http.nio.reactor.SessionBufferStatus

Fields

protected final HttpConnectionMetricsImpl connMetrics

protected ContentDecoder contentDecoder

protected ContentEncoder contentEncoder

protected final HttpContext context

protected boolean hasBufferedInput

protected boolean hasBufferedOutput

protected final HttpTransportMetricsImpl inTransportMetrics

protected final SessionInputBufferImpl inbuf

protected final ContentLengthStrategy incomingContentStrategy

protected final HttpTransportMetricsImpl outTransportMetrics

protected final SessionOutputBufferImpl outbuf

protected final ContentLengthStrategy outgoingContentStrategy

protected HttpRequest request

protected HttpResponse response

protected IOSession session

protected int status

Public Constructors

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

Creates a new instance of this class given the underlying I/O session.

Parameters
session the underlying I/O session.
allocator byte buffer allocator.
params HTTP parameters.

Public Methods

public void close ()

Throws
IOException

public HttpContext getContext ()

Returns an HTTP execution context associated with this connection.

Returns
  • HTTP context

public HttpRequest getHttpRequest ()

Returns the current HTTP request if one is being received / transmitted. Otherwise returns null.

Returns
  • HTTP request, if available, null otherwise.

public HttpResponse getHttpResponse ()

Returns the current HTTP response if one is being received / transmitted. Otherwise returns null.

Returns
  • HTTP response, if available, null otherwise.

public InetAddress getLocalAddress ()

public int getLocalPort ()

public HttpConnectionMetrics getMetrics ()

public InetAddress getRemoteAddress ()

public int getRemotePort ()

public int getSocketTimeout ()

public int getStatus ()

Returns status of the connection:

ACTIVE: connection is active.

CLOSING: connection is being closed.

CLOSED: connection has been closed.

Returns
  • connection status.

public boolean hasBufferedInput ()

Determines if the session input buffer contains data.

Returns
  • true if the session input buffer contains data, false otherwise.

public boolean hasBufferedOutput ()

Determines if the session output buffer contains data.

Returns
  • true if the session output buffer contains data, false otherwise.

public boolean isOpen ()

public boolean isStale ()

public void requestInput ()

Requests event notifications to be triggered when the underlying channel is ready for input operations.

public void requestOutput ()

Requests event notifications to be triggered when the underlying channel is ready for output operations.

public void setSocketTimeout (int timeout)

public void shutdown ()

Shuts down the underlying channel.

Throws
IOException

public void suspendInput ()

Suspends event notifications about the underlying channel being ready for input operations.

public void suspendOutput ()

Suspends event notifications about the underlying channel being ready for output operations.

Protected Methods

protected void assertNotClosed ()

Assets if the connection is still open.

Throws
ConnectionClosedException in case the connection has already been closed.

protected HttpConnectionMetricsImpl createConnectionMetrics (HttpTransportMetrics inTransportMetric, HttpTransportMetrics outTransportMetric)

protected ContentDecoder createContentDecoder (long len, ReadableByteChannel channel, SessionInputBuffer buffer, HttpTransportMetricsImpl metrics)

Factory method for ContentDecoder instances.

Parameters
len content length, if known, CHUNKED or IDENTITY, if unknown.
channel the session channel.
buffer the session buffer.
metrics transport metrics.
Returns
  • content decoder.

protected ContentEncoder createContentEncoder (long len, WritableByteChannel channel, SessionOutputBuffer buffer, HttpTransportMetricsImpl metrics)

Factory method for ContentEncoder instances.

Parameters
len content length, if known, CHUNKED or IDENTITY, if unknown.
channel the session channel.
buffer the session buffer.
metrics transport metrics.
Returns
  • content encoder.

protected HttpTransportMetricsImpl createTransportMetrics ()

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.

Parameters
message the HTTP message.
Returns
  • HTTP entity.
Throws
HttpException in case of an HTTP protocol violation.

protected void prepareEncoder (HttpMessage message)

Initializes a specific ContentEncoder implementation based on the properties of the given HttpMessage.

Parameters
message the HTTP message.
Throws
HttpException in case of an HTTP protocol violation.