Package com.yahoo.container.jdisc
Class ThreadedRequestHandler
java.lang.Object
com.yahoo.jdisc.AbstractResource
com.yahoo.jdisc.handler.AbstractRequestHandler
com.yahoo.container.jdisc.ThreadedRequestHandler
- All Implemented Interfaces:
com.yahoo.jdisc.handler.RequestHandler
,com.yahoo.jdisc.SharedResource
- Direct Known Subclasses:
ThreadedHttpRequestHandler
public abstract class ThreadedRequestHandler
extends com.yahoo.jdisc.handler.AbstractRequestHandler
A request handler which assigns a worker thread to handle each request.
This is meant to be subclassed by handlers who do work by executing each
request in a separate thread.
Note that this means that subclass handlers are synchronous - the request io can continue after completion of the worker thread.
- Author:
- Simon Thoresen Hult
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.yahoo.jdisc.SharedResource
com.yahoo.jdisc.SharedResource.Debug
-
Field Summary
Fields inherited from interface com.yahoo.jdisc.SharedResource
DEBUG, SYSTEM_PROPERTY_NAME_DEBUG
-
Constructor Summary
ModifierConstructorDescriptionprotected
ThreadedRequestHandler
(Executor executor) protected
ThreadedRequestHandler
(Executor executor, com.yahoo.jdisc.Metric metric) protected
ThreadedRequestHandler
(Executor executor, com.yahoo.jdisc.Metric metric, boolean allowAsyncResponse) Creates a threaded request handler -
Method Summary
Modifier and TypeMethodDescriptionexecutor()
protected Optional<com.yahoo.jdisc.Request.RequestType>
Returns the request type classification to use for requests to this handler.protected abstract void
handleRequest
(com.yahoo.jdisc.Request request, com.yahoo.jdisc.handler.BufferedContentChannel requestContent, com.yahoo.jdisc.handler.ResponseHandler responseHandler) final com.yahoo.jdisc.handler.ContentChannel
handleRequest
(com.yahoo.jdisc.Request request, com.yahoo.jdisc.handler.ResponseHandler responseHandler) Handles a request by assigning a worker thread to it.protected void
writeErrorResponseOnOverload
(com.yahoo.jdisc.Request request, com.yahoo.jdisc.handler.ResponseHandler responseHandler) Invoked to write an error response when the worker pool is overloaded.Methods inherited from class com.yahoo.jdisc.handler.AbstractRequestHandler
handleTimeout
Methods inherited from class com.yahoo.jdisc.AbstractResource
currentState, destroy, refer, refer, release, retainCount
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.yahoo.jdisc.SharedResource
refer, refer, release
-
Field Details
-
metric
protected final com.yahoo.jdisc.Metric metric
-
-
Constructor Details
-
ThreadedRequestHandler
-
ThreadedRequestHandler
-
ThreadedRequestHandler
@Inject protected ThreadedRequestHandler(Executor executor, com.yahoo.jdisc.Metric metric, boolean allowAsyncResponse) Creates a threaded request handler- Parameters:
executor
- the executor to use to execute requestsmetric
- the metric object to which event in this are to be collectedallowAsyncResponse
- true to allow the response header to be created asynchronously. If false (default), this will create an error response if the response header is not returned by the subclass of this before handleRequest returns.
-
-
Method Details
-
handleRequest
public final com.yahoo.jdisc.handler.ContentChannel handleRequest(com.yahoo.jdisc.Request request, com.yahoo.jdisc.handler.ResponseHandler responseHandler) Handles a request by assigning a worker thread to it.- Throws:
com.yahoo.jdisc.handler.OverloadException
- if thread pool has no available thread
-
getRequestType
Returns the request type classification to use for requests to this handler. This overrides the default classification based on request method, and can in turn be overridden by setting a request type on individual responses in handleRequest whenever it is invoked (i.e not for requests that are rejected early e.g due to overload).
This default implementation returns empty.
- Returns:
- the request type to set, or empty to not override the default classification based on request method
-
getTimeout
-
executor
-
handleRequest
protected abstract void handleRequest(com.yahoo.jdisc.Request request, com.yahoo.jdisc.handler.BufferedContentChannel requestContent, com.yahoo.jdisc.handler.ResponseHandler responseHandler) -
writeErrorResponseOnOverload
protected void writeErrorResponseOnOverload(com.yahoo.jdisc.Request request, com.yahoo.jdisc.handler.ResponseHandler responseHandler) Invoked to write an error response when the worker pool is overloaded. A subclass may override this method to define a custom response.
-