org.apache.catalina.valves

Class SemaphoreValve

public class SemaphoreValve extends ValveBase implements Lifecycle

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.

Version: $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (Tue, 24 Oct 2006) $

Author: Remy Maucherat

Field Summary
protected booleanblock
Block until a permit is available.
protected intconcurrency
Concurrency level of the semaphore.
protected booleanfairness
Fairness of the semaphore.
protected booleaninterruptible
Block interruptibly until a permit is available.
protected LifecycleSupportlifecycle
The lifecycle event support for this component.
protected Semaphoresemaphore
Semaphore.
Method Summary
voidaddLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
booleancontrolConcurrency(Request request, Response response)
Subclass friendly method to add conditions.
LifecycleListener[]findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle.
booleangetBlock()
intgetConcurrency()
booleangetFairness()
StringgetInfo()
Return descriptive information about this Valve implementation.
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.
voidremoveLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
voidsetBlock(boolean block)
voidsetConcurrency(int concurrency)
voidsetFairness(boolean fairness)
voidsetInterruptible(boolean interruptible)
voidstart()
Prepare for the beginning of active use of the public methods of this component.
voidstop()
Gracefully terminate the active use of the public methods of this component.

Field Detail

block

protected boolean block
Block until a permit is available.

concurrency

protected int concurrency
Concurrency level of the semaphore.

fairness

protected boolean fairness
Fairness of the semaphore.

interruptible

protected boolean interruptible
Block interruptibly until a permit is available.

lifecycle

protected LifecycleSupport lifecycle
The lifecycle event support for this component.

semaphore

protected Semaphore semaphore
Semaphore.

Method Detail

addLifecycleListener

public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.

Parameters: listener The listener to add

controlConcurrency

public boolean controlConcurrency(Request request, Response response)
Subclass friendly method to add conditions.

findLifecycleListeners

public LifecycleListener[] findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.

getBlock

public boolean getBlock()

getConcurrency

public int getConcurrency()

getFairness

public boolean getFairness()

getInfo

public String getInfo()
Return descriptive information about this Valve implementation.

getInterruptible

public boolean getInterruptible()

invoke

public void invoke(Request request, Response response)
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: IOException if an input/output error occurs ServletException if a servlet error occurs

permitDenied

public void permitDenied(Request request, Response response)
Subclass friendly method to add error handling when a permit isn't granted.

removeLifecycleListener

public void removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.

Parameters: listener The listener to add

setBlock

public void setBlock(boolean block)

setConcurrency

public void setConcurrency(int concurrency)

setFairness

public void setFairness(boolean fairness)

setInterruptible

public void setInterruptible(boolean interruptible)

start

public void start()
Prepare for the beginning of active use of the public methods of this component. This method should be called after configure(), and before any of the public methods of the component are utilized.

Throws: LifecycleException if this component detects a fatal error that prevents this component from being used

stop

public void stop()
Gracefully terminate the active use of the public methods of this component. This method should be the last one called on a given instance of this component.

Throws: LifecycleException if this component detects a fatal error that needs to be reported

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