FileDocCategorySizeDatePackage
JvmRouteSessionIDBinderListener.javaAPI DocApache Tomcat 6.0.146030Fri Jul 20 04:20:36 BST 2007org.apache.catalina.ha.session

JvmRouteSessionIDBinderListener

public class JvmRouteSessionIDBinderListener extends ClusterListener
Receive SessionID cluster change from other backup node after primary session node is failed.
author
Peter Rossbach
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
protected static final String
info
The descriptive information about this implementation.
protected boolean
started
private long
numberOfSessions
number of session that goes to this cluster node
Constructors Summary
public JvmRouteSessionIDBinderListener()


    //--Constructor---------------------------------------------

      
    
Methods Summary
public booleanaccept(org.apache.catalina.ha.ClusterMessage msg)
Accept only SessionIDMessages

param
msg ClusterMessage
return
boolean - returns true to indicate that messageReceived should be invoked. If false is returned, the messageReceived method will not be invoked.

        return (msg instanceof SessionIDMessage);
    
public java.lang.StringgetInfo()
Return descriptive information about this implementation.


        return (info);

    
public longgetNumberOfSessions()

return
Returns the numberOfSessions.

        return numberOfSessions;
    
public voidmessageReceived(org.apache.catalina.ha.ClusterMessage msg)
Callback from the cluster, when a message is received, The cluster will broadcast it invoking the messageReceived on the receiver.

param
msg ClusterMessage - the message received from the cluster

        if (msg instanceof SessionIDMessage && msg != null) {
            SessionIDMessage sessionmsg = (SessionIDMessage) msg;
            if (log.isDebugEnabled())
                log.debug(sm.getString(
                        "jvmRoute.receiveMessage.sessionIDChanged", sessionmsg
                                .getOrignalSessionID(), sessionmsg
                                .getBackupSessionID(), sessionmsg
                                .getContextPath()));
            Container container = getCluster().getContainer();
            Container host = null ;
            if(container instanceof Engine) {
                host = container.findChild(sessionmsg.getHost());
            } else {
                host = container ;
            }
            if (host != null) {
                Context context = (Context) host.findChild(sessionmsg
                        .getContextPath());
                if (context != null) {
                    try {
                        Session session = context.getManager().findSession(
                                sessionmsg.getOrignalSessionID());
                        if (session != null) {
                            session.setId(sessionmsg.getBackupSessionID());
                        } else if (log.isInfoEnabled())
                            log.info(sm.getString("jvmRoute.lostSession",
                                    sessionmsg.getOrignalSessionID(),
                                    sessionmsg.getContextPath()));
                    } catch (IOException e) {
                        log.error(e);
                    }

                } else if (log.isErrorEnabled())
                    log.error(sm.getString("jvmRoute.contextNotFound",
                            sessionmsg.getContextPath(), ((StandardEngine) host
                                    .getParent()).getJvmRoute()));
            } else if (log.isErrorEnabled())
                log.error(sm.getString("jvmRoute.hostNotFound", sessionmsg.getContextPath()));
        }
        return;
    
public voidstart()
Add this Mover as Cluster Listener ( receiver)

throws
LifecycleException

        if (started)
            return;
        getCluster().addClusterListener(this);
        started = true;
        if (log.isInfoEnabled())
            log.info(sm.getString("jvmRoute.clusterListener.started"));
    
public voidstop()
Remove this from Cluster Listener

throws
LifecycleException

        started = false;
        getCluster().removeClusterListener(this);
        if (log.isInfoEnabled())
            log.info(sm.getString("jvmRoute.clusterListener.stopped"));