org.apache.catalina.ha.ClusterListener Java Examples

The following examples show how to use org.apache.catalina.ha.ClusterListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleTomEETcpCluster.java    From tomee with Apache License 2.0 6 votes vote down vote up
@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) {
        clusterListener.setCluster(this); // we don't care about TomEEClusterListener since it is stateless
    }
    if (getClusterDeployer() != null) {
        getClusterDeployer().setCluster(this);
    }

    super.checkDefaults();
    addClusterListener(tomEEClusterListener); // since that's a singleton and all listeners have to be unique (contains()) we can always add it
}
 
Example #2
Source File: SimpleTcpCluster.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Get the cluster listeners associated with this cluster. If this Array has
 * no listeners registered, a zero-length array is returned.
 * @return the listener array
 */
public ClusterListener[] findClusterListeners() {
    if (clusterListeners.size() > 0) {
        ClusterListener[] listener = new ClusterListener[clusterListeners.size()];
        clusterListeners.toArray(listener);
        return listener;
    } else
        return new ClusterListener[0];

}
 
Example #3
Source File: SimpleTcpCluster.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Add cluster message listener and register cluster to this listener.
 *
 * @param listener The new listener
 * @see org.apache.catalina.ha.CatalinaCluster#addClusterListener(org.apache.catalina.ha.ClusterListener)
 */
@Override
public void addClusterListener(ClusterListener listener) {
    if (listener != null && !clusterListeners.contains(listener)) {
        clusterListeners.add(listener);
        listener.setCluster(this);
    }
}
 
Example #4
Source File: SimpleTcpCluster.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Remove message listener and deregister Cluster from listener.
 *
 * @param listener The listener to remove
 * @see org.apache.catalina.ha.CatalinaCluster#removeClusterListener(org.apache.catalina.ha.ClusterListener)
 */
@Override
public void removeClusterListener(ClusterListener listener) {
    if (listener != null) {
        clusterListeners.remove(listener);
        listener.setCluster(null);
    }
}
 
Example #5
Source File: SimpleTcpCluster.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
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()
                            + " transferred but no listener registered");
                }
            }
        }
    }
 
Example #6
Source File: SimpleTcpCluster.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Get the cluster listeners associated with this cluster. If this Array has
 * no listeners registered, a zero-length array is returned.
 */
public ClusterListener[] findClusterListeners() {
    if (clusterListeners.size() > 0) {
        ClusterListener[] listener = new ClusterListener[clusterListeners.size()];
        clusterListeners.toArray(listener);
        return listener;
    } else
        return new ClusterListener[0];

}
 
Example #7
Source File: SimpleTcpCluster.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Add cluster message listener and register cluster to this listener.
 * 
 * @see org.apache.catalina.ha.CatalinaCluster#addClusterListener(org.apache.catalina.ha.ClusterListener)
 */
@Override
public void addClusterListener(ClusterListener listener) {
    if (listener != null && !clusterListeners.contains(listener)) {
        clusterListeners.add(listener);
        listener.setCluster(this);
    }
}
 
Example #8
Source File: SimpleTcpCluster.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Remove message listener and deregister Cluster from listener.
 * 
 * @see org.apache.catalina.ha.CatalinaCluster#removeClusterListener(org.apache.catalina.ha.ClusterListener)
 */
@Override
public void removeClusterListener(ClusterListener listener) {
    if (listener != null) {
        clusterListeners.remove(listener);
        listener.setCluster(null);
    }
}
 
Example #9
Source File: SimpleTcpCluster.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example #10
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Get the cluster listeners associated with this cluster. If this Array has
 * no listeners registered, a zero-length array is returned.
 */
public ClusterListener[] findClusterListeners() {
    if (clusterListeners.size() > 0) {
        ClusterListener[] listener = new ClusterListener[clusterListeners.size()];
        clusterListeners.toArray(listener);
        return listener;
    } else
        return new ClusterListener[0];

}
 
Example #11
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Add cluster message listener and register cluster to this listener.
 * 
 * @see org.apache.catalina.ha.CatalinaCluster#addClusterListener(org.apache.catalina.ha.ClusterListener)
 */
@Override
public void addClusterListener(ClusterListener listener) {
    if (listener != null && !clusterListeners.contains(listener)) {
        clusterListeners.add(listener);
        listener.setCluster(this);
    }
}
 
Example #12
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Remove message listener and deregister Cluster from listener.
 * 
 * @see org.apache.catalina.ha.CatalinaCluster#removeClusterListener(org.apache.catalina.ha.ClusterListener)
 */
@Override
public void removeClusterListener(ClusterListener listener) {
    if (listener != null) {
        clusterListeners.remove(listener);
        listener.setCluster(null);
    }
}
 
Example #13
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example #14
Source File: CatalinaClusterSF.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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());
        }
    }
}