Top Description Fields Constructors Methods
org.apache.catalina.valves

public Class SemaphoreValve

extends ValveBase
Class Inheritance
Imports
java.io.IOException, java.util.concurrent.Semaphore, jakarta.servlet.ServletException, org.apache.catalina.LifecycleException, org.apache.catalina.connector.Request, .Response

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 Summary

Modifier and TypeField 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.

Inherited from org.apache.catalina.valves.ValveBase:
asyncSupportedcontainercontainerLognextsm

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the concurrency control should occur on this request
controlConcurrency
(Request
The Servlet request
request
,
Response
The Servlet response
response
)

Subclass friendly method to add conditions.

public boolean
public int
public boolean
public boolean
public void
invoke(Request
The servlet request to be processed
request
,
Response
The servlet response to be created
response
)

Implements org.apache.catalina.Valve.invoke.

Do concurrency control on the request using the semaphore.

public void
permitDenied(Request
The Servlet request
request
,
Response
The Servlet response
response
)

Subclass friendly method to add error handling when a permit isn't granted.

public void
setBlock(boolean block)

public void
setConcurrency(int concurrency)

public void
setFairness(boolean fairness)

public void
setInterruptible(boolean interruptible)

protected void
protected void
Inherited from org.apache.catalina.valves.ValveBase:
backgroundProcessgetContainergetDomainInternalgetNextgetObjectNameKeyPropertiesinitInternalisAsyncSupportedsetAsyncSupportedsetContainersetNexttoString

Field Detail

blockback to summary
protected boolean block

Block until a permit is available.

concurrencyback to summary
protected int concurrency

Concurrency level of the semaphore.

fairnessback to summary
protected boolean fairness

Fairness of the semaphore.

interruptibleback to summary
protected boolean interruptible

Block interruptibly until a permit is available.

semaphoreback to summary
protected Semaphore semaphore

Semaphore.

Constructor Detail

SemaphoreValveback to summary
public SemaphoreValve()

Method Detail

controlConcurrencyback to summary
public boolean controlConcurrency(Request request, Response response)

Subclass friendly method to add conditions.

Parameters
request:Request

The Servlet request

response:Response

The Servlet response

Returns:boolean

true if the concurrency control should occur on this request

getBlockback to summary
public boolean getBlock()
getConcurrencyback to summary
public int getConcurrency()
getFairnessback to summary
public boolean getFairness()
getInterruptibleback to summary
public boolean getInterruptible()
invokeback to summary
public void invoke(Request request, Response response) throws IOException, ServletException

Implements org.apache.catalina.Valve.invoke.

Do concurrency control on the request using the semaphore.

Parameters
request:Request

The servlet request to be processed

response:Response

The servlet response to be created

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
ServletException:
if a servlet error occurs
permitDeniedback to summary
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:Request

The Servlet request

response:Response

The Servlet response

Exceptions
IOException:
Error writing output
ServletException:
Other error
setBlockback to summary
public void setBlock(boolean block)
setConcurrencyback to summary
public void setConcurrency(int concurrency)
setFairnessback to summary
public void setFairness(boolean fairness)
setInterruptibleback to summary
public void setInterruptible(boolean interruptible)
startInternalback to summary
protected void startInternal() throws LifecycleException

Overrides org.apache.catalina.valves.ValveBase.startInternal.

Start this component and implement the requirements of org.apache.catalina.util.LifecycleBase#startInternal().

Annotations
@Override
Exceptions
LifecycleException:
if this component detects a fatal error that prevents this component from being used
stopInternalback to summary
protected void stopInternal() throws LifecycleException

Overrides org.apache.catalina.valves.ValveBase.stopInternal.

Stop this component and implement the requirements of org.apache.catalina.util.LifecycleBase#stopInternal().

Annotations
@Override
Exceptions
LifecycleException:
if this component detects a fatal error that prevents this component from being used