Package 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:
- javax.management.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.LifecycleLifecycle.SingleUse
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected booleanblockBlock until a permit is available.protected intconcurrencyConcurrency level of the semaphore.protected booleanfairnessFairness of the semaphore.protected booleaninterruptibleBlock interruptibly until a permit is available.protected java.util.concurrent.SemaphoresemaphoreSemaphore.- 
Fields inherited from class org.apache.catalina.valves.ValveBaseasyncSupported, container, containerLog, next, sm
 - 
Fields inherited from class org.apache.catalina.util.LifecycleMBeanBasemserver
 - 
Fields inherited from interface org.apache.catalina.LifecycleAFTER_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 SummaryConstructors Constructor Description SemaphoreValve()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontrolConcurrency(Request request, Response response)Subclass friendly method to add conditions.booleangetBlock()intgetConcurrency()booleangetFairness()booleangetInterruptible()voidinvoke(Request request, Response response)Do concurrency control on the request using the semaphore.voidpermitDenied(Request request, Response response)Subclass friendly method to add error handling when a permit isn't granted.voidsetBlock(boolean block)voidsetConcurrency(int concurrency)voidsetFairness(boolean fairness)voidsetInterruptible(boolean interruptible)protected voidstartInternal()Start this component and implement the requirements ofLifecycleBase.startInternal().protected voidstopInternal()Stop this component and implement the requirements ofLifecycleBase.stopInternal().- 
Methods inherited from class org.apache.catalina.valves.ValveBasebackgroundProcess, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, toString
 - 
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBasedestroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister
 - 
Methods inherited from class org.apache.catalina.util.LifecycleBaseaddLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
 
- 
 
- 
- 
- 
Field Detail- 
semaphoreprotected java.util.concurrent.Semaphore semaphore Semaphore.
 - 
concurrencyprotected int concurrency Concurrency level of the semaphore.
 - 
fairnessprotected boolean fairness Fairness of the semaphore.
 - 
blockprotected boolean block Block until a permit is available.
 - 
interruptibleprotected boolean interruptible Block interruptibly until a permit is available.
 
- 
 - 
Method Detail- 
getConcurrencypublic int getConcurrency() 
 - 
setConcurrencypublic void setConcurrency(int concurrency) 
 - 
getFairnesspublic boolean getFairness() 
 - 
setFairnesspublic void setFairness(boolean fairness) 
 - 
getBlockpublic boolean getBlock() 
 - 
setBlockpublic void setBlock(boolean block) 
 - 
getInterruptiblepublic boolean getInterruptible() 
 - 
setInterruptiblepublic void setInterruptible(boolean interruptible) 
 - 
startInternalprotected void startInternal() throws LifecycleExceptionStart this component and implement the requirements ofLifecycleBase.startInternal().- Overrides:
- startInternalin class- ValveBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
stopInternalprotected void stopInternal() throws LifecycleExceptionStop this component and implement the requirements ofLifecycleBase.stopInternal().- Overrides:
- stopInternalin class- ValveBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 - 
invokepublic void invoke(Request request, Response response) throws java.io.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:
- java.io.IOException- if an input/output error occurs
- ServletException- if a servlet error occurs
 
 - 
controlConcurrencypublic boolean controlConcurrency(Request request, Response response) Subclass friendly method to add conditions.- Parameters:
- request- The Servlet request
- response- The Servlet response
- Returns:
- trueif the concurrency control should occur on this request
 
 - 
permitDeniedpublic void permitDenied(Request request, Response response) throws java.io.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:
- java.io.IOException- Error writing output
- ServletException- Other error
 
 
- 
 
-