public class PersistentValve extends ValveBase
To avoid conflicts and/or errors when updating the session store, each session must only be accessed by no more than
one concurrent request. The filter field can be used to define requests (e.g. those for static resources)
that do not need access to the session and can Requests for resources that do not need to access the session and can
bypass the session load/save functionality provided by this Valve.
The Valve uses a per session Semaphore to ensure that each session is accessed by no more than one request at
a time within a single Tomcat instance. The behaviour if multiple requests try to access the session concurrently can
be controlled by the semaphoreFairness, semaphoreBlockOnAcquire and semaphoreAcquireUninterruptibly fields. If a request fails to obtain the Semaphore, the response is generated by the
onSemaphoreNotAcquired(Request, Response) method which, by default, returns a 429 status code.
The per session Semaphores only provide limited protection against concurrent requests within a single Tomcat instance. If multiple requests access the same session concurrently across different Tomcat instances, update conflicts and/or session data loss and/or errors are very likely.
USAGE CONSTRAINTS:
Lifecycle.SingleUse| Modifier and Type | Field and Description |
|---|---|
protected java.util.regex.Pattern |
filter |
asyncSupported, container, containerLog, next, smmserverAFTER_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 and Description |
|---|
PersistentValve() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getFilter() |
void |
invoke(Request request,
Response response)
Select the appropriate child Context to process this request, based on the specified request URI.
|
protected boolean |
isRequestWithoutSession(java.lang.String uri) |
boolean |
isSemaphoreAcquireUninterruptibly()
If a thread is blocking to acquire a per session Semaphore, can that thread be interrupted?
|
boolean |
isSemaphoreBlockOnAcquire()
If a thread attempts to acquire the per session Semaphore while it is being used by another request, should the
thread block to wait for the Semaphore or should the request be rejected?
|
boolean |
isSemaphoreFairness()
If multiple threads attempt to acquire the same per session Semaphore, will permits be granted in the same order
they were requested?
|
protected boolean |
isSessionStale(Session session,
long timeNow)
Indicate whether the session has been idle for longer than its expiration date as of the supplied time.
|
protected void |
onSemaphoreNotAcquired(Request request,
Response response)
Handle the case where a semaphore cannot be obtained.
|
void |
setContainer(Container container)
Set the
Container with which this instance is associated. |
void |
setFilter(java.lang.String filter) |
void |
setSemaphoreAcquireUninterruptibly(boolean semaphoreAcquireUninterruptibly)
Configure whether a thread blocking to acquire a per session Semaphore can be interrupted.
|
void |
setSemaphoreBlockOnAcquire(boolean semaphoreBlockOnAcquire)
Configure whether a thread should block and wait for the per session Semaphore or reject the request if the
Semaphore is being used by another request.
|
void |
setSemaphoreFairness(boolean semaphoreFairness)
Configure whether the per session Semaphores will handle granting of permits in the same order they were
requested if multiple threads attempt to acquire the same Semaphore.
|
backgroundProcess, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setNext, startInternal, stopInternal, toStringdestroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisteraddLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stoppublic void setContainer(Container container)
ContainedContainer with which this instance is associated.setContainer in interface ContainedsetContainer in class ValveBasecontainer - The Container instance with which this instance is to
be associated, or null to disassociate this instance
from any Containerpublic void invoke(Request request, Response response) throws java.io.IOException, ServletException
request - Request to be processedresponse - Response to be producedjava.io.IOException - if an input/output error occurredServletException - if a servlet error occurredprotected void onSemaphoreNotAcquired(Request request, Response response) throws java.io.IOException
request - The request that will not be processedresponse - The response that will be used for this requestjava.io.IOException - If an I/O error occurs while working with the request or responseprotected boolean isSessionStale(Session session, long timeNow)
session - The session to checktimeNow - The current time to check fortrue if the session is past its expirationprotected boolean isRequestWithoutSession(java.lang.String uri)
public java.lang.String getFilter()
public void setFilter(java.lang.String filter)
public boolean isSemaphoreFairness()
true if fairness is enabled, otherwise falsepublic void setSemaphoreFairness(boolean semaphoreFairness)
semaphoreFairness - true if permits should be granted in the same order they are requested,
otherwise falsepublic boolean isSemaphoreBlockOnAcquire()
true if the thread should block, otherwise false to reject the concurrent requestpublic void setSemaphoreBlockOnAcquire(boolean semaphoreBlockOnAcquire)
semaphoreBlockOnAcquire - true to block, otherwise falsepublic boolean isSemaphoreAcquireUninterruptibly()
true if the thread can not be interrupted, otherwise false.public void setSemaphoreAcquireUninterruptibly(boolean semaphoreAcquireUninterruptibly)
semaphoreAcquireUninterruptibly - true if the thread can not be interrupted, otherwise
false.Copyright © 2000-2024 Apache Software Foundation.
Apache Tomcat, Tomcat, Apache, the Apache Tomcat logo and the Apache logo are either registered trademarks or trademarks of the Apache Software Foundation.