|
Apache Tomcat 7.0.28 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.catalina.util.LifecycleBase org.apache.catalina.util.LifecycleMBeanBase org.apache.catalina.valves.ValveBase org.apache.catalina.ha.session.JvmRouteBinderValve
public class JvmRouteBinderValve
Valve to handle Tomcat jvmRoute takeover using mod_jk module after node failure. After a node crashes, subsequent requests go to other cluster nodes. That incurs a drop in performance. When this Valve is enabled on a backup node and sees a request, which was intended for another (thus failed) node, it will rewrite the cookie jsessionid information to use the route to this backup cluster node, that answered the request. After the response is delivered to the client, all subsequent client requests will go directly to the backup node. The change of sessionid is also sent to all other cluster nodes. After all that, the session stickiness will work directly to the backup node and the traffic will not go back to the failed node after it is restarted!
For this valve to function correctly, so that all nodes of the cluster
receive the sessionid change notifications that it generates, the following
ClusterListener MUST be configured at all nodes of the cluster:
JvmRouteSessionIDBinderListener
since Tomcat 5.5.10, and both
JvmRouteSessionIDBinderListener and JvmRouteSessionIDBinderLifecycleListener
for earlier versions of Tomcat.
Add this Valve to your host definition at conf/server.xml .
Since 5.5.10 as direct cluster valve:
<Cluster> <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" /> </Cluster>
<Host> <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" /> </Host>A Trick:
Field Summary | |
---|---|
protected CatalinaCluster |
cluster
the cluster |
protected boolean |
enabled
enabled this component |
protected static String |
info
The descriptive information about this implementation. |
static Log |
log
|
protected long |
numberOfSessions
number of session that no at this tomcat instanz hosted |
protected String |
sessionIdAttribute
|
protected static StringManager |
sm
The string manager for this package. |
Fields inherited from class org.apache.catalina.valves.ValveBase |
---|
asyncSupported, container, containerLog, next |
Fields inherited from class org.apache.catalina.util.LifecycleMBeanBase |
---|
mserver |
Fields inherited from interface org.apache.catalina.Lifecycle |
---|
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 Summary | |
---|---|
JvmRouteBinderValve()
|
Method Summary | |
---|---|
protected void |
changeRequestSessionID(Request request,
String sessionId,
String newSessionID)
Change Request Session id |
protected void |
changeSessionID(Request request,
String sessionId,
String newSessionID,
Session catalinaSession)
change session id and send to all cluster nodes |
CatalinaCluster |
getCluster()
Returns the cluster the cluster deployer is associated with |
boolean |
getEnabled()
|
String |
getInfo()
Return descriptive information about this implementation. |
protected String |
getLocalJvmRoute(Request request)
get jvmroute from engine |
protected Manager |
getManager(Request request)
get Cluster DeltaManager |
long |
getNumberOfSessions()
|
String |
getSessionIdAttribute()
set session id attribute to failed node for request. |
protected void |
handleJvmRoute(Request request,
String sessionId,
String localJvmRoute)
Handle jvmRoute stickiness after tomcat instance failed. |
protected void |
handlePossibleTurnover(Request request)
handle possible session turn over. |
void |
invoke(Request request,
Response response)
Detect possible the JVMRoute change at cluster backup node.. |
protected void |
sendSessionIDClusterBackup(Request request,
String sessionId,
String newSessionID)
Send the changed Sessionid to all clusternodes. |
void |
setCluster(CatalinaCluster cluster)
Associates the cluster deployer with a cluster |
void |
setEnabled(boolean enabled)
|
void |
setSessionIdAttribute(String sessionIdAttribute)
get name of failed request session attribute |
protected void |
startInternal()
Start this component and implement the requirements of LifecycleBase.startInternal() . |
protected void |
stopInternal()
Stop this component and implement the requirements of LifecycleBase.stopInternal() . |
Methods inherited from class org.apache.catalina.valves.ValveBase |
---|
backgroundProcess, event, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, toString |
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase |
---|
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister |
Methods inherited from class org.apache.catalina.util.LifecycleBase |
---|
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, init, removeLifecycleListener, setState, setState, start, stop |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.apache.catalina.Valve |
---|
backgroundProcess, event, getNext, isAsyncSupported, setNext |
Field Detail |
---|
public static final Log log
protected static final String info
protected CatalinaCluster cluster
protected static final StringManager sm
protected boolean enabled
protected long numberOfSessions
protected String sessionIdAttribute
Constructor Detail |
---|
public JvmRouteBinderValve()
Method Detail |
---|
public String getInfo()
getInfo
in interface Valve
getInfo
in class ValveBase
public String getSessionIdAttribute()
public void setSessionIdAttribute(String sessionIdAttribute)
sessionIdAttribute
- The sessionIdAttribute to set.public long getNumberOfSessions()
public boolean getEnabled()
public void setEnabled(boolean enabled)
enabled
- The enabled to set.public void invoke(Request request, Response response) throws IOException, ServletException
invoke
in interface Valve
invoke
in class ValveBase
request
- tomcat request being processedresponse
- tomcat response being processed
IOException
- if an input/output error has occurred
ServletException
- if a servlet error has occurredprotected void handlePossibleTurnover(Request request)
request
- current requesthandleJvmRoute(Request, String, String)
protected String getLocalJvmRoute(Request request)
request
- current request
protected Manager getManager(Request request)
request
- current request
public CatalinaCluster getCluster()
ClusterValve
getCluster
in interface ClusterValve
public void setCluster(CatalinaCluster cluster)
ClusterValve
setCluster
in interface ClusterValve
cluster
- The cluster to set.protected void handleJvmRoute(Request request, String sessionId, String localJvmRoute)
request
- current requestsessionId
- request SessionID from CookielocalJvmRoute
- local jvmRouteprotected void changeSessionID(Request request, String sessionId, String newSessionID, Session catalinaSession)
request
- current requestsessionId
- original session idnewSessionID
- new session id for node migrationcatalinaSession
- current session with original session idprotected void changeRequestSessionID(Request request, String sessionId, String newSessionID)
request
- current requestsessionId
- original session idnewSessionID
- new session id for node migrationprotected void sendSessionIDClusterBackup(Request request, String sessionId, String newSessionID)
sessionId
- current failed sessionidnewSessionID
- new session id, bind to the new cluster nodeJvmRouteSessionIDBinderListener.messageReceived(
org.apache.catalina.ha.ClusterMessage)
protected void startInternal() throws LifecycleException
LifecycleBase.startInternal()
.
startInternal
in class ValveBase
LifecycleException
- if this component detects a fatal error
that prevents this component from being usedprotected void stopInternal() throws LifecycleException
LifecycleBase.stopInternal()
.
stopInternal
in class ValveBase
LifecycleException
- if this component detects a fatal error
that prevents this component from being used
|
Apache Tomcat 7.0.28 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |