HttpReceiver provides the abstract code to implement the various steps of the receive of HTTP responses.
HttpReceiver maintains a state machine that is updated when the steps of receiving a response are executed.
Subclasses must handle the transport-specific details, for example how to read from the raw socket and how to parse the bytes read from the socket. Then they have to call the methods defined in this class in the following order:
responseBegin(HttpExchange), when the HTTP response data containing the HTTP status code
is availableresponseHeader(HttpExchange, HttpField), when an HTTP field is availableresponseHeaders(HttpExchange), when all HTTP headers are availableresponseSuccess(HttpExchange, Runnable), when the response is successfulresponseFailure(Throwable, Promise) to indicate that the response has failed
(for example, because of I/O exceptions).
At any time, user threads may abort the response which will cause responseFailure(Throwable, Promise) to be
invoked.
The state machine maintained by this class ensures that the response steps are not executed by an I/O thread if the response has already been failed.
HttpSender
| Modifier and Type | Class and Description |
|---|---|
| private class | HttpReceiver.ContentSource
This Content.Source implementation guarantees that all |
| private static class | |
| private static interface | |
| private static enum | HttpReceiver.ResponseState
The request states |
| Modifier and Type | Field and Description |
|---|---|
| private final HttpChannel | |
| private HttpReceiver. | |
| private Throwable | |
| private final SerializedInvoker | |
| private static final Logger | |
| private HttpReceiver. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| private void | |
| protected void | |
| protected abstract void | |
| protected HttpChannel | |
| protected HttpDestination | |
| protected HttpExchange | |
| protected boolean | |
| public boolean | |
| protected abstract void | |
| protected abstract Content. | Returns: the chunk of data that was read, ornull if nothing was read.true to register for fill interest when no data was read. fillInterestIfNeeded)Reads a chunk of data. |
| protected void | |
| protected void | responseBegin(HttpExchange
the HTTP exchange exchange)Method to be invoked when the response status code is available. |
| protected void | |
| protected void | responseFailure(Throwable
the response failure failure, Promise<Boolean> promise)Method to be invoked when the response is failed. |
| protected void | responseHeader(HttpExchange
the HTTP exchange exchange, HttpField the response HTTP field field)Method to be invoked when a response HTTP header is available. |
| protected void | responseHeaders(HttpExchange
the HTTP exchange exchange)Method to be invoked after all response HTTP headers are available. |
| protected void | responseSuccess(HttpExchange
the HTTP exchange exchange, Runnable an optional task to invoke afterwards afterSuccessTask)Method to be invoked when the response is successful. |
| protected void | |
| private void | |
| private void | |
| public String |
| channel | back to summary |
|---|---|
| private final HttpChannel channel | |
| contentSource | back to summary |
|---|---|
| private HttpReceiver. | |
| failure | back to summary |
|---|---|
| private Throwable failure | |
| invoker | back to summary |
|---|---|
| private final SerializedInvoker invoker | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| responseState | back to summary |
|---|---|
| private HttpReceiver. | |
| HttpReceiver | back to summary |
|---|---|
| protected HttpReceiver(HttpChannel channel) | |
| abort | back to summary |
|---|---|
| public void abort(HttpExchange exchange, Throwable failure, Promise<Boolean> promise) | |
| cleanup | back to summary |
|---|---|
| private void cleanup() | |
| dispose | back to summary |
|---|---|
| protected void dispose() Disposes the state of this HttpReceiver.
Subclasses should override (but remember to call
Either this method or | |
| failAndClose | back to summary |
|---|---|
| protected abstract void failAndClose(Throwable failure) Fails the receiver and closes the underlying stream.
| |
| getHttpChannel | back to summary |
|---|---|
| protected HttpChannel getHttpChannel() | |
| getHttpDestination | back to summary |
|---|---|
| protected HttpDestination getHttpDestination() | |
| getHttpExchange | back to summary |
|---|---|
| protected HttpExchange getHttpExchange() | |
| hasContent | back to summary |
|---|---|
| protected boolean hasContent() | |
| isFailed | back to summary |
|---|---|
| public boolean isFailed() | |
| onInterim | back to summary |
|---|---|
| protected abstract void onInterim() Prepare for the next step after an interim response was read. | |
| read | back to summary |
|---|---|
| protected abstract Content. Reads a chunk of data.
If no data was read,
The returned chunk of data may be the last one or an error exactly like
| |
| reset | back to summary |
|---|---|
| protected void reset() Resets the state of this HttpReceiver.
Subclasses should override (but remember to call
Either this method or | |
| responseBegin | back to summary |
|---|---|
| protected void responseBegin(HttpExchange exchange) Method to be invoked when the response status code is available.
Subclasses must have set the response status code on the
This method takes case of notifying
| |
| responseContentAvailable | back to summary |
|---|---|
| protected void responseContentAvailable() Method to be invoked when response content is available to be read.
This method takes care of ensuring the | |
| responseFailure | back to summary |
|---|---|
| protected void responseFailure(Throwable failure, Promise<Boolean> promise) Method to be invoked when the response is failed.
This method takes care of notifying
| |
| responseHeader | back to summary |
|---|---|
| protected void responseHeader(HttpExchange exchange, HttpField field) Method to be invoked when a response HTTP header is available.
Subclasses must not have added the header to the
This method takes case of notifying
| |
| responseHeaders | back to summary |
|---|---|
| protected void responseHeaders(HttpExchange exchange) Method to be invoked after all response HTTP headers are available.
This method takes care of notifying
| |
| responseSuccess | back to summary |
|---|---|
| protected void responseSuccess(HttpExchange exchange, Runnable afterSuccessTask) Method to be invoked when the response is successful.
This method takes care of notifying
| |
| storeCookie | back to summary |
|---|---|
| protected void storeCookie(URI uri, HttpField field) | |
| terminateResponse | back to summary |
|---|---|
| private void terminateResponse(HttpExchange exchange) | |
| terminateResponse | back to summary |
|---|---|
| private void terminateResponse(HttpExchange exchange, Result result) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
read(boolean) calls
happening from a demand(Runnable) callback must be serialized.
| Modifier and Type | Field and Description |
|---|---|
| private Content. | |
| private final AtomicReference | |
| private final AutoLock | |
| private static final Logger | |
| private final Runnable |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private Content. | |
| public void | demand(Runnable
the demand callback to invoke where there is a content chunk available demandCallback)Implements org. Demands to invoke the given demand callback parameter when a chunk of content is available. |
| public boolean | |
| public void | fail(Throwable
the cause of the failure failure)Implements org. Fails this content source with a |
| private void | |
| public void | |
| private void | |
| public Content. | |
| public String |
| currentChunk | back to summary |
|---|---|
| private Content. | |
| demandCallbackRef | back to summary |
|---|---|
| private final AtomicReference<Runnable> demandCallbackRef | |
| lock | back to summary |
|---|---|
| private final AutoLock lock | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| processDemand | back to summary |
|---|---|
| private final Runnable processDemand | |
| ContentSource | back to summary |
|---|---|
| private ContentSource() | |
| chunk | back to summary |
|---|---|
| private Content. | |
| demand | back to summary |
|---|---|
| public void demand(Runnable demandCallback) Implements org. Doc from org. Demands to invoke the given demand callback parameter when a chunk of content is available. See how to use this method idiomatically. Implementations guarantee that calls to this method are safely reentrant so that
stack overflows are avoided in the case of mutual recursion between the execution of
the The demand callback may be invoked spuriously: a subsequent call to Calling this method establishes a pending demand, which is fulfilled when the demand callback is invoked. Calling this method when there is already a pending demand results in an
If the invocation of the demand callback throws an exception, then | |
| error | back to summary |
|---|---|
| public boolean error(Throwable failure) Implements org.
| |
| fail | back to summary |
|---|---|
| public void fail(Throwable failure) Implements org. Doc from org. Fails this content source with a The failure may be notified to the content reader at a later time, when
the content reader reads a content chunk, via a If Typical failure: the content being aborted by user code, or idle timeouts. If this method has already been called, then it is a no operation. | |
| invokeDemandCallback | back to summary |
|---|---|
| private void invokeDemandCallback(boolean invoke) | |
| onDataAvailable | back to summary |
|---|---|
| public void onDataAvailable() Implements org.
| |
| processDemand | back to summary |
|---|---|
| private void processDemand() | |
| read | back to summary |
|---|---|
| public Content. Implements org. Doc from org. Reads a chunk of content. See how to use this method idiomatically. The returned chunk could be:
Once a read returns an Once a read returns a The content reader code must ultimately arrange for a call to
Additionally, prior to the ultimate call to Concurrent reads from different threads are not recommended, as they are inherently in a race condition. Reads performed outside the invocation context of a
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| private volatile Content. | |
| private final ContentDecoder | |
| private final Response | |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| private | DecodingContentSource(HttpReceiver.
|
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public boolean | |
| protected HttpReceiver. | |
| public void | |
| protected Content. | transform(Content.
a chunk read from the wrapped inputChunkContent.Implements abstract org. Transforms the input chunk parameter into an output chunk. |
| _chunk | back to summary |
|---|---|
| private volatile Content. | |
| _decoder | back to summary |
|---|---|
| private final ContentDecoder _decoder | |
| _response | back to summary |
|---|---|
| private final Response _response | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| DecodingContentSource | back to summary |
|---|---|
| private DecodingContentSource(HttpReceiver. | |
| destroy | back to summary |
|---|---|
| public void destroy() Overrides default org.
| |
| error | back to summary |
|---|---|
| public boolean error(Throwable failure) Implements org.
| |
| getContentSource | back to summary |
|---|---|
| protected HttpReceiver. Overrides org.
| |
| onDataAvailable | back to summary |
|---|---|
| public void onDataAvailable() Implements org.
| |
| transform | back to summary |
|---|---|
| protected Content. Implements abstract org. Doc from org. Transforms the input chunk parameter into an output chunk. When this method produces a non- The input chunk is released as soon as this method returns, so
implementations that must hold onto the input chunk must arrange to call
Implementations should return an Exceptions thrown by this method are equivalent to returning an error chunk. Implementations of this method may return:
| |
| Modifier and Type | Method and Description |
|---|---|
| public default void | |
| public boolean | |
| public void |
| destroy | back to summary |
|---|---|
| public default void destroy() Implements org.
| |
| error | back to summary |
|---|---|
| public boolean error(Throwable failure) | |
| onDataAvailable | back to summary |
|---|---|
| public void onDataAvailable() | |
HttpReceiver goes through when receiving a response.
| Modifier and Type | Field and Description |
|---|---|
| public static final HttpReceiver. | BEGIN
The response status code has been received |
| public static final HttpReceiver. | CONTENT
The response content is being received |
| public static final HttpReceiver. | FAILURE
The response is failed |
| public static final HttpReceiver. | HEADER
The response headers are being received |
| public static final HttpReceiver. | HEADERS
All the response headers have been received |
| public static final HttpReceiver. | IDLE
The response is not yet received, the initial state |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static HttpReceiver. | |
| public static HttpReceiver. |
| BEGIN | back to summary |
|---|---|
| public static final HttpReceiver. The response status code has been received | |
| CONTENT | back to summary |
|---|---|
| public static final HttpReceiver. The response content is being received | |
| FAILURE | back to summary |
|---|---|
| public static final HttpReceiver. The response is failed | |
| HEADER | back to summary |
|---|---|
| public static final HttpReceiver. The response headers are being received | |
| HEADERS | back to summary |
|---|---|
| public static final HttpReceiver. All the response headers have been received | |
| IDLE | back to summary |
|---|---|
| public static final HttpReceiver. The response is not yet received, the initial state | |
| ResponseState | back to summary |
|---|---|
| private ResponseState() | |
| valueOf | back to summary |
|---|---|
| public static HttpReceiver. | |
| values | back to summary |
|---|---|
| public static HttpReceiver. | |