| Method from org.apache.catalina.valves.SemaphoreValve Detail: |
public void addLifecycleListener(LifecycleListener listener) {
lifecycle.addLifecycleListener(listener);
}
Add a lifecycle event listener to this component. |
public boolean controlConcurrency(Request request,
Response response) {
return true;
}
Subclass friendly method to add conditions. |
public LifecycleListener[] findLifecycleListeners() {
return lifecycle.findLifecycleListeners();
}
Get the lifecycle listeners associated with this lifecycle. If this
Lifecycle has no listeners registered, a zero-length array is returned. |
public boolean getBlock() {
return block;
}
|
public int getConcurrency() {
return concurrency;
}
|
public boolean getFairness() {
return fairness;
}
|
public String getInfo() {
return (info);
}
Return descriptive information about this Valve implementation. |
public boolean getInterruptible() {
return interruptible;
}
|
public void invoke(Request request,
Response response) throws IOException, ServletException {
if (controlConcurrency(request, response)) {
boolean shouldRelease = true;
try {
if (block) {
if (interruptible) {
try {
semaphore.acquire();
} catch (InterruptedException e) {
shouldRelease = false;
permitDenied(request, response);
return;
}
} else {
semaphore.acquireUninterruptibly();
}
} else {
if (!semaphore.tryAcquire()) {
shouldRelease = false;
permitDenied(request, response);
return;
}
}
getNext().invoke(request, response);
} finally {
if (shouldRelease) {
semaphore.release();
}
}
} else {
getNext().invoke(request, response);
}
}
Do concurrency control on the request using the semaphore. |
public void permitDenied(Request request,
Response response) throws IOException, ServletException {
}
Subclass friendly method to add error handling when a permit isn't granted. |
public void removeLifecycleListener(LifecycleListener listener) {
lifecycle.removeLifecycleListener(listener);
}
Remove a lifecycle event listener from this component. |
public void setBlock(boolean block) {
this.block = block;
}
|
public void setConcurrency(int concurrency) {
this.concurrency = concurrency;
}
|
public void setFairness(boolean fairness) {
this.fairness = fairness;
}
|
public void setInterruptible(boolean interruptible) {
this.interruptible = interruptible;
}
|
public void start() throws LifecycleException {
// Validate and update our current component state
if (started)
throw new LifecycleException
(sm.getString("semaphoreValve.alreadyStarted"));
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
semaphore = new Semaphore(concurrency, fairness);
}
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. |
public void stop() throws LifecycleException {
// Validate and update our current component state
if (!started)
throw new LifecycleException
(sm.getString("semaphoreValve.notStarted"));
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
semaphore = null;
}
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. |