Class SemaphoreValve

  • All Implemented Interfaces:, 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.

    Remy Maucherat
    • Field Detail

      • semaphore

        protected java.util.concurrent.Semaphore semaphore
      • concurrency

        protected int concurrency
        Concurrency level of the semaphore.
      • fairness

        protected boolean fairness
        Fairness of the semaphore.
      • block

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

        protected boolean interruptible
        Block interruptibly until a permit is available.
    • Constructor Detail

      • SemaphoreValve

        public SemaphoreValve()
    • Method Detail

      • getConcurrency

        public int getConcurrency()
      • setConcurrency

        public void setConcurrency​(int concurrency)
      • getFairness

        public boolean getFairness()
      • setFairness

        public void setFairness​(boolean fairness)
      • getBlock

        public boolean getBlock()
      • setBlock

        public void setBlock​(boolean block)
      • getInterruptible

        public boolean getInterruptible()
      • setInterruptible

        public void setInterruptible​(boolean interruptible)
      • invoke

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

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

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