Search in sources :

Example 6 with Cluster

use of org.apache.catalina.Cluster in project tomcat by apache.

the class ContainerBase method stopInternal.

/**
     * Stop this component and implement the requirements
     * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents this component from being used
     */
@Override
protected synchronized void stopInternal() throws LifecycleException {
    // Stop our thread
    threadStop();
    setState(LifecycleState.STOPPING);
    // Stop the Valves in our pipeline (including the basic), if any
    if (pipeline instanceof Lifecycle && ((Lifecycle) pipeline).getState().isAvailable()) {
        ((Lifecycle) pipeline).stop();
    }
    // Stop our child containers, if any
    Container[] children = findChildren();
    List<Future<Void>> results = new ArrayList<>();
    for (int i = 0; i < children.length; i++) {
        results.add(startStopExecutor.submit(new StopChild(children[i])));
    }
    boolean fail = false;
    for (Future<Void> result : results) {
        try {
            result.get();
        } catch (Exception e) {
            log.error(sm.getString("containerBase.threadedStopFailed"), e);
            fail = true;
        }
    }
    if (fail) {
        throw new LifecycleException(sm.getString("containerBase.threadedStopFailed"));
    }
    // Stop our subordinate components, if any
    Realm realm = getRealmInternal();
    if (realm instanceof Lifecycle) {
        ((Lifecycle) realm).stop();
    }
    Cluster cluster = getClusterInternal();
    if (cluster instanceof Lifecycle) {
        ((Lifecycle) cluster).stop();
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Cluster(org.apache.catalina.Cluster) LifecycleException(org.apache.catalina.LifecycleException) Container(org.apache.catalina.Container) Future(java.util.concurrent.Future) Realm(org.apache.catalina.Realm)

Example 7 with Cluster

use of org.apache.catalina.Cluster in project tomcat by apache.

the class ContainerBase method startInternal.

/**
     * Start this component and implement the requirements
     * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents this component from being used
     */
@Override
protected synchronized void startInternal() throws LifecycleException {
    // Start our subordinate components, if any
    logger = null;
    getLogger();
    Cluster cluster = getClusterInternal();
    if (cluster instanceof Lifecycle) {
        ((Lifecycle) cluster).start();
    }
    Realm realm = getRealmInternal();
    if (realm instanceof Lifecycle) {
        ((Lifecycle) realm).start();
    }
    // Start our child containers, if any
    Container[] children = findChildren();
    List<Future<Void>> results = new ArrayList<>();
    for (int i = 0; i < children.length; i++) {
        results.add(startStopExecutor.submit(new StartChild(children[i])));
    }
    boolean fail = false;
    for (Future<Void> result : results) {
        try {
            result.get();
        } catch (Exception e) {
            log.error(sm.getString("containerBase.threadedStartFailed"), e);
            fail = true;
        }
    }
    if (fail) {
        throw new LifecycleException(sm.getString("containerBase.threadedStartFailed"));
    }
    // Start the Valves in our pipeline (including the basic), if any
    if (pipeline instanceof Lifecycle)
        ((Lifecycle) pipeline).start();
    setState(LifecycleState.STARTING);
    // Start our thread
    threadStart();
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Cluster(org.apache.catalina.Cluster) LifecycleException(org.apache.catalina.LifecycleException) Container(org.apache.catalina.Container) Future(java.util.concurrent.Future) Realm(org.apache.catalina.Realm)

Example 8 with Cluster

use of org.apache.catalina.Cluster in project tomcat by apache.

the class ContainerBase method setCluster.

/**
     * Set the Cluster with which this Container is associated.
     *
     * @param cluster The newly associated Cluster
     */
@Override
public void setCluster(Cluster cluster) {
    Cluster oldCluster = null;
    Lock writeLock = clusterLock.writeLock();
    writeLock.lock();
    try {
        // Change components if necessary
        oldCluster = this.cluster;
        if (oldCluster == cluster)
            return;
        this.cluster = cluster;
        // Stop the old component if necessary
        if (getState().isAvailable() && (oldCluster != null) && (oldCluster instanceof Lifecycle)) {
            try {
                ((Lifecycle) oldCluster).stop();
            } catch (LifecycleException e) {
                log.error("ContainerBase.setCluster: stop: ", e);
            }
        }
        // Start the new component if necessary
        if (cluster != null)
            cluster.setContainer(this);
        if (getState().isAvailable() && (cluster != null) && (cluster instanceof Lifecycle)) {
            try {
                ((Lifecycle) cluster).start();
            } catch (LifecycleException e) {
                log.error("ContainerBase.setCluster: start: ", e);
            }
        }
    } finally {
        writeLock.unlock();
    }
    // Report this property change to interested listeners
    support.firePropertyChange("cluster", oldCluster, cluster);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Cluster(org.apache.catalina.Cluster) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

Cluster (org.apache.catalina.Cluster)8 Container (org.apache.catalina.Container)6 Lifecycle (org.apache.catalina.Lifecycle)6 Realm (org.apache.catalina.Realm)6 ArrayList (java.util.ArrayList)4 LifecycleException (org.apache.catalina.LifecycleException)4 Valve (org.apache.catalina.Valve)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Future (java.util.concurrent.Future)2 LifecycleListener (org.apache.catalina.LifecycleListener)2 ClusterValve (org.apache.catalina.ha.ClusterValve)2 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 StandardEngine (org.apache.catalina.core.StandardEngine)1 StandardHost (org.apache.catalina.core.StandardHost)1 CatalinaCluster (org.apache.catalina.ha.CatalinaCluster)1 SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)1 TomEEClusterListener (org.apache.tomee.catalina.cluster.TomEEClusterListener)1