Search in sources :

Example 81 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat70 by apache.

the class LifecycleBase method stop.

/**
 * {@inheritDoc}
 */
@Override
public final synchronized void stop() throws LifecycleException {
    if (LifecycleState.STOPPING_PREP.equals(state) || LifecycleState.STOPPING.equals(state) || LifecycleState.STOPPED.equals(state)) {
        if (log.isDebugEnabled()) {
            Exception e = new LifecycleException();
            log.debug(sm.getString("lifecycleBase.alreadyStopped", toString()), e);
        } else if (log.isInfoEnabled()) {
            log.info(sm.getString("lifecycleBase.alreadyStopped", toString()));
        }
        return;
    }
    if (state.equals(LifecycleState.NEW)) {
        state = LifecycleState.STOPPED;
        return;
    }
    if (!state.equals(LifecycleState.STARTED) && !state.equals(LifecycleState.FAILED)) {
        invalidTransition(Lifecycle.BEFORE_STOP_EVENT);
    }
    try {
        if (state.equals(LifecycleState.FAILED)) {
            // Don't transition to STOPPING_PREP as that would briefly mark the
            // component as available but do ensure the BEFORE_STOP_EVENT is
            // fired
            fireLifecycleEvent(BEFORE_STOP_EVENT, null);
        } else {
            setStateInternal(LifecycleState.STOPPING_PREP, null, false);
        }
        stopInternal();
        // doing what they are supposed to.
        if (!state.equals(LifecycleState.STOPPING) && !state.equals(LifecycleState.FAILED)) {
            invalidTransition(Lifecycle.AFTER_STOP_EVENT);
        }
        setStateInternal(LifecycleState.STOPPED, null, false);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        setStateInternal(LifecycleState.FAILED, null, false);
        throw new LifecycleException(sm.getString("lifecycleBase.stopFail", toString()), t);
    } finally {
        if (this instanceof Lifecycle.SingleUse) {
            // Complete stop process first
            setStateInternal(LifecycleState.STOPPED, null, false);
            destroy();
        }
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) LifecycleException(org.apache.catalina.LifecycleException)

Example 82 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat70 by apache.

the class LifecycleBase method destroy.

@Override
public final synchronized void destroy() throws LifecycleException {
    if (LifecycleState.FAILED.equals(state)) {
        try {
            // Triggers clean-up
            stop();
        } catch (LifecycleException e) {
            // Just log. Still want to destroy.
            log.warn(sm.getString("lifecycleBase.destroyStopFail", toString()), e);
        }
    }
    if (LifecycleState.DESTROYING.equals(state) || LifecycleState.DESTROYED.equals(state)) {
        if (log.isDebugEnabled()) {
            Exception e = new LifecycleException();
            log.debug(sm.getString("lifecycleBase.alreadyDestroyed", toString()), e);
        } else if (log.isInfoEnabled() && !(this instanceof Lifecycle.SingleUse)) {
            // Rather than have every component that might need to call
            // destroy() check for SingleUse, don't log an info message if
            // multiple calls are made to destroy()
            log.info(sm.getString("lifecycleBase.alreadyDestroyed", toString()));
        }
        return;
    }
    if (!state.equals(LifecycleState.STOPPED) && !state.equals(LifecycleState.FAILED) && !state.equals(LifecycleState.NEW) && !state.equals(LifecycleState.INITIALIZED)) {
        invalidTransition(Lifecycle.BEFORE_DESTROY_EVENT);
    }
    try {
        setStateInternal(LifecycleState.DESTROYING, null, false);
        destroyInternal();
        setStateInternal(LifecycleState.DESTROYED, null, false);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        setStateInternal(LifecycleState.FAILED, null, false);
        throw new LifecycleException(sm.getString("lifecycleBase.destroyFail", toString()), t);
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) LifecycleException(org.apache.catalina.LifecycleException)

Example 83 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat70 by apache.

the class LifecycleBase method start.

/**
 * {@inheritDoc}
 */
@Override
public final synchronized void start() throws LifecycleException {
    if (LifecycleState.STARTING_PREP.equals(state) || LifecycleState.STARTING.equals(state) || LifecycleState.STARTED.equals(state)) {
        if (log.isDebugEnabled()) {
            Exception e = new LifecycleException();
            log.debug(sm.getString("lifecycleBase.alreadyStarted", toString()), e);
        } else if (log.isInfoEnabled()) {
            log.info(sm.getString("lifecycleBase.alreadyStarted", toString()));
        }
        return;
    }
    if (state.equals(LifecycleState.NEW)) {
        init();
    } else if (state.equals(LifecycleState.FAILED)) {
        stop();
    } else if (!state.equals(LifecycleState.INITIALIZED) && !state.equals(LifecycleState.STOPPED)) {
        invalidTransition(Lifecycle.BEFORE_START_EVENT);
    }
    try {
        setStateInternal(LifecycleState.STARTING_PREP, null, false);
        startInternal();
        if (state.equals(LifecycleState.FAILED)) {
            // This is a 'controlled' failure. The component put itself into the
            // FAILED state so call stop() to complete the clean-up.
            stop();
        } else if (!state.equals(LifecycleState.STARTING)) {
            // Shouldn't be necessary but acts as a check that sub-classes are
            // doing what they are supposed to.
            invalidTransition(Lifecycle.AFTER_START_EVENT);
        } else {
            setStateInternal(LifecycleState.STARTED, null, false);
        }
    } catch (Throwable t) {
        // This is an 'uncontrolled' failure so put the component into the
        // FAILED state and throw an exception.
        ExceptionUtils.handleThrowable(t);
        setStateInternal(LifecycleState.FAILED, null, false);
        throw new LifecycleException(sm.getString("lifecycleBase.startFail", toString()), t);
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) LifecycleException(org.apache.catalina.LifecycleException)

Example 84 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat70 by apache.

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) {
    Lock writeLock = managerLock.writeLock();
    writeLock.lock();
    Manager oldManager = null;
    try {
        // Change components if necessary
        oldManager = this.manager;
        if (oldManager == manager)
            return;
        this.manager = manager;
        // Stop the old component if necessary
        if (oldManager instanceof Lifecycle) {
            try {
                ((Lifecycle) oldManager).stop();
                ((Lifecycle) oldManager).destroy();
            } catch (LifecycleException e) {
                log.error("ContainerBase.setManager: stop-destroy: ", e);
            }
        }
        // Start the new component if necessary
        if (manager != null)
            manager.setContainer(this);
        if (getState().isAvailable() && manager instanceof Lifecycle) {
            try {
                ((Lifecycle) manager).start();
            } catch (LifecycleException e) {
                log.error("ContainerBase.setManager: start: ", e);
            }
        }
    } finally {
        writeLock.unlock();
    }
    // Report this property change to interested listeners
    support.firePropertyChange("manager", oldManager, manager);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) StringManager(org.apache.tomcat.util.res.StringManager) Manager(org.apache.catalina.Manager) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 85 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat70 by apache.

the class StandardContext 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 {
    // Send j2ee.state.stopping notification
    if (this.getObjectName() != null) {
        Notification notification = new Notification("j2ee.state.stopping", this.getObjectName(), sequenceNumber.getAndIncrement());
        broadcaster.sendNotification(notification);
    }
    setState(LifecycleState.STOPPING);
    // Binding thread
    ClassLoader oldCCL = bindThread();
    try {
        // Stop our child containers, if any
        final Container[] children = findChildren();
        ClassLoader old = bindThread();
        try {
            // Stop ContainerBackgroundProcessor thread
            threadStop();
            for (int i = 0; i < children.length; i++) {
                children[i].stop();
            }
            // Stop our filters
            filterStop();
            Manager manager = getManagerInternal();
            if (manager != null && manager instanceof Lifecycle && ((Lifecycle) manager).getState().isAvailable()) {
                ((Lifecycle) manager).stop();
            }
            // Stop our application listeners
            listenerStop();
        } finally {
            unbindThread(old);
        }
        // Finalize our character set mapper
        setCharsetMapper(null);
        // Normal container shutdown processing
        if (log.isDebugEnabled())
            log.debug("Processing standard container shutdown");
        // after the application has finished with the resource
        if (namingResources != null) {
            namingResources.stop();
        }
        fireLifecycleEvent(Lifecycle.CONFIGURE_STOP_EVENT, null);
        // Stop the Valves in our pipeline (including the basic), if any
        if (pipeline instanceof Lifecycle && ((Lifecycle) pipeline).getState().isAvailable()) {
            ((Lifecycle) pipeline).stop();
        }
        // Clear all application-originated servlet context attributes
        if (context != null)
            context.clearAttributes();
        // Stop resources
        resourcesStop();
        Realm realm = getRealmInternal();
        if ((realm != null) && (realm instanceof Lifecycle)) {
            ((Lifecycle) realm).stop();
        }
        Cluster cluster = getClusterInternal();
        if ((cluster != null) && (cluster instanceof Lifecycle)) {
            ((Lifecycle) cluster).stop();
        }
        Loader loader = getLoaderInternal();
        if ((loader != null) && (loader instanceof Lifecycle)) {
            ((Lifecycle) loader).stop();
        }
    } finally {
        // Unbinding thread
        unbindThread(oldCCL);
    }
    // Send j2ee.state.stopped notification
    if (this.getObjectName() != null) {
        Notification notification = new Notification("j2ee.state.stopped", this.getObjectName(), sequenceNumber.getAndIncrement());
        broadcaster.sendNotification(notification);
    }
    // Reset application context
    context = null;
    // This object will no longer be visible or used.
    try {
        resetContext();
    } catch (Exception ex) {
        log.error("Error resetting context " + this + " " + ex, ex);
    }
    // reset the instance manager
    setInstanceManager(null);
    if (log.isDebugEnabled())
        log.debug("Stopping complete");
}
Also used : Container(org.apache.catalina.Container) Lifecycle(org.apache.catalina.Lifecycle) Cluster(org.apache.catalina.Cluster) WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) Manager(org.apache.catalina.Manager) InstanceManager(org.apache.tomcat.InstanceManager) StandardManager(org.apache.catalina.session.StandardManager) Realm(org.apache.catalina.Realm) Notification(javax.management.Notification) SecurityConstraint(org.apache.catalina.deploy.SecurityConstraint) LifecycleException(org.apache.catalina.LifecycleException) ListenerNotFoundException(javax.management.ListenerNotFoundException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) MalformedURLException(java.net.MalformedURLException)

Aggregations

LifecycleException (org.apache.catalina.LifecycleException)128 Lifecycle (org.apache.catalina.Lifecycle)36 IOException (java.io.IOException)29 Container (org.apache.catalina.Container)19 NamingException (javax.naming.NamingException)18 File (java.io.File)17 Realm (org.apache.catalina.Realm)16 MalformedURLException (java.net.MalformedURLException)15 ServletException (javax.servlet.ServletException)12 ArrayList (java.util.ArrayList)9 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)9 Manager (org.apache.catalina.Manager)9 Valve (org.apache.catalina.Valve)9 Tomcat (org.apache.catalina.startup.Tomcat)9 Lock (java.util.concurrent.locks.Lock)8 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)8 Cluster (org.apache.catalina.Cluster)8 Loader (org.apache.catalina.Loader)8 Server (org.apache.catalina.Server)8 Contained (org.apache.catalina.Contained)7