Valve that implements per-request session persistence. It is intended to be used with non-sticky load-balancers and a PersistentManager. The Valve works by loading the session from the Store at the start of the request, the request then updates the session as required and the Valve saves the session
| 71 | * </ul> |
| 72 | */ |
| 73 | public class PersistentValve extends ValveBase { |
| 74 | |
| 75 | private static final Log log = LogFactory.getLog(PersistentValve.class); |
| 76 | |
| 77 | // Saves a couple of calls to getClassLoader() on every request. Under high |
| 78 | // load these calls took just long enough to appear as a hot spot (although |
| 79 | // a very minor one) in a profiler. |
| 80 | private static final ClassLoader MY_CLASSLOADER = PersistentValve.class.getClassLoader(); |
| 81 | |
| 82 | private volatile boolean clBindRequired; |
| 83 | |
| 84 | /** |
| 85 | * Regular expression pattern used to filter requests that should bypass session persistence. |
| 86 | */ |
| 87 | protected Pattern filter = null; |
| 88 | |
| 89 | private final ConcurrentMap<String,UsageCountingSemaphore> sessionToSemaphoreMap = new ConcurrentHashMap<>(); |
| 90 | |
| 91 | private boolean semaphoreFairness = true; |
| 92 | |
| 93 | private boolean semaphoreBlockOnAcquire = true; |
| 94 | |
| 95 | private boolean semaphoreAcquireUninterruptibly = true; |
| 96 | |
| 97 | |
| 98 | /** |
| 99 | * Constructs a new PersistentValve instance. |
| 100 | */ |
| 101 | public PersistentValve() { |
| 102 | super(true); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | @Override |
| 107 | public void setContainer(Container container) { |
| 108 | super.setContainer(container); |
| 109 | clBindRequired = container instanceof Engine || container instanceof Host; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | @Override |
| 114 | public void invoke(Request request, Response response) throws IOException, ServletException { |
| 115 | |
| 116 | // request without session |
| 117 | if (isRequestWithoutSession(request.getDecodedRequestURI())) { |
| 118 | if (containerLog.isTraceEnabled()) { |
| 119 | containerLog.trace(sm.getString("persistentValve.requestIgnore", request.getDecodedRequestURI())); |
| 120 | } |
| 121 | getNext().invoke(request, response); |
| 122 | return; |
| 123 | } else if (containerLog.isTraceEnabled()) { |
| 124 | containerLog.trace(sm.getString("persistentValve.requestProcess", request.getDecodedRequestURI())); |
| 125 | } |
| 126 | |
| 127 | // Select the Context to be used for this Request |
| 128 | Context context = request.getContext(); |
| 129 | if (context == null) { |
| 130 | response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sm.getString("standardHost.noContext")); |
nothing calls this directly
no test coverage detected