Class ResponseTimeout

java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.service.Service
services.moleculer.web.middleware.HttpMiddleware
services.moleculer.web.middleware.ResponseTimeout
All Implemented Interfaces:
services.moleculer.service.MoleculerLifecycle, HttpConstants

public class ResponseTimeout extends HttpMiddleware implements HttpConstants
Middleware that will timeout requests if the response has not been written after the specified time. HTTP response code will be "408". Sample:
route.use(new ResponseTimeout(1000L * 30));
  • Field Details

    • timeout

      protected long timeout
      Request timeout in MILLISECONDS (0 = no timeout / disable timer).
    • status

      protected int status
      Response status (408 = Request Timeout).
    • htmlTemplate

      protected String htmlTemplate
      Template of the HTML response.
    • htmlTemplatePath

      protected String htmlTemplatePath
      Template path of the HTML response.
    • scheduler

      protected ScheduledExecutorService scheduler
    • cachedHTML

      protected byte[] cachedHTML
    • cachedJSON

      protected byte[] cachedJSON
  • Constructor Details

    • ResponseTimeout

      public ResponseTimeout()
    • ResponseTimeout

      public ResponseTimeout(long timeoutMillis)
    • ResponseTimeout

      public ResponseTimeout(long timeoutMillis, int status, String htmlTemplateOrPath)
  • Method Details

    • started

      public void started(services.moleculer.ServiceBroker broker) throws Exception
      Specified by:
      started in interface services.moleculer.service.MoleculerLifecycle
      Overrides:
      started in class services.moleculer.service.MoleculerComponent
      Throws:
      Exception
    • install

      public RequestProcessor install(RequestProcessor next, io.datatree.Tree config)
      Specified by:
      install in class HttpMiddleware
    • refreshCaches

      protected void refreshCaches()
    • getTimeout

      public long getTimeout()
    • setTimeout

      public void setTimeout(long timeout)
    • getHtmlTemplate

      public String getHtmlTemplate()
      Returns:
      the htmlTemplate
    • setHtmlTemplate

      public void setHtmlTemplate(String htmlTemplate)
      Parameters:
      htmlTemplate - the htmlTemplate to set
    • getHtmlTemplatePath

      public String getHtmlTemplatePath()
      Returns:
      the htmlTemplatePath
    • setHtmlTemplatePath

      public void setHtmlTemplatePath(String htmlTemplatePath)
      Parameters:
      htmlTemplatePath - the htmlTemplatePath to set
    • getStatus

      public int getStatus()
      Returns:
      the status
    • setStatus

      public void setStatus(int status)
      Parameters:
      status - the status to set