Fields Summary |
---|
private static final String | infoThe descriptive information related to this implementation. |
private org.apache.catalina.util.StringManager | smThe string manager for this package. |
protected Semaphore | semaphoreSemaphore. |
protected org.apache.catalina.util.LifecycleSupport | lifecycleThe lifecycle event support for this component. |
private boolean | startedHas this component been started yet? |
protected int | concurrencyConcurrency level of the semaphore. |
protected boolean | fairnessFairness of the semaphore. |
protected boolean | blockBlock until a permit is available. |
protected boolean | interruptibleBlock interruptibly until a permit is available. |
Methods Summary |
---|
public void | addLifecycleListener(org.apache.catalina.LifecycleListener listener)Add a lifecycle event listener to this component.
lifecycle.addLifecycleListener(listener);
|
public boolean | controlConcurrency(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)Subclass friendly method to add conditions.
return true;
|
public org.apache.catalina.LifecycleListener[] | findLifecycleListeners()Get the lifecycle listeners associated with this lifecycle. If this
Lifecycle has no listeners registered, a zero-length array is returned.
return lifecycle.findLifecycleListeners();
|
public boolean | getBlock()
return block;
|
public int | getConcurrency()
return concurrency;
|
public boolean | getFairness()
return fairness;
|
public java.lang.String | getInfo()Return descriptive information about this Valve implementation.
return (info);
|
public boolean | getInterruptible()
return interruptible;
|
public void | invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)Do concurrency control on the request using the semaphore.
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);
}
|
public void | permitDenied(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)Subclass friendly method to add error handling when a permit isn't granted.
|
public void | removeLifecycleListener(org.apache.catalina.LifecycleListener listener)Remove a lifecycle event listener from this component.
lifecycle.removeLifecycleListener(listener);
|
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()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.
// 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);
|
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.
// 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;
|