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
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface Lifecycle
Lifecycle.SingleUse -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanBlock until a permit is available.protected intConcurrency level of the semaphore.protected booleanFairness of the semaphore.protected intHigh concurrency status.protected booleanBlock interruptibly until a permit is available.protected SemaphoreSemaphore.Fields inherited from class ValveBase
asyncSupported, container, containerLog, next, smFields inherited from interface 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 -
Method Summary
Modifier and TypeMethodDescriptionbooleancontrolConcurrency(Request request, Response response) Subclass friendly method to add conditions.booleangetBlock()Return whether the valve blocks until a permit is available.intReturn the concurrency level of the semaphore.booleanReturn the fairness setting of the semaphore.intReturn the HTTP status code returned when concurrency is too high.booleanReturn whether the valve blocks interruptibly.voidDo 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) Set whether the valve blocks until a permit is available.voidsetConcurrency(int concurrency) Set the concurrency level of the semaphore.voidsetFairness(boolean fairness) Set the fairness setting of the semaphore.voidsetHighConcurrencyStatus(int highConcurrencyStatus) Set the HTTP status code returned when concurrency is too high.voidsetInterruptible(boolean interruptible) Set whether the valve blocks interruptibly.protected voidStart this component and implement the requirements ofLifecycleBase.startInternal().protected voidStop this component and implement the requirements ofLifecycleBase.stopInternal().Methods inherited from class ValveBase
backgroundProcess, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, toStringMethods inherited from class LifecycleMBeanBase
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisterMethods inherited from class LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
-
Field Details
-
semaphore
Semaphore. -
concurrency
protected int concurrencyConcurrency level of the semaphore. -
fairness
protected boolean fairnessFairness of the semaphore. -
block
protected boolean blockBlock until a permit is available. -
interruptible
protected boolean interruptibleBlock interruptibly until a permit is available. -
highConcurrencyStatus
protected int highConcurrencyStatusHigh concurrency status. This status code is returned as an error if concurrency is too high.
-
-
Constructor Details
-
SemaphoreValve
public SemaphoreValve()Construct a newSemaphoreValvewith async support enabled.
-
-
Method Details
-
getConcurrency
public int getConcurrency()Return the concurrency level of the semaphore.- Returns:
- the concurrency level
-
setConcurrency
public void setConcurrency(int concurrency) Set the concurrency level of the semaphore.- Parameters:
concurrency- the concurrency level
-
getFairness
public boolean getFairness()Return the fairness setting of the semaphore.- Returns:
trueif the semaphore uses fair ordering
-
setFairness
public void setFairness(boolean fairness) Set the fairness setting of the semaphore.- Parameters:
fairness-trueif the semaphore should use fair ordering
-
getBlock
public boolean getBlock()Return whether the valve blocks until a permit is available.- Returns:
trueif the valve blocks waiting for a permit
-
setBlock
public void setBlock(boolean block) Set whether the valve blocks until a permit is available.- Parameters:
block-trueif the valve should block waiting for a permit
-
getInterruptible
public boolean getInterruptible()Return whether the valve blocks interruptibly.- Returns:
trueif the valve blocks interruptibly
-
setInterruptible
public void setInterruptible(boolean interruptible) Set whether the valve blocks interruptibly.- Parameters:
interruptible-trueif the valve should block interruptibly
-
getHighConcurrencyStatus
public int getHighConcurrencyStatus()Return the HTTP status code returned when concurrency is too high.- Returns:
- the status code, or -1 if no error is returned
-
setHighConcurrencyStatus
public void setHighConcurrencyStatus(int highConcurrencyStatus) Set the HTTP status code returned when concurrency is too high.- Parameters:
highConcurrencyStatus- the status code to return
-
startInternal
Start this component and implement the requirements ofLifecycleBase.startInternal().- Overrides:
startInternalin classValveBase- Throws:
LifecycleException- if this component detects a fatal error that prevents this component from being used
-
stopInternal
Stop this component and implement the requirements ofLifecycleBase.stopInternal().- Overrides:
stopInternalin classValveBase- Throws:
LifecycleException- if this component detects a fatal error that prevents this component from being used
-
invoke
Do concurrency control on the request using the semaphore.- Parameters:
request- The servlet request to be processedresponse- The servlet response to be created- Throws:
IOException- if an input/output error occursServletException- if a servlet error occurs
-
controlConcurrency
-
permitDenied
Subclass friendly method to add error handling when a permit isn't granted.- Parameters:
request- The Servlet requestresponse- The Servlet response- Throws:
IOException- Error writing outputServletException- Other error
-