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:
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private volatile boolean | |
| protected Pattern | |
| private static final ClassLoader | |
| private boolean | |
| private boolean | |
| private boolean | |
| private ConcurrentMap |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public String | |
| public void | invoke(Request
Request to be processed request, Response Response to be produced response)Implements org. Select the appropriate child Context to process this request, based on the specified request URI. |
| protected boolean | |
| public boolean | Returns: true if the thread can not be interrupted, otherwise false.If a thread is blocking to acquire a per session Semaphore, can that thread be interrupted? |
| public boolean | Returns: true if the thread should block, otherwise false to reject the concurrent requestIf 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? |
| public boolean | Returns: true if fairness is enabled, otherwise falseIf multiple threads attempt to acquire the same per session Semaphore, will permits be granted in the same order they were requested? |
| protected boolean | Returns: true if the session is past its expirationThe session to check session, long The current time to check for timeNow)Indicate whether the session has been idle for longer than its expiration date as of the supplied time. |
| protected void | onSemaphoreNotAcquired(Request
The request that will not be processed request, Response The response that will be used for this request response)Handle the case where a semaphore cannot be obtained. |
| public void | setContainer(Container
The Container instance with which this instance is to
be associated, or container)null to disassociate this instance
from any ContainerOverrides org. Implements org. Set the |
| public void | |
| public void | setSemaphoreAcquireUninterruptibly(boolean
true if the thread can not be interrupted, otherwise
false.Configure whether a thread blocking to acquire a per session Semaphore can be interrupted. |
| public void | setSemaphoreBlockOnAcquire(boolean
true to block, otherwise falseConfigure 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. |
| public void | setSemaphoreFairness(boolean
true if permits should be granted in the same order they are requested,
otherwise falseConfigure 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. |
| private void |
| clBindRequired | back to summary |
|---|---|
| private volatile boolean clBindRequired | |
| filter | back to summary |
|---|---|
| protected Pattern filter | |
| MY_CLASSLOADER | back to summary |
|---|---|
| private static final ClassLoader MY_CLASSLOADER | |
| semaphoreAcquireUninterruptibly | back to summary |
|---|---|
| private boolean semaphoreAcquireUninterruptibly | |
| semaphoreBlockOnAcquire | back to summary |
|---|---|
| private boolean semaphoreBlockOnAcquire | |
| semaphoreFairness | back to summary |
|---|---|
| private boolean semaphoreFairness | |
| sessionToSemaphoreMap | back to summary |
|---|---|
| private ConcurrentMap<String, PersistentValve. | |
| PersistentValve | back to summary |
|---|---|
| public PersistentValve() | |
| bind | back to summary |
|---|---|
| private void bind(Context context) | |
| getFilter | back to summary |
|---|---|
| public String getFilter() | |
| invoke | back to summary |
|---|---|
| public void invoke(Request request, Response response) throws IOException, ServletException Implements org. Select the appropriate child Context to process this request, based on the specified request URI. If no matching Context can be found, return an appropriate HTTP error.
| |
| isRequestWithoutSession | back to summary |
|---|---|
| protected boolean isRequestWithoutSession(String uri) | |
| isSemaphoreAcquireUninterruptibly | back to summary |
|---|---|
| public boolean isSemaphoreAcquireUninterruptibly() If a thread is blocking to acquire a per session Semaphore, can that thread be interrupted?
| |
| isSemaphoreBlockOnAcquire | back to summary |
|---|---|
| public 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?
| |
| isSemaphoreFairness | back to summary |
|---|---|
| public boolean isSemaphoreFairness() If multiple threads attempt to acquire the same per session Semaphore, will permits be granted in the same order they were requested?
| |
| isSessionStale | back to summary |
|---|---|
| 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.
| |
| onSemaphoreNotAcquired | back to summary |
|---|---|
| protected void onSemaphoreNotAcquired(Request request, Response response) throws IOException Handle the case where a semaphore cannot be obtained. The default behaviour is to return a 429 (too many requests) status code.
| |
| setContainer | back to summary |
|---|---|
| public void setContainer(Container container) Overrides org. Implements org. Doc from org. Set the | |
| setFilter | back to summary |
|---|---|
| public void setFilter(String filter) | |
| setSemaphoreAcquireUninterruptibly | back to summary |
|---|---|
| public void setSemaphoreAcquireUninterruptibly(boolean semaphoreAcquireUninterruptibly) Configure whether a thread blocking to acquire a per session Semaphore can be interrupted.
| |
| setSemaphoreBlockOnAcquire | back to summary |
|---|---|
| public 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.
| |
| setSemaphoreFairness | back to summary |
|---|---|
| public 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.
| |
| unbind | back to summary |
|---|---|
| private void unbind(Context context) | |
| Modifier and Type | Field and Description |
|---|---|
| private final Semaphore | |
| private final AtomicLong |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| private long | |
| private PersistentValve. | |
| private void | |
| private boolean |
| semaphore | back to summary |
|---|---|
| private final Semaphore semaphore | |
| usageCount | back to summary |
|---|---|
| private final AtomicLong usageCount | |
| UsageCountingSemaphore | back to summary |
|---|---|
| private UsageCountingSemaphore(boolean fairness) | |
| acquire | back to summary |
|---|---|
| private void acquire() throws InterruptedException | |
| acquireUninterruptibly | back to summary |
|---|---|
| private void acquireUninterruptibly() | |
| decrementAndGetUsageCount | back to summary |
|---|---|
| private long decrementAndGetUsageCount() | |
| incrementUsageCount | back to summary |
|---|---|
| private PersistentValve. | |
| release | back to summary |
|---|---|
| private void release() | |
| tryAcquire | back to summary |
|---|---|
| private boolean tryAcquire() | |