public class LoadBalancerDrainingValve extends ValveBase
A Valve to detect situations where a load-balanced node receiving a request has been deactivated by the load balancer (JK_LB_ACTIVATION=DIS) and the incoming request has no valid session.
In these cases, the user's session cookie should be removed if it exists, any ";jsessionid" parameter should be removed from the request URI, and the client should be redirected to the same URI. This will cause the load-balanced to re-balance the client to another server.
All this work is required because when the activation state of a node is DISABLED, the load-balancer will still send requests to the node if they appear to have a session on that node. Since mod_jk doesn't actually know whether the session id is valid, it will send the request blindly to the disabled node, which makes it take much longer to drain the node than strictly necessary.
For testing purposes, a special cookie can be configured and used
by a client to ignore the normal behavior of this Valve and allow
a client to get a new session on a DISABLED node. See
setIgnoreCookieName(java.lang.String)
and setIgnoreCookieValue(java.lang.String)
to configure those values.
This Valve should be installed earlier in the Valve pipeline than any authentication valves, as the redirection should take place before an authentication valve would save a request to a protected resource.
Lifecycle.SingleUse
Modifier and Type | Field and Description |
---|---|
static String |
ATTRIBUTE_KEY_JK_LB_ACTIVATION
The request attribute key where the load-balancer's activation state
can be found.
|
asyncSupported, container, containerLog, next, sm
mserver
AFTER_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 |
---|
LoadBalancerDrainingValve() |
Modifier and Type | Method and Description |
---|---|
String |
getIgnoreCookieName()
Gets the name of the cookie that can be used to override the
re-balancing behavior of this Valve when the current node is
in the DISABLED activation state.
|
String |
getIgnoreCookieValue()
Gets the expected value of the cookie that can be used to override the
re-balancing behavior of this Valve when the current node is
in the DISABLED activation state.
|
void |
invoke(Request request,
Response response)
Perform request processing as required by this Valve.
|
void |
setIgnoreCookieName(String cookieName)
Sets the name of the cookie that can be used to override the
re-balancing behavior of this Valve when the current node is
in the DISABLED activation state.
|
void |
setIgnoreCookieValue(String cookieValue)
Sets the expected value of the cookie that can be used to override the
re-balancing behavior of this Valve when the current node is
in the DISABLED activation state.
|
void |
setRedirectStatusCode(int code)
Sets the HTTP response code that will be used to redirect the request
back to the load-balancer for re-balancing.
|
backgroundProcess, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, startInternal, stopInternal, toString
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
public static final String ATTRIBUTE_KEY_JK_LB_ACTIVATION
public void setRedirectStatusCode(int code)
code
- The code to use for the redirectpublic String getIgnoreCookieName()
setIgnoreCookieValue(java.lang.String)
public void setIgnoreCookieName(String cookieName)
cookieName
- The cookie name to use to ignore normal
processing rules.getIgnoreCookieValue()
public String getIgnoreCookieValue()
setIgnoreCookieValue(java.lang.String)
public void setIgnoreCookieValue(String cookieValue)
cookieValue
- The cookie value to use to ignore normal
processing rules.getIgnoreCookieValue()
public void invoke(Request request, Response response) throws IOException, ServletException
Valve
Perform request processing as required by this Valve.
An individual Valve MAY perform the following actions, in the specified order:
getNext().invoke()
.
A Valve MUST NOT do any of the following things:
getNext().invoke()
method has returned.
getNext().invoke()
method has
returned.
request
- The servlet request to be processedresponse
- The servlet response to be createdIOException
- if an input/output error occurs, or is thrown
by a subsequently invoked Valve, Filter, or ServletServletException
- if a servlet error occurs, or is thrown
by a subsequently invoked Valve, Filter, or ServletCopyright © 2000-2020 Apache Software Foundation. All Rights Reserved.