Class 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 mean to be subclasses by handlers who does 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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.yahoo.jdisc.Metric metric  
      • Fields inherited from interface com.yahoo.jdisc.SharedResource

        DEBUG, SYSTEM_PROPERTY_NAME_DEBUG
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ThreadedRequestHandler​(java.util.concurrent.Executor executor)  
      protected ThreadedRequestHandler​(java.util.concurrent.Executor executor, com.yahoo.jdisc.Metric metric)  
      protected ThreadedRequestHandler​(java.util.concurrent.Executor executor, com.yahoo.jdisc.Metric metric, boolean allowAsyncResponse)
      Creates a threaded request handler
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.time.Duration getTimeout()  
      protected abstract void handleRequest​(com.yahoo.jdisc.Request request, com.yahoo.jdisc.handler.BufferedContentChannel requestContent, com.yahoo.jdisc.handler.ResponseHandler responseHandler)  
      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.
      • Methods inherited from class com.yahoo.jdisc.handler.AbstractRequestHandler

        handleTimeout
      • 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.SharedResource

        refer, release
    • Field Detail

      • metric

        protected final com.yahoo.jdisc.Metric metric
    • Constructor Detail

      • ThreadedRequestHandler

        protected ThreadedRequestHandler​(java.util.concurrent.Executor executor)
      • ThreadedRequestHandler

        @Inject
        protected ThreadedRequestHandler​(java.util.concurrent.Executor executor,
                                         com.yahoo.jdisc.Metric metric)
      • ThreadedRequestHandler

        @Inject
        protected ThreadedRequestHandler​(java.util.concurrent.Executor executor,
                                         com.yahoo.jdisc.Metric metric,
                                         boolean allowAsyncResponse)
        Creates a threaded request handler
        Parameters:
        executor - the executor to use to execute requests
        metric - the metric object to which event in this are to be collected
        allowAsyncResponse - 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 Detail

      • 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
      • getTimeout

        public java.time.Duration getTimeout()
      • handleRequest

        protected abstract void handleRequest​(com.yahoo.jdisc.Request request,
                                              com.yahoo.jdisc.handler.BufferedContentChannel requestContent,
                                              com.yahoo.jdisc.handler.ResponseHandler responseHandler)