Search in sources :

Example 21 with Lifecycle

use of org.apache.catalina.Lifecycle 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 22 with Lifecycle

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

the class ContainerBase method setRealm.

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

Example 23 with Lifecycle

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

Example 24 with Lifecycle

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

the class StandardPipeline method removeValve.

/**
     * Remove the specified Valve from the pipeline associated with this
     * Container, if it is found; otherwise, do nothing.  If the Valve is
     * found and removed, the Valve's <code>setContainer(null)</code> method
     * will be called if it implements <code>Contained</code>.
     *
     * @param valve Valve to be removed
     */
@Override
public void removeValve(Valve valve) {
    Valve current;
    if (first == valve) {
        first = first.getNext();
        current = null;
    } else {
        current = first;
    }
    while (current != null) {
        if (current.getNext() == valve) {
            current.setNext(valve.getNext());
            break;
        }
        current = current.getNext();
    }
    if (first == basic)
        first = null;
    if (valve instanceof Contained)
        ((Contained) valve).setContainer(null);
    if (valve instanceof Lifecycle) {
        // Stop this valve if necessary
        if (getState().isAvailable()) {
            try {
                ((Lifecycle) valve).stop();
            } catch (LifecycleException e) {
                log.error("StandardPipeline.removeValve: stop: ", e);
            }
        }
        try {
            ((Lifecycle) valve).destroy();
        } catch (LifecycleException e) {
            log.error("StandardPipeline.removeValve: destroy: ", e);
        }
    }
    container.fireContainerEvent(Container.REMOVE_VALVE_EVENT, valve);
}
Also used : Contained(org.apache.catalina.Contained) LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

Example 25 with Lifecycle

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

the class StandardPipeline method stopInternal.

/**
     * Stop {@link Valve}s) in this pipeline and implement the requirements
     * of {@link 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 {
    setState(LifecycleState.STOPPING);
    // Stop the Valves in our pipeline (including the basic), if any
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        if (current instanceof Lifecycle)
            ((Lifecycle) current).stop();
        current = current.getNext();
    }
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

Aggregations

Lifecycle (org.apache.catalina.Lifecycle)34 LifecycleException (org.apache.catalina.LifecycleException)21 Realm (org.apache.catalina.Realm)11 Container (org.apache.catalina.Container)9 Valve (org.apache.catalina.Valve)8 IOException (java.io.IOException)6 Cluster (org.apache.catalina.Cluster)6 LifecycleListener (org.apache.catalina.LifecycleListener)6 Notification (javax.management.Notification)5 ServletException (javax.servlet.ServletException)5 Loader (org.apache.catalina.Loader)5 Manager (org.apache.catalina.Manager)5 WebappLoader (org.apache.catalina.loader.WebappLoader)5 StandardManager (org.apache.catalina.session.StandardManager)5 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4 Lock (java.util.concurrent.locks.Lock)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)4 NamingException (javax.naming.NamingException)4