Class JvmRouteBinderValve

  • All Implemented Interfaces:, Contained, ClusterValve, JmxEnabled, Lifecycle, Valve

    public class JvmRouteBinderValve
    extends ValveBase
    implements ClusterValve
    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!

    Add this Valve to your cluster definition at conf/server.xml .

      <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
    A Trick:
    You can enable this mod_jk turnover mode via JMX before you drop a node to all backup nodes! Set enable true on all JvmRouteBinderValve backups, disable worker at mod_jk and then drop node and restart it! Then enable mod_jk worker and disable JvmRouteBinderValves again. This use case means that only requested sessions are migrated.
    Peter Rossbach
    • Field Detail

      • log

        public static final Log log
      • sm

        protected static final StringManager sm
        The string manager for this package.
      • enabled

        protected boolean enabled
        enabled this component
      • numberOfSessions

        protected long numberOfSessions
        number of session that no at this tomcat instance hosted
      • sessionIdAttribute

        protected java.lang.String sessionIdAttribute
    • Constructor Detail

      • JvmRouteBinderValve

        public JvmRouteBinderValve()
    • Method Detail

      • getSessionIdAttribute

        public java.lang.String getSessionIdAttribute()
        set session id attribute to failed node for request.
        Returns the sessionIdAttribute.
      • setSessionIdAttribute

        public void setSessionIdAttribute​(java.lang.String sessionIdAttribute)
        get name of failed request session attribute
        sessionIdAttribute - The sessionIdAttribute to set.
      • getNumberOfSessions

        public long getNumberOfSessions()
        Returns the number of migrated sessions.
      • getEnabled

        public boolean getEnabled()
        Returns the enabled.
      • setEnabled

        public void setEnabled​(boolean enabled)
        enabled - The enabled to set.
      • invoke

        public void invoke​(Request request,
                           Response response)
        Detect possible the JVMRoute change at cluster backup node..
        Specified by:
        invoke in interface Valve
        request - tomcat request being processed
        response - tomcat response being processed
        Throws: - if an input/output error has occurred
        ServletException - if a servlet error has occurred
      • getLocalJvmRoute

        protected java.lang.String getLocalJvmRoute​(Request request)
        get jvmroute from engine
        request - current request
        return jvmRoute from ManagerBase or null
      • getManager

        protected Manager getManager​(Request request)
        get ClusterManager
        request - current request
        manager or null
      • setCluster

        public void setCluster​(CatalinaCluster cluster)
        Description copied from interface: ClusterValve
        Associates the cluster deployer with a cluster
        Specified by:
        setCluster in interface ClusterValve
        cluster - The cluster to set.
      • handleJvmRoute

        protected void handleJvmRoute​(Request request,
                                      java.lang.String sessionId,
                                      java.lang.String localJvmRoute)
        Handle jvmRoute stickiness after tomcat instance failed. After this correction a new Cookie send to client with new jvmRoute and the SessionID change propagate to the other cluster nodes.
        request - current request
        sessionId - request SessionID from Cookie
        localJvmRoute - local jvmRoute
      • changeSessionID

        protected void changeSessionID​(Request request,
                                       java.lang.String sessionId,
                                       java.lang.String newSessionID,
                                       Session catalinaSession)
        change session id and send to all cluster nodes
        request - current request
        sessionId - original session id
        newSessionID - new session id for node migration
        catalinaSession - current session with original session id
      • changeRequestSessionID

        protected void changeRequestSessionID​(Request request,
                                              java.lang.String sessionId,
                                              java.lang.String newSessionID)
        Change Request Session id
        request - current request
        sessionId - original session id
        newSessionID - new session id for node migration
      • changeSessionAuthenticationNote

        protected void changeSessionAuthenticationNote​(java.lang.String sessionId,
                                                       java.lang.String newSessionID,
                                                       Session catalinaSession)
        Change the current session ID that is stored in a session note during authentication. It is part of the CSRF protection.
        sessionId - The original session ID
        newSessionID - The new session ID for node migration
        catalinaSession - The session object (that will be using the new session ID at the point this method is called)