|
Apache Tomcat 6.0.53 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object 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 stickyness 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 java.lang.String |
info
The descriptive information about this implementation. |
protected LifecycleSupport |
lifecycle
The lifecycle event support for this component. |
static Log |
log
|
protected long |
numberOfSessions
number of session that no at this tomcat instanz hosted |
protected java.lang.String |
sessionIdAttribute
|
protected StringManager |
sm
The string manager for this package. |
protected boolean |
started
Has this component been started yet? |
Fields inherited from class org.apache.catalina.valves.ValveBase |
---|
container, containerLog, controller, domain, mserver, next, oname |
Fields inherited from interface org.apache.catalina.Lifecycle |
---|
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, DESTROY_EVENT, INIT_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT |
Constructor Summary | |
---|---|
JvmRouteBinderValve()
|
Method Summary | |
---|---|
void |
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component. |
protected void |
changeRequestSessionID(Request request,
Response response,
java.lang.String sessionId,
java.lang.String newSessionID)
Change Request Session id |
protected void |
changeSessionID(Request request,
Response response,
java.lang.String sessionId,
java.lang.String newSessionID,
Session catalinaSession)
change session id and send to all cluster nodes |
LifecycleListener[] |
findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. |
CatalinaCluster |
getCluster()
Returns the cluster the cluster deployer is associated with |
boolean |
getEnabled()
|
java.lang.String |
getInfo()
Return descriptive information about this implementation. |
protected java.lang.String |
getLocalJvmRoute(Request request)
get jvmroute from engine |
protected Manager |
getManager(Request request)
get Cluster DeltaManager |
long |
getNumberOfSessions()
|
java.lang.String |
getSessionIdAttribute()
set session id attribute to failed node for request. |
protected void |
handleJvmRoute(Request request,
Response response,
java.lang.String sessionId,
java.lang.String localJvmRoute)
Handle jvmRoute stickyness after tomcat instance failed. |
protected void |
handlePossibleTurnover(Request request,
Response response)
handle possible session turn over. |
void |
invoke(Request request,
Response response)
Detect possible the JVMRoute change at cluster backup node.. |
void |
removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component. |
protected void |
sendSessionIDClusterBackup(ClusterManager manager,
Request request,
java.lang.String sessionId,
java.lang.String newSessionID)
Send the changed Sessionid to all clusternodes. |
void |
setCluster(CatalinaCluster cluster)
Associates the cluster deployer with a cluster |
void |
setEnabled(boolean enabled)
|
protected void |
setNewSessionCookie(Request request,
Response response,
java.lang.String sessionId)
Deprecated. Use Request.changeSessionId(String) |
void |
setSessionIdAttribute(java.lang.String sessionIdAttribute)
get name of failed reqeust session attribute |
void |
start()
Prepare for the beginning of active use of the public methods of this component. |
void |
stop()
Gracefully terminate the active use of the public methods of this component. |
Methods inherited from class org.apache.catalina.valves.ValveBase |
---|
backgroundProcess, createObjectName, event, getContainer, getContainerName, getController, getDomain, getNext, getObjectName, getParentName, postDeregister, postRegister, preDeregister, preRegister, setContainer, setController, setNext, setObjectName, toString |
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, setNext |
Field Detail |
---|
public static Log log
protected static final java.lang.String info
protected CatalinaCluster cluster
protected StringManager sm
protected boolean started
protected boolean enabled
protected long numberOfSessions
protected java.lang.String sessionIdAttribute
protected LifecycleSupport lifecycle
Constructor Detail |
---|
public JvmRouteBinderValve()
Method Detail |
---|
public java.lang.String getInfo()
getInfo
in interface Valve
getInfo
in class ValveBase
public java.lang.String getSessionIdAttribute()
public void setSessionIdAttribute(java.lang.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 java.io.IOException, javax.servlet.ServletException
invoke
in interface Valve
invoke
in class ValveBase
request
- tomcat request being processedresponse
- tomcat response being processed
java.io.IOException
- if an input/output error has occurred
javax.servlet.ServletException
- if a servlet error has occurredprotected void handlePossibleTurnover(Request request, Response response)
request
- current requestresponse
- current responsehandleJvmRoute(Request, Response, String, String)
protected java.lang.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, Response response, java.lang.String sessionId, java.lang.String localJvmRoute)
request
- current requestresponse
- Tomcat ResponsesessionId
- request SessionID from CookielocalJvmRoute
- local jvmRouteprotected void changeSessionID(Request request, Response response, java.lang.String sessionId, java.lang.String newSessionID, Session catalinaSession)
request
- current requestresponse
- current responsesessionId
- original session idnewSessionID
- new session id for node migrationcatalinaSession
- current session with original session idprotected void changeRequestSessionID(Request request, Response response, java.lang.String sessionId, java.lang.String newSessionID)
request
- current requestresponse
- current responsesessionId
- original session idnewSessionID
- new session id for node migrationprotected void sendSessionIDClusterBackup(ClusterManager manager, Request request, java.lang.String sessionId, java.lang.String newSessionID)
manager
- ClusterManagersessionId
- current failed sessionidnewSessionID
- new session id, bind to the new cluster nodeJvmRouteSessionIDBinderListener.messageReceived(ClusterMessage)
protected void setNewSessionCookie(Request request, Response response, java.lang.String sessionId)
Request.changeSessionId(String)
Request.configureSessionCookie(javax.servlet.http.Cookie)
request
- current requestresponse
- Tomcat ResponsesessionId
- The session idpublic void addLifecycleListener(LifecycleListener listener)
addLifecycleListener
in interface Lifecycle
listener
- The listener to addpublic LifecycleListener[] findLifecycleListeners()
findLifecycleListeners
in interface Lifecycle
public void removeLifecycleListener(LifecycleListener listener)
removeLifecycleListener
in interface Lifecycle
listener
- The listener to addpublic void start() throws LifecycleException
configure()
,
and before any of the public methods of the component are utilized.
start
in interface Lifecycle
LifecycleException
- if this component detects a fatal error that prevents this
component from being usedpublic void stop() throws LifecycleException
stop
in interface Lifecycle
LifecycleException
- if this component detects a fatal error that needs to be
reported
|
Apache Tomcat 6.0.53 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |