A Handler. that fires events during the processing of the requests.
EventsHandler will emit events for the various phases the server goes through while processing an HTTP request and response.
Subclasses may listen to those events to track timing and/or other values such as request URI, etc.
The events parameters, especially the Request object, may be
in a transient state depending on the event, and not all properties/features
of the parameters may be available inside a listener method.
It is recommended that the event parameters are not acted upon in the listener methods, or undefined behavior may result. On the other hand, it is legit to store request attributes in one listener method that may be possibly retrieved in another listener method in a later event.
Listener methods are invoked synchronously from the thread that is performing the request processing, and they should not call blocking code (otherwise the request processing will be blocked as well).
The kind of chunk passed to onRequestRead(Request, Content. depends on
the parent of this handler. For instance, if the parent is the Server, then raw chunks
are always passed. If somewhere in the parent chain is the GzipHandler then
unzipped chunks are passed.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | handle(Request
the HTTP request to handle request, Response the HTTP response to handle response, Callback the callback to complete when the handling is complete callback)Overrides org. Implements org. Invoked to handle the passed HTTP request and response. |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| protected void | onAfterHandling(Request
the request object. The request, boolean read(), demand(Runnable) and fail(Throwable) methods must not be called by the listener.if the server handlers handled the request handled, Throwable the exception thrown by the application failure)Invoked after application handling (i.e. just after the call to the |
| protected void | onBeforeHandling(Request
the request object. The request)read(), demand(Runnable) and fail(Throwable) methods must not be called by the listener.Invoked just before calling the server handler tree (i.e. just before the |
| protected void | onComplete(Request
the request object. The request, Throwable read(), demand(Runnable) and fail(Throwable) methods must not be called by the listener.if there was a failure to complete failure)Invoked when the request and response processing are complete,
just before the request and response will be recycled (i.e. after the
|
| protected void | onRequestRead(Request
the request object. The request, Content.read(), demand(Runnable) and fail(Throwable) methods must not be called by the listener.a potentially null request content chunk, including chunkerror
and org. chunks.
If a reference to the chunk (or its ByteBuffer) is kept,
then Content. must be called.Invoked every time a request content chunk has been parsed, just before
making it available to the application (i.e. from within a call to
|
| protected void | onResponseBegin(Request
the request object. The request, int read(), demand(Runnable) and fail(Throwable) methods must not be called by the listener.the response status status, HttpFields the immutable fields of the response object headers)Invoked just before the response is line written to the network (i.e. from
within the first call to |
| protected void | onResponseTrailersComplete(Request
the request object. The request, HttpFields read(), demand(Runnable) and fail(Throwable) methods must not be called by the listener.the written trailers. trailers)Invoked after the response trailers have been written and the final |
| protected void | onResponseWrite(Request
the request object. The request, boolean read(), demand(Runnable) and fail(Throwable) methods must not be called by the listener.indicating last write last, ByteBuffer The content)ByteBuffer of the response content chunk (readonly).Invoked before each response content chunk has been written (i.e. from
within the any call to |
| protected void | onResponseWriteComplete(Request
the request object. The request, Throwable read(), demand(Runnable) and fail(Throwable) methods must not be called by the listener.if there was a failure to write the given content failure)Invoked after each response content chunk has been written
(i.e. immediately before calling the |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| EventsHandler | back to summary |
|---|---|
| public EventsHandler() | |
| EventsHandler | back to summary |
|---|---|
| public EventsHandler(Handler handler) | |
| handle | back to summary |
|---|---|
| public boolean handle(Request request, Response response, Callback callback) throws Exception Overrides org. Implements org. Doc from org. Invoked to handle the passed HTTP request and response. The request is accepted by returning true, then handling must be concluded by completing the passed callback. The handling may be asynchronous, i.e. this method may return true and complete the given callback later, possibly from a different thread. If this method returns false, then the callback must not be invoked and any mutation on the response reversed. Exceptions thrown by this method may be subsequently handled by an error The simplest implementation is:
public boolean handle(Request request, Response response, Callback callback)
{
callback.succeeded();
return true;
}
A HelloWorld implementation is:
public boolean handle(Request request, Response response, Callback callback)
{
response.write(true, ByteBuffer.wrap("Hello World\n".getBytes(StandardCharsets.UTF_8)), callback);
return true;
}
| |
| notifyOnAfterHandling | back to summary |
|---|---|
| private void notifyOnAfterHandling(Request request, boolean handled, Throwable failure) | |
| notifyOnBeforeHandling | back to summary |
|---|---|
| private void notifyOnBeforeHandling(Request request) | |
| notifyOnComplete | back to summary |
|---|---|
| private void notifyOnComplete(Request request, Throwable failure) | |
| notifyOnRequestRead | back to summary |
|---|---|
| private void notifyOnRequestRead(Request wrapped, Content. | |
| notifyOnResponseBegin | back to summary |
|---|---|
| private void notifyOnResponseBegin(Request request, EventsHandler. | |
| notifyOnResponseTrailersComplete | back to summary |
|---|---|
| private void notifyOnResponseTrailersComplete(Request request, EventsHandler. | |
| notifyOnResponseWrite | back to summary |
|---|---|
| private void notifyOnResponseWrite(Request request, boolean last, ByteBuffer content) | |
| notifyOnResponseWriteComplete | back to summary |
|---|---|
| private void notifyOnResponseWriteComplete(Request request, Throwable failure) | |
| onAfterHandling | back to summary |
|---|---|
| protected void onAfterHandling(Request request, boolean handled, Throwable failure) Invoked after application handling (i.e. just after the call to the
| |
| onBeforeHandling | back to summary |
|---|---|
| protected void onBeforeHandling(Request request) Invoked just before calling the server handler tree (i.e. just before the This is the final state of the request before the handlers are called. This includes any request customization.
| |
| onComplete | back to summary |
|---|---|
| protected void onComplete(Request request, Throwable failure) Invoked when the request and response processing are complete,
just before the request and response will be recycled (i.e. after the
| |
| onRequestRead | back to summary |
|---|---|
| protected void onRequestRead(Request request, Content. Invoked every time a request content chunk has been parsed, just before
making it available to the application (i.e. from within a call to
| |
| onResponseBegin | back to summary |
|---|---|
| protected void onResponseBegin(Request request, int status, HttpFields headers) Invoked just before the response is line written to the network (i.e. from
within the first call to
| |
| onResponseTrailersComplete | back to summary |
|---|---|
| protected void onResponseTrailersComplete(Request request, HttpFields trailers) Invoked after the response trailers have been written and the final
| |
| onResponseWrite | back to summary |
|---|---|
| protected void onResponseWrite(Request request, boolean last, ByteBuffer content) Invoked before each response content chunk has been written (i.e. from
within the any call to
| |
| onResponseWriteComplete | back to summary |
|---|---|
| protected void onResponseWriteComplete(Request request, Throwable failure) Invoked after each response content chunk has been written
(i.e. immediately before calling the
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Content. | read()
Overrides org. Implements org. Reads a chunk of content. |
| roRequest | back to summary |
|---|---|
| private final Request roRequest | |
| EventsRequest | back to summary |
|---|---|
| public EventsRequest(Request request, Request roRequest) | |
| read | back to summary |
|---|---|
| public Content. Overrides org. 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
In addition, the returned
| |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private HttpFields |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | setTrailersSupplier(Supplier<HttpFields>
a supplier for the HTTP trailers trailers)Overrides org. Implements org. Sets the supplier for the HTTP trailers. |
| public void | write(boolean
whether the ByteBuffer is the last to write last, ByteBuffer the ByteBuffer to write byteBuffer, Callback the callback to notify when the write operation is complete callback)Overrides org. Implements org. Writes the given |
| notifiedOnResponseBegin | back to summary |
|---|---|
| private boolean notifiedOnResponseBegin | |
| suppliedTrailers | back to summary |
|---|---|
| private HttpFields suppliedTrailers | |
| EventsResponse | back to summary |
|---|---|
| public EventsResponse(Request roRequest, Response response) | |
| setTrailersSupplier | back to summary |
|---|---|
| public void setTrailersSupplier(Supplier<HttpFields> trailers) Overrides org. Implements org. Doc from org. Sets the supplier for the HTTP trailers. The method Example:
| |
| write | back to summary |
|---|---|
| public void write(boolean last, ByteBuffer byteBuffer, Callback callback) Overrides org. Implements org. Doc from org. Writes the given 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 invocation of the passed Thus a
| |