SemaphoreValve (Apache Tomcat 7.0.104 API Documentation)

org.apache.catalina.valves

## Class SemaphoreValve

- java.lang.Object
- - org.apache.catalina.util.LifecycleBase
  - - org.apache.catalina.util.LifecycleMBeanBase
    - - org.apache.catalina.valves.ValveBase
      - - org.apache.catalina.valves.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

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.apache.catalina.Lifecycle

      `Lifecycle.SingleUse`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `block` Block until a permit is available.
    `protected int` | `concurrency` Concurrency level of the semaphore.
    `protected boolean` | `fairness` Fairness of the semaphore.
    `protected boolean` | `interruptible` Block interruptibly until a permit is available.
    `protected Semaphore` | `semaphore` Semaphore.

    - ### Fields inherited from class org.apache.catalina.valves.ValveBase

      `asyncSupported, container, containerLog, next, sm`

    - ### Fields inherited from class org.apache.catalina.util.LifecycleMBeanBase

      `mserver`

    - ### Fields inherited from interface org.apache.catalina.Lifecycle

      `AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SemaphoreValve()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `controlConcurrency(Request request, Response response)` Subclass friendly method to add conditions.
    `boolean` | `getBlock()`
    `int` | `getConcurrency()`
    `boolean` | `getFairness()`
    `String` | `getInfo()` Return descriptive information about this Valve implementation.
    `boolean` | `getInterruptible()`
    `void` | `invoke(Request request, Response response)` Do concurrency control on the request using the semaphore.
    `void` | `permitDenied(Request request, Response response)` Subclass friendly method to add error handling when a permit isn't granted.
    `void` | `setBlock(boolean block)`
    `void` | `setConcurrency(int concurrency)`
    `void` | `setFairness(boolean fairness)`
    `void` | `setInterruptible(boolean interruptible)`
    `protected void` | `startInternal()` Start this component and implement the requirements of `LifecycleBase.startInternal()`.
    `protected void` | `stopInternal()` Stop this component and implement the requirements of `LifecycleBase.stopInternal()`.

    - ### Methods inherited from class org.apache.catalina.valves.ValveBase

      `backgroundProcess, event, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, toString`

    - ### Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase

      `destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister`

    - ### Methods inherited from class org.apache.catalina.util.LifecycleBase

      `addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### semaphore

          protected Semaphore 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)

    - #### startInternal

          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

          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

    - #### getInfo

          public String getInfo()

      Return descriptive information about this Valve implementation.
      Specified by:
        `getInfo` in interface `Valve`
      Overrides:
        `getInfo` in class `ValveBase`
      Returns:
        descriptive information about this Valve implementation.

    - #### invoke

          public void invoke(Request request,
                    Response response)
                      throws IOException,
                             ServletException

      Do concurrency control on the request using the semaphore.
      Specified by:
        `invoke` in interface `Valve`
      Specified by:
        `invoke` in class `ValveBase`
      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

          public boolean controlConcurrency(Request request,
                                   Response response)

      Subclass friendly method to add conditions.
      Parameters:
        `request` -
        `response` -

    - #### permitDenied

          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` -
        `response` -
      Throws:
        `IOException`
        `ServletException`

Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.