public interface WebDispatcher
Once a HTTP request is fully read by the server it is dispatched calling all available WebDispatcher
instances available. To provide a WebDispatch, a subclass therefore needs to wear an
As the first request arrives, all dispatchers are asked for their priority (via
then sorted according to that in an ascending manner. As default priority
PriorityCollector.DEFAULT_PRIORITY can be used. Note that this will only be done
once, therefore getPriority() must only return a constant value as it is never re-evaluated. By default,
a not found handler (
DefaultDispatcher is registered with 999 as priority, so higher
priorities will never be executed.
For each incoming request, the list of dispatchers is iterated and
dispatch(WebContext) is invoked
until one of those returns true, to signal that the request was handled.
If a dispatcher performs serious work or any blocking IO operation. The dispatcher must complete the request
in another thread (using
If a dispatcher is willing to handle all incoming data (payload of a PUT or POST request) by itself - instead of
just accumulating this data in memory or on disk, the
preDispatch(WebContext) method must return
true for a given request. This needs to install a
ContentHandler. Note that no further
dispatch(WebContext) will be called for a request which received a true for its call
|Modifier and Type||Method and Description|
Invoked in order to handle the given request.
Returns the priority to determine the position in the dispatcher list.
Invoked as soon as the complete request but not its contents are available.
boolean preDispatch(WebContext ctx) throws Exception
In contrast to
dispatch(WebContext) this method is invoked before the complete data is accumulated.
This permits the handler to install an
in order to directly process the uploaded data. A request for which true was replied will not
be dispatched again once it is complete.
Note that it is required to handle and consume the request in another thread as further contents are not processed until this method returns.
boolean dispatch(WebContext ctx) throws Exception
If the dispatcher doesn't feel responsible for handling the request, it simply returns false. Otherwise if the request is being handled, true must be returned
Note that no blocking operation must be performed in this method. For any complex interaction, a new thread
should be forked using
Tasks.executor(String). Note that even
Response.outputStream(io.netty.handler.codec.http.HttpResponseStatus, String) might
block sooner or later to limit heap memory usage - so fork a thread for any serious work besides checking
responsibilities for handling requests.
ctx- the request to handle
Exception- in case of an error when parsing or dispatching the request
Copyright © 2017. All rights reserved.