Class AbstractRequestHandler
- java.lang.Object
-
- com.yahoo.jdisc.AbstractResource
-
- com.yahoo.jdisc.handler.AbstractRequestHandler
-
- All Implemented Interfaces:
RequestHandler
,SharedResource
- Direct Known Subclasses:
AbstractClientProvider
,ThreadedRequestHandler
public abstract class AbstractRequestHandler extends AbstractResource implements RequestHandler
This class provides an abstract
RequestHandler
implementation with reasonable defaults for everything butRequestHandler.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
-
-
Field Summary
-
Fields inherited from interface com.yahoo.jdisc.SharedResource
DEBUG, SYSTEM_PROPERTY_NAME_DEBUG
-
-
Constructor Summary
Constructors Constructor Description AbstractRequestHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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, 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, release
-
-
-
-
Method Detail
-
handleTimeout
public void handleTimeout(Request request, ResponseHandler responseHandler)
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:
Response.dispatchTimeout(ResponseHandler)
-
-