Search in sources :

Example 1 with ClusterManager

use of org.apache.catalina.ha.ClusterManager in project tomcat70 by apache.

the class SimpleTcpCluster method createManager.

/**
 * Create new Manager without add to cluster (comes with start the manager)
 *
 * @param name
 *            Context Name of this manager
 * @see org.apache.catalina.Cluster#createManager(java.lang.String)
 * @see DeltaManager#start()
 */
@Override
public synchronized Manager createManager(String name) {
    if (log.isDebugEnabled()) {
        log.debug("Creating ClusterManager for context " + name + " using class " + getManagerTemplate().getClass().getName());
    }
    ClusterManager manager = null;
    try {
        manager = managerTemplate.cloneFromTemplate();
        manager.setName(name);
    } catch (Exception x) {
        log.error("Unable to clone cluster manager, defaulting to org.apache.catalina.ha.session.DeltaManager", x);
        manager = new org.apache.catalina.ha.session.DeltaManager();
    } finally {
        if (manager != null)
            manager.setCluster(this);
    }
    return manager;
}
Also used : DeltaManager(org.apache.catalina.ha.session.DeltaManager) ClusterManager(org.apache.catalina.ha.ClusterManager) LifecycleException(org.apache.catalina.LifecycleException)

Example 2 with ClusterManager

use of org.apache.catalina.ha.ClusterManager in project tomcat70 by apache.

the class SimpleTcpCluster method removeManager.

/**
 * Remove an application from cluster replication bus.
 *
 * @see org.apache.catalina.Cluster#removeManager(Manager)
 */
@Override
public void removeManager(Manager manager) {
    if (manager != null && manager instanceof ClusterManager) {
        ClusterManager cmgr = (ClusterManager) manager;
        // Notify our interested LifecycleListeners
        fireLifecycleEvent(BEFORE_MANAGERUNREGISTER_EVENT, manager);
        managers.remove(getManagerName(cmgr.getName(), manager));
        cmgr.setCluster(null);
        // Notify our interested LifecycleListeners
        fireLifecycleEvent(AFTER_MANAGERUNREGISTER_EVENT, manager);
    }
}
Also used : ClusterManager(org.apache.catalina.ha.ClusterManager)

Example 3 with ClusterManager

use of org.apache.catalina.ha.ClusterManager in project tomcat70 by apache.

the class SimpleTcpCluster method registerManager.

@Override
public void registerManager(Manager manager) {
    if (!(manager instanceof ClusterManager)) {
        log.warn("Manager [ " + manager + "] does not implement ClusterManager, addition to cluster has been aborted.");
        return;
    }
    ClusterManager cmanager = (ClusterManager) manager;
    // Notify our interested LifecycleListeners
    fireLifecycleEvent(BEFORE_MANAGERREGISTER_EVENT, manager);
    String clusterName = getManagerName(cmanager.getName(), manager);
    cmanager.setName(clusterName);
    cmanager.setCluster(this);
    managers.put(clusterName, cmanager);
    // Notify our interested LifecycleListeners
    fireLifecycleEvent(AFTER_MANAGERREGISTER_EVENT, manager);
}
Also used : ClusterManager(org.apache.catalina.ha.ClusterManager)

Example 4 with ClusterManager

use of org.apache.catalina.ha.ClusterManager in project tomcat70 by apache.

the class ClusterSessionListener method messageReceived.

/**
 * Callback from the cluster, when a message is received, The cluster will
 * broadcast it invoking the messageReceived on the receiver.
 *
 * @param myobj
 *            ClusterMessage - the message received from the cluster
 */
