HttpAsyncRequestExecutor and HttpAsyncRequester@Deprecated @Contract(threading=SAFE_CONDITIONAL) public class ThrottlingHttpClientHandler extends NHttpHandlerBase implements NHttpClientHandler
HttpRequestExecutionHandler.handleResponse(HttpResponse, HttpContext)
method will fire immediately when a message is received. The protocol handler
delegate the task of processing requests and generating response content to
an Executor, which is expected to perform those tasks using
dedicated worker threads in order to avoid blocking the I/O thread.
Usually throttling protocol handlers need only a modest number of worker threads, much fewer than the number of concurrent connections. If the length of the message is smaller or about the size of the shared content buffer worker thread will just store content in the buffer and terminate almost immediately without blocking. The I/O dispatch thread in its turn will take care of sending out the buffered content asynchronously. The worker thread will have to block only when processing large messages and the shared buffer fills up. It is generally advisable to allocate shared buffers of a size of an average content body for optimal performance.
The following parameters can be used to customize the behavior of this class:
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
ThrottlingHttpClientHandler.ClientConnState
Deprecated.
|
| Modifier and Type | Field and Description |
|---|---|
private int |
bufsize
Deprecated.
|
protected HttpRequestExecutionHandler |
execHandler
Deprecated.
|
protected java.util.concurrent.Executor |
executor
Deprecated.
|
allocator, CONN_STATE, connStrategy, eventListener, httpProcessor, params| Constructor and Description |
|---|
ThrottlingHttpClientHandler(HttpProcessor httpProcessor,
HttpRequestExecutionHandler execHandler,
ConnectionReuseStrategy connStrategy,
ByteBufferAllocator allocator,
java.util.concurrent.Executor executor,
HttpParams params)
Deprecated.
|
ThrottlingHttpClientHandler(HttpProcessor httpProcessor,
HttpRequestExecutionHandler execHandler,
ConnectionReuseStrategy connStrategy,
java.util.concurrent.Executor executor,
HttpParams params)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
void |
closed(NHttpClientConnection conn)
Deprecated.
Triggered when the connection is closed.
|
void |
connected(NHttpClientConnection conn,
java.lang.Object attachment)
Deprecated.
Triggered when a new outgoing connection is created.
|
private void |
continueRequest(NHttpClientConnection conn,
ThrottlingHttpClientHandler.ClientConnState connState)
Deprecated.
|
void |
exception(NHttpClientConnection conn,
HttpException ex)
Deprecated.
Triggered when an HTTP protocol violation occurs while receiving
an HTTP response.
|
void |
exception(NHttpClientConnection conn,
java.io.IOException ex)
Deprecated.
Triggered when an I/O error occurs while reading from or writing
to the underlying channel.
|
private void |
handleResponse(HttpResponse response,
ThrottlingHttpClientHandler.ClientConnState connState,
NHttpClientConnection conn)
Deprecated.
|
private void |
initialize(NHttpClientConnection conn,
java.lang.Object attachment)
Deprecated.
|
void |
inputReady(NHttpClientConnection conn,
ContentDecoder decoder)
Deprecated.
Triggered when the underlying channel is ready for reading a
new portion of the response entity through the corresponding
content decoder.
|
void |
outputReady(NHttpClientConnection conn,
ContentEncoder encoder)
Deprecated.
Triggered when the underlying channel is ready for writing a next portion
of the request entity through the corresponding content encoder.
|
void |
requestReady(NHttpClientConnection conn)
Deprecated.
Triggered when the connection is ready to accept a new HTTP request.
|
void |
responseReceived(NHttpClientConnection conn)
Deprecated.
Triggered when an HTTP response is received.
|
private void |
sendRequestBody(HttpEntityEnclosingRequest request,
ThrottlingHttpClientHandler.ClientConnState connState,
NHttpClientConnection conn)
Deprecated.
|
void |
timeout(NHttpClientConnection conn)
Deprecated.
Triggered when no input is detected on this connection over the
maximum period of inactivity.
|
canResponseHaveBody, closeConnection, getParams, handleTimeout, setEventListener, shutdownConnectionprotected HttpRequestExecutionHandler execHandler
protected final java.util.concurrent.Executor executor
private final int bufsize
public ThrottlingHttpClientHandler(HttpProcessor httpProcessor, HttpRequestExecutionHandler execHandler, ConnectionReuseStrategy connStrategy, ByteBufferAllocator allocator, java.util.concurrent.Executor executor, HttpParams params)
public ThrottlingHttpClientHandler(HttpProcessor httpProcessor, HttpRequestExecutionHandler execHandler, ConnectionReuseStrategy connStrategy, java.util.concurrent.Executor executor, HttpParams params)
public void connected(NHttpClientConnection conn, java.lang.Object attachment)
NHttpClientHandlerconnected in interface NHttpClientHandlerconn - new outgoing HTTP connection.attachment - an object that was attached to the session requestpublic void closed(NHttpClientConnection conn)
NHttpClientHandlerclosed in interface NHttpClientHandlerconn - closed HTTP connection.public void exception(NHttpClientConnection conn, HttpException ex)
NHttpClientHandlerexception in interface NHttpClientHandlerconn - HTTP connection that caused an HTTP protocol violationex - HTTP protocol violation exceptionpublic void exception(NHttpClientConnection conn, java.io.IOException ex)
NHttpClientHandlerexception in interface NHttpClientHandlerconn - HTTP connection that caused an I/O errorex - I/O exceptionpublic void requestReady(NHttpClientConnection conn)
NHttpClientHandlerrequestReady in interface NHttpClientHandlerconn - HTTP connection that is ready to accept a new HTTP request.NHttpClientConnectionpublic void outputReady(NHttpClientConnection conn, ContentEncoder encoder)
NHttpClientHandler
If the content producer is unable to generate the outgoing content,
output event notifications can be temporarily suspended using
IOControl interface.
outputReady in interface NHttpClientHandlerconn - HTTP connection that can accommodate a new portion
of the outgoing request content.encoder - The content encoder to use to write content.NHttpClientConnection,
ContentEncoder,
IOControlpublic void responseReceived(NHttpClientConnection conn)
NHttpClientHandler
If the response received encloses a response entity this method will
be followed by a series of
NHttpClientHandler.inputReady(NHttpClientConnection, ContentDecoder) calls
to transfer the response content.
responseReceived in interface NHttpClientHandlerconn - HTTP connection that contains an HTTP responseNHttpClientConnectionpublic void inputReady(NHttpClientConnection conn, ContentDecoder decoder)
NHttpClientHandler
If the content consumer is unable to process the incoming content,
input event notifications can be temporarily suspended using
IOControl interface.
inputReady in interface NHttpClientHandlerconn - HTTP connection that can produce a new portion of the
incoming response content.decoder - The content decoder to use to read content.NHttpClientConnection,
ContentDecoder,
IOControlpublic void timeout(NHttpClientConnection conn)
NHttpClientHandlertimeout in interface NHttpClientHandlerconn - HTTP connection that caused timeout condition.private void initialize(NHttpClientConnection conn, java.lang.Object attachment)
private void continueRequest(NHttpClientConnection conn, ThrottlingHttpClientHandler.ClientConnState connState) throws java.io.IOException
java.io.IOExceptionprivate void sendRequestBody(HttpEntityEnclosingRequest request, ThrottlingHttpClientHandler.ClientConnState connState, NHttpClientConnection conn) throws java.io.IOException
java.io.IOException - - not thrown currentlyprivate void handleResponse(HttpResponse response, ThrottlingHttpClientHandler.ClientConnState connState, NHttpClientConnection conn)