Class AbstractRequestHandler
- All Implemented Interfaces:
RequestHandler
,SharedResource
- Direct Known Subclasses:
AbstractClientProvider
,ThreadedRequestHandler
This class provides an abstract RequestHandler
implementation with reasonable defaults for everything but
RequestHandler.handleRequest(Request, ResponseHandler)
.
A very simple hello world handler could be implemented like this:
class HelloWorldHandler extends AbstractRequestHandler { @Override public ContentChannel handleRequest(Request request, ResponseHandler handler) { ContentWriter writer = ResponseDispatch.newInstance(Response.Status.OK).connectWriter(handler); try { writer.write("Hello World!"); } finally { writer.close(); } return null; } }
- Author:
- Simon Thoresen Hult
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.yahoo.jdisc.SharedResource
SharedResource.Debug
-
Field Summary
Fields inherited from interface com.yahoo.jdisc.SharedResource
DEBUG, SYSTEM_PROPERTY_NAME_DEBUG
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
handleTimeout
(Request request, ResponseHandler responseHandler) This method is called by theContainer
when aRequest
that was previously accepted byRequestHandler.handleRequest(Request, ResponseHandler)
has timed out.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.handler.RequestHandler
handleRequest
Methods inherited from interface com.yahoo.jdisc.SharedResource
refer, refer, release
-
Constructor Details
-
AbstractRequestHandler
public AbstractRequestHandler()
-
-
Method Details
-
handleTimeout
Description copied from interface:RequestHandler
This method is called by the
Container
when aRequest
that was previously accepted byRequestHandler.handleRequest(Request, ResponseHandler)
has timed out. If the Request has no timeout (i.e.Request.getTimeout(TimeUnit)
returns null), then this method is never called.The given
ResponseHandler
is the same ResponseHandler that was initially passed to theRequestHandler.handleRequest(Request, ResponseHandler)
method, and it is guarded by a volatile boolean so that only the first call toResponseHandler.handleResponse(Response)
is actually passed on. This means that you do NOT need to manage the ResponseHandlers yourself to prevent a late Response from calling the same ResponseHandler.Notice that you MUST call
ResponseHandler.handleResponse(Response)
as a reaction to having this method invoked. Failure to do so will prevent the Container from ever shutting down.- Specified by:
handleTimeout
in interfaceRequestHandler
- Parameters:
request
- The Request that has timed out.responseHandler
- The handler to pass the timeoutResponse
to.- See Also:
-