@Override
public void messageReceived(ClusterMessage myobj) {
    if (myobj != null && myobj instanceof SessionMessage) {
        SessionMessage msg = (SessionMessage) myobj;
        String ctxname = msg.getContextName();
        // check if the message is a EVT_GET_ALL_SESSIONS,
        // if so, wait until we are fully started up
        Map<String, ClusterManager> managers = cluster.getManagers();
        if (ctxname == null) {
            for (Map.Entry<String, ClusterManager> entry : managers.entrySet()) {
                if (entry.getValue() != null)
                    entry.getValue().messageDataReceived(msg);
                else {
                    // up
                    if (log.isDebugEnabled())
                        log.debug("Context manager doesn't exist:" + entry.getKey());
                }
            }
        } else {
            ClusterManager mgr = managers.get(ctxname);
            if (mgr != null) {
                mgr.messageDataReceived(msg);
            } else {
                if (log.isWarnEnabled())
                    log.warn("Context manager doesn't exist:" + ctxname);
                // timeout of GET_ALL_SESSIONS sync phase.
                if (msg.getEventType() == SessionMessage.EVT_GET_ALL_SESSIONS) {
                    SessionMessage replymsg = new SessionMessageImpl(ctxname, SessionMessage.EVT_ALL_SESSION_NOCONTEXTMANAGER, null, "NO-CONTEXT-MANAGER", "NO-CONTEXT-MANAGER-" + ctxname);
                    cluster.send(replymsg, msg.getAddress());
                }
            }
        }
    }
    return;
}
Also used : ClusterManager(org.apache.catalina.ha.ClusterManager) Map(java.util.Map)

Example 5 with ClusterManager

use of org.apache.catalina.ha.ClusterManager in project tomcat by apache.

the class CatalinaClusterSF method storeChildren.

/**
 * Store the specified Cluster children.
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aCluster
 *            Cluster whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aCluster, StoreDescription parentDesc) throws Exception {
    if (aCluster instanceof CatalinaCluster) {
        CatalinaCluster cluster = (CatalinaCluster) aCluster;
        if (cluster instanceof SimpleTcpCluster) {
            SimpleTcpCluster tcpCluster = (SimpleTcpCluster) cluster;
            // Store nested <Manager> element
            ClusterManager manager = tcpCluster.getManagerTemplate();
            if (manager != null) {
                storeElement(aWriter, indent, manager);
            }
        }
        // Store nested <Channel> element
        Channel channel = cluster.getChannel();
        if (channel != null) {
            storeElement(aWriter, indent, channel);
        }
        // Store nested <Deployer> element
        ClusterDeployer deployer = cluster.getClusterDeployer();
        if (deployer != null) {
            storeElement(aWriter, indent, deployer);
        }
        // Store nested <Valve> element
        // ClusterValve are not store at Hosts element, see
        Valve[] valves = cluster.getValves();
        storeElementArray(aWriter, indent, valves);
        if (aCluster instanceof SimpleTcpCluster) {
            // Store nested <Listener> elements
            LifecycleListener[] listeners = ((SimpleTcpCluster) cluster).findLifecycleListeners();
            storeElementArray(aWriter, indent, listeners);
            // Store nested <ClusterListener> elements
            ClusterListener[] mlisteners = ((SimpleTcpCluster) cluster).findClusterListeners();
            List<ClusterListener> clusterListeners = new ArrayList<>();
            for (ClusterListener clusterListener : mlisteners) {
                if (clusterListener != deployer) {
                    clusterListeners.add(clusterListener);
                }
            }
            storeElementArray(aWriter, indent, clusterListeners.toArray());
        }
    }
}
Also used : ClusterDeployer(org.apache.catalina.ha.ClusterDeployer) Channel(org.apache.catalina.tribes.Channel) ArrayList(java.util.ArrayList) LifecycleListener(org.apache.catalina.LifecycleListener) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) ClusterListener(org.apache.catalina.ha.ClusterListener) Valve(org.apache.catalina.Valve) ClusterManager(org.apache.catalina.ha.ClusterManager)

Aggregations

ClusterManager (org.apache.catalina.ha.ClusterManager)16 Map (java.util.Map)2 Context (org.apache.catalina.Context)2 LifecycleException (org.apache.catalina.LifecycleException)2 StandardContext (org.apache.catalina.core.StandardContext)2 CatalinaCluster (org.apache.catalina.ha.CatalinaCluster)2 DeltaManager (org.apache.catalina.ha.session.DeltaManager)2 ObjectInputStream (java.io.ObjectInputStream)1 ArrayList (java.util.ArrayList)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Valve (org.apache.catalina.Valve)1 ClusterDeployer (org.apache.catalina.ha.ClusterDeployer)1 ClusterListener (org.apache.catalina.ha.ClusterListener)1 ClusterMessage (org.apache.catalina.ha.ClusterMessage)1 DeltaSession (org.apache.catalina.ha.session.DeltaSession)1 SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)1 Channel (org.apache.catalina.tribes.Channel)1 ReplicationStream (org.apache.catalina.tribes.io.ReplicationStream)1