Class SemaphoreValve

All Implemented Interfaces:
MBeanRegistration, Contained, JmxEnabled, Lifecycle, Valve

public class SemaphoreValve extends ValveBase

Implementation of a Valve that limits concurrency.

This Valve may be attached to any Container, depending on the granularity of the concurrency control you wish to perform. Note that internally, some async requests may require multiple serial requests to complete what - to the user - appears as a single request.

Author:
Remy Maucherat
  • Field Details Link icon

    • semaphore Link icon

      protected Semaphore semaphore
      Semaphore.
    • concurrency Link icon

      protected int concurrency
      Concurrency level of the semaphore.
    • fairness Link icon

      protected boolean fairness
      Fairness of the semaphore.
    • block Link icon

      protected boolean block
      Block until a permit is available.
    • interruptible Link icon

      protected boolean interruptible
      Block interruptibly until a permit is available.
    • highConcurrencyStatus Link icon

      protected int highConcurrencyStatus
      High concurrency status. This status code is returned as an error if concurrency is too high.
  • Constructor Details Link icon

    • SemaphoreValve Link icon

      public SemaphoreValve()
  • Method Details Link icon

    • getConcurrency Link icon

      public int getConcurrency()
    • setConcurrency Link icon

      public void setConcurrency(int concurrency)
    • getFairness Link icon

      public boolean getFairness()
    • setFairness Link icon

      public void setFairness(boolean fairness)
    • getBlock Link icon

      public boolean getBlock()
    • setBlock Link icon

      public void setBlock(boolean block)
    • getInterruptible Link icon

      public boolean getInterruptible()
    • setInterruptible Link icon

      public void setInterruptible(boolean interruptible)
    • getHighConcurrencyStatus Link icon

      public int getHighConcurrencyStatus()
    • setHighConcurrencyStatus Link icon

      public void setHighConcurrencyStatus(int highConcurrencyStatus)
    • startInternal Link icon

      protected void startInternal() throws LifecycleException
      Start this component and implement the requirements of LifecycleBase.startInternal().
      Overrides:
      startInternal in class ValveBase
      Throws:
      LifecycleException - if this component detects a fatal error that prevents this component from being used
    • stopInternal Link icon

      protected void stopInternal() throws LifecycleException
      Stop this component and implement the requirements of LifecycleBase.stopInternal().
      Overrides:
      stopInternal in class ValveBase
      Throws:
      LifecycleException - if this component detects a fatal error that prevents this component from being used
    • invoke Link icon

      public void invoke(Request request, Response response) throws IOException, ServletException
      Do concurrency control on the request using the semaphore.
      Parameters:
      request - The servlet request to be processed
      response - The servlet response to be created
      Throws:
      IOException - if an input/output error occurs
      ServletException - if a servlet error occurs
    • controlConcurrency Link icon

      public boolean controlConcurrency(Request request, Response response)
      Subclass friendly method to add conditions.
      Parameters:
      request - The Servlet request
      response - The Servlet response
      Returns:
      true if the concurrency control should occur on this request
    • permitDenied Link icon

      public void permitDenied(Request request, Response response) throws IOException, ServletException
      Subclass friendly method to add error handling when a permit isn't granted.
      Parameters:
      request - The Servlet request
      response - The Servlet response
      Throws:
      IOException - Error writing output
      ServletException - Other error