Search in sources :

Example 16 with Lifecycle

use of org.apache.catalina.Lifecycle in project Payara by payara.

the class ContainerBase method setManager.

/**
 * Set the Manager with which this Container is associated.
 *
 * @param manager The newly associated Manager
 */
@Override
public void setManager(Manager manager) {
    Manager oldManager;
    try {
        writeLock.lock();
        // Change components if necessary
        oldManager = this.manager;
        if (oldManager == manager)
            return;
        this.manager = manager;
        // Stop the old component if necessary
        if (started && (oldManager != null) && (oldManager instanceof Lifecycle)) {
            try {
                ((Lifecycle) oldManager).stop();
            } catch (LifecycleException e) {
                log.log(Level.SEVERE, LogFacade.CONTAINER_BASE_SET_MANAGER_STOP, e);
            }
        }
        // Start the new component if necessary
        if (manager != null)
            manager.setContainer(this);
        if (started && (manager != null) && (manager instanceof Lifecycle)) {
            try {
                ((Lifecycle) manager).start();
            } catch (LifecycleException e) {
                log.log(Level.SEVERE, LogFacade.CONTAINER_BASE_SET_MANAGER_START, e);
            }
        }
    } finally {
        writeLock.unlock();
    }
    // Report this property change to interested listeners
    support.firePropertyChange("manager", oldManager, this.manager);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Manager(org.apache.catalina.Manager)

Example 17 with Lifecycle

use of org.apache.catalina.Lifecycle in project Payara by payara.

the class ContainerBase method setLoader.

/**
 * Set the Loader with which this Container is associated.
 *
 * @param loader The newly associated loader
 */
@Override
public void setLoader(Loader loader) {
    Loader oldLoader;
    try {
        writeLock.lock();
        // Change components if necessary
        oldLoader = this.loader;
        if (oldLoader == loader)
            return;
        this.loader = loader;
        // Stop the old component if necessary
        if (started && (oldLoader != null) && (oldLoader instanceof Lifecycle)) {
            try {
                ((Lifecycle) oldLoader).stop();
            } catch (LifecycleException e) {
                log.log(Level.SEVERE, LogFacade.CONTAINER_BASE_SET_LOADER_STOP, e);
            }
        }
        // Start the new component if necessary
        if (loader != null)
            loader.setContainer(this);
        if (started && (loader != null) && (loader instanceof Lifecycle)) {
            try {
                ((Lifecycle) loader).start();
            } catch (LifecycleException e) {
                log.log(Level.SEVERE, LogFacade.CONTAINER_BASE_SET_LOADER_START, e);
            }
        }
    } finally {
        writeLock.unlock();
    }
    // Report this property change to interested listeners
    support.firePropertyChange("loader", oldLoader, this.loader);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Loader(org.apache.catalina.Loader)

Example 18 with Lifecycle

use of org.apache.catalina.Lifecycle in project Payara by payara.

the class LifecycleListenerRule method begin.

// --------------------------------------------------------- Public Methods
/**
 * Handle the beginning of an XML element.
 *
 * @param attributes The attributes of this element
 *
 * @exception Exception if a processing error occurs
 */
public void begin(Attributes attributes) throws Exception {
    // Instantiate a new LifecyleListener implementation object
    String className = listenerClass;
    if (attributeName != null) {
        String value = attributes.getValue(attributeName);
        if (value != null)
            className = value;
    }
    Class clazz = Class.forName(className);
    LifecycleListener listener = (LifecycleListener) clazz.newInstance();
    // Add this LifecycleListener to our associated component
    Lifecycle lifecycle = (Lifecycle) digester.peek();
    lifecycle.addLifecycleListener(listener);
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) LifecycleListener(org.apache.catalina.LifecycleListener)

Example 19 with Lifecycle

use of org.apache.catalina.Lifecycle in project Payara by payara.

the class StandardContext method alternateResourcesStop.

/**
 * Stops this context's alternate doc base resources.
 */
public boolean alternateResourcesStop() {
    boolean ok = true;
    if (alternateDocBases == null || alternateDocBases.isEmpty()) {
        return ok;
    }
    for (AlternateDocBase alternateDocBase : alternateDocBases) {
        final DirContext alternateResources = ContextsAdapterUtility.unwrap(alternateDocBase.getResources());
        if (alternateResources instanceof Lifecycle) {
            try {
                ((Lifecycle) alternateResources).stop();
            } catch (Throwable t) {
                log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
                ok = false;
            }
        }
        final DirContext alternateWebappResources = ContextsAdapterUtility.unwrap(alternateDocBase.getWebappResources());
        if (alternateWebappResources instanceof BaseDirContext) {
            try {
                ((BaseDirContext) alternateWebappResources).release();
            } catch (Throwable t) {
                log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
                ok = false;
            }
        }
    }
    this.alternateDocBases = null;
    return (ok);
}
Also used : AlternateDocBase(org.glassfish.grizzly.http.server.util.AlternateDocBase) Lifecycle(org.apache.catalina.Lifecycle) BaseDirContext(org.apache.naming.resources.BaseDirContext) WARDirContext(org.apache.naming.resources.WARDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) WebDirContext(org.apache.naming.resources.WebDirContext) FileDirContext(org.apache.naming.resources.FileDirContext)

Example 20 with Lifecycle

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

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