Search in sources :

Example 51 with LifecycleException

use of org.apache.catalina.LifecycleException in project tomcat 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) {
        handleSubClassException(t, "lifecycleBase.stopFail", toString());
    } 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 52 with LifecycleException

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

the class StandardService method setContainer.

@Override
public void setContainer(Engine engine) {
    Engine oldEngine = this.engine;
    if (oldEngine != null) {
        oldEngine.setService(null);
    }
    this.engine = engine;
    if (this.engine != null) {
        this.engine.setService(this);
    }
    if (getState().isAvailable()) {
        if (this.engine != null) {
            try {
                this.engine.start();
            } catch (LifecycleException e) {
                log.warn(sm.getString("standardService.engine.startFailed"), e);
            }
        }
        // Restart MapperListener to pick up new engine.
        try {
            mapperListener.stop();
        } catch (LifecycleException e) {
            log.warn(sm.getString("standardService.mapperListener.stopFailed"), e);
        }
        try {
            mapperListener.start();
        } catch (LifecycleException e) {
            log.warn(sm.getString("standardService.mapperListener.startFailed"), e);
        }
        if (oldEngine != null) {
            try {
                oldEngine.stop();
            } catch (LifecycleException e) {
                log.warn(sm.getString("standardService.engine.stopFailed"), e);
            }
        }
    }
    // Report this property change to interested listeners
    support.firePropertyChange("container", oldEngine, this.engine);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Engine(org.apache.catalina.Engine)

Example 53 with LifecycleException

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

the class NamingResourcesImpl method initInternal.

// ------------------------------------------------------- Lifecycle methods
@Override
protected void initInternal() throws LifecycleException {
    super.initInternal();
    // Set this before we register currently known naming resources to avoid
    // timing issues. Duplication registration is not an issue.
    resourceRequireExplicitRegistration = true;
    for (ContextResource cr : resources.values()) {
        try {
            MBeanUtils.createMBean(cr);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail", cr.getName()), e);
        }
    }
    for (ContextEnvironment ce : envs.values()) {
        try {
            MBeanUtils.createMBean(ce);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail", ce.getName()), e);
        }
    }
    for (ContextResourceLink crl : resourceLinks.values()) {
        try {
            MBeanUtils.createMBean(crl);
        } catch (Exception e) {
            log.warn(sm.getString("namingResources.mbeanCreateFail", crl.getName()), e);
        }
    }
}
Also used : ContextEnvironment(org.apache.tomcat.util.descriptor.web.ContextEnvironment) ContextResourceLink(org.apache.tomcat.util.descriptor.web.ContextResourceLink) NamingException(javax.naming.NamingException) LifecycleException(org.apache.catalina.LifecycleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Example 54 with LifecycleException

use of org.apache.catalina.LifecycleException 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 55 with LifecycleException

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

the class StandardPipeline method addValve.

/**
     * <p>Add a new Valve to the end of the pipeline associated with this
     * Container.  Prior to adding the Valve, the Valve's
     * <code>setContainer()</code> method will be called, if it implements
     * <code>Contained</code>, with the owning Container as an argument.
     * The method may throw an
     * <code>IllegalArgumentException</code> if this Valve chooses not to
     * be associated with this Container, or <code>IllegalStateException</code>
     * if it is already associated with a different Container.</p>
     *
     * @param valve Valve to be added
     *
     * @exception IllegalArgumentException if this Container refused to
     *  accept the specified Valve
     * @exception IllegalArgumentException if the specified Valve refuses to be
     *  associated with this Container
     * @exception IllegalStateException if the specified Valve is already
     *  associated with a different Container
     */
@Override
public void addValve(Valve valve) {
    // Validate that we can add this Valve
    if (valve instanceof Contained)
        ((Contained) valve).setContainer(this.container);
    // Start the new component if necessary
    if (getState().isAvailable()) {
        if (valve instanceof Lifecycle) {
            try {
                ((Lifecycle) valve).start();
            } catch (LifecycleException e) {
                log.error("StandardPipeline.addValve: start: ", e);
            }
        }
    }
    // Add this Valve to the set associated with this Pipeline
    if (first == null) {
        first = valve;
        valve.setNext(basic);
    } else {
        Valve current = first;
        while (current != null) {
            if (current.getNext() == basic) {
                current.setNext(valve);
                valve.setNext(basic);
                break;
            }
            current = current.getNext();
        }
    }
    container.fireContainerEvent(Container.ADD_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)

Aggregations

LifecycleException (org.apache.catalina.LifecycleException)78 Lifecycle (org.apache.catalina.Lifecycle)23 IOException (java.io.IOException)18 NamingException (javax.naming.NamingException)12 MalformedURLException (java.net.MalformedURLException)11 Container (org.apache.catalina.Container)11 File (java.io.File)10 Realm (org.apache.catalina.Realm)10 ServletException (javax.servlet.ServletException)9 ArrayList (java.util.ArrayList)7 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)5 Context (org.apache.catalina.Context)5 Loader (org.apache.catalina.Loader)5 StandardManager (org.apache.catalina.session.StandardManager)5 BindException (java.net.BindException)4 Properties (java.util.Properties)4 Lock (java.util.concurrent.locks.Lock)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 Notification (javax.management.Notification)4