Search in sources :

Example 1 with ClusterListener

use of org.apache.catalina.ha.ClusterListener 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)

Example 2 with ClusterListener

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

the class SimpleTcpCluster method messageReceived.

public void messageReceived(ClusterMessage message) {
    if (log.isDebugEnabled() && message != null)
        log.debug("Assuming clocks are synched: Replication for " + message.getUniqueId() + " took=" + (System.currentTimeMillis() - (message).getTimestamp()) + " ms.");
    //invoke all the listeners
    boolean accepted = false;
    if (message != null) {
        for (Iterator<ClusterListener> iter = clusterListeners.iterator(); iter.hasNext(); ) {
            ClusterListener listener = iter.next();
            if (listener.accept(message)) {
                accepted = true;
                listener.messageReceived(message);
            }
        }
        if (!accepted && notifyLifecycleListenerOnFailure) {
            Member dest = message.getAddress();
            // Notify our interested LifecycleListeners
            fireLifecycleEvent(RECEIVE_MESSAGE_FAILURE_EVENT, new SendMessageData(message, dest, null));
            if (log.isDebugEnabled()) {
                log.debug("Message " + message.toString() + " from type " + message.getClass().getName() + " transfered but no listener registered");
            }
        }
    }
    return;
}
Also used : ClusterListener(org.apache.catalina.ha.ClusterListener) Member(org.apache.catalina.tribes.Member)

Example 3 with ClusterListener

use of org.apache.catalina.ha.ClusterListener in project tomee by apache.

the class SimpleTomEETcpCluster method checkDefaults.

@Override
protected void checkDefaults() {
    final List<ClusterListener> currentListeners = clusterListeners;
    final TomEEClusterListener tomEEClusterListener = SystemInstance.get().getComponent(TomEEClusterListener.class);
    if (currentListeners.size() == 1 && currentListeners.iterator().next() == tomEEClusterListener) {
        currentListeners.clear();
    }
    // else force the new cluster listener
    for (final ClusterListener clusterListener : currentListeners) {
        // we don't care about TomEEClusterListener since it is stateless
        clusterListener.setCluster(this);
    }
    if (getClusterDeployer() != null) {
        getClusterDeployer().setCluster(this);
    }
    super.checkDefaults();
    // since that's a singleton and all listeners have to be unique (contains()) we can always add it
    addClusterListener(tomEEClusterListener);
}
Also used : TomEEClusterListener(org.apache.tomee.catalina.cluster.TomEEClusterListener) TomEEClusterListener(org.apache.tomee.catalina.cluster.TomEEClusterListener) ClusterListener(org.apache.catalina.ha.ClusterListener)

Aggregations

ClusterListener (org.apache.catalina.ha.ClusterListener)3 ArrayList (java.util.ArrayList)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Valve (org.apache.catalina.Valve)1 CatalinaCluster (org.apache.catalina.ha.CatalinaCluster)1 ClusterDeployer (org.apache.catalina.ha.ClusterDeployer)1 ClusterManager (org.apache.catalina.ha.ClusterManager)1 SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)1 Channel (org.apache.catalina.tribes.Channel)1 Member (org.apache.catalina.tribes.Member)1 TomEEClusterListener (org.apache.tomee.catalina.cluster.TomEEClusterListener)1