Search in sources :

Example 1 with Loader

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

the class StandardContextSF method storeChildren.

/**
     * Store the specified context element children.
     *
     * @param aWriter Current output writer
     * @param indent Indentation level
     * @param aContext Context to store
     * @param parentDesc The element description
     * @throws Exception Configuration storing error
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aContext, StoreDescription parentDesc) throws Exception {
    if (aContext instanceof StandardContext) {
        StandardContext context = (StandardContext) aContext;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = context.findLifecycleListeners();
        ArrayList<LifecycleListener> listenersArray = new ArrayList<>();
        for (LifecycleListener listener : listeners) {
            if (!(listener instanceof ThreadLocalLeakPreventionListener)) {
                listenersArray.add(listener);
            }
        }
        storeElementArray(aWriter, indent, listenersArray.toArray());
        // Store nested <Valve> elements
        Valve[] valves = context.getPipeline().getValves();
        storeElementArray(aWriter, indent, valves);
        // Store nested <Loader> elements
        Loader loader = context.getLoader();
        storeElement(aWriter, indent, loader);
        // Store nested <Manager> elements
        if (context.getCluster() == null || !context.getDistributable()) {
            Manager manager = context.getManager();
            storeElement(aWriter, indent, manager);
        }
        // Store nested <Realm> element
        Realm realm = context.getRealm();
        if (realm != null) {
            Realm parentRealm = null;
            // @TODO is this case possible?
            if (context.getParent() != null) {
                parentRealm = context.getParent().getRealm();
            }
            if (realm != parentRealm) {
                storeElement(aWriter, indent, realm);
            }
        }
        // Store nested resources
        WebResourceRoot resources = context.getResources();
        storeElement(aWriter, indent, resources);
        // Store nested <WrapperListener> elements
        String[] wLifecycles = context.findWrapperLifecycles();
        getStoreAppender().printTagArray(aWriter, "WrapperListener", indent + 2, wLifecycles);
        // Store nested <WrapperLifecycle> elements
        String[] wListeners = context.findWrapperListeners();
        getStoreAppender().printTagArray(aWriter, "WrapperLifecycle", indent + 2, wListeners);
        // Store nested <Parameter> elements
        ApplicationParameter[] appParams = context.findApplicationParameters();
        storeElementArray(aWriter, indent, appParams);
        // Store nested naming resources elements (EJB,Resource,...)
        NamingResourcesImpl nresources = context.getNamingResources();
        storeElement(aWriter, indent, nresources);
        // Store nested watched resources <WatchedResource>
        String[] wresources = context.findWatchedResources();
        wresources = filterWatchedResources(context, wresources);
        getStoreAppender().printTagArray(aWriter, "WatchedResource", indent + 2, wresources);
        // Store nested <JarScanner> elements
        JarScanner jarScanner = context.getJarScanner();
        storeElement(aWriter, indent, jarScanner);
        // Store nested <CookieProcessor> elements
        CookieProcessor cookieProcessor = context.getCookieProcessor();
        storeElement(aWriter, indent, cookieProcessor);
    }
}
Also used : ApplicationParameter(org.apache.tomcat.util.descriptor.web.ApplicationParameter) ArrayList(java.util.ArrayList) Loader(org.apache.catalina.Loader) LifecycleListener(org.apache.catalina.LifecycleListener) Manager(org.apache.catalina.Manager) JarScanner(org.apache.tomcat.JarScanner) ThreadLocalLeakPreventionListener(org.apache.catalina.core.ThreadLocalLeakPreventionListener) CookieProcessor(org.apache.tomcat.util.http.CookieProcessor) StandardContext(org.apache.catalina.core.StandardContext) Valve(org.apache.catalina.Valve) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) Realm(org.apache.catalina.Realm) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 2 with Loader

use of org.apache.catalina.Loader in project tomcat 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();
        // Stop ContainerBackgroundProcessor thread
        threadStop();
        for (int i = 0; i < children.length; i++) {
            children[i].stop();
        }
        // Stop our filters
        filterStop();
        Manager manager = getManager();
        if (manager instanceof Lifecycle && ((Lifecycle) manager).getState().isAvailable()) {
            ((Lifecycle) manager).stop();
        }
        // Stop our application listeners
        listenerStop();
        // 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();
        Realm realm = getRealmInternal();
        if (realm instanceof Lifecycle) {
            ((Lifecycle) realm).stop();
        }
        Loader loader = getLoader();
        if (loader instanceof Lifecycle) {
            ClassLoader classLoader = loader.getClassLoader();
            ((Lifecycle) loader).stop();
            if (classLoader != null) {
                InstanceManagerBindings.unbind(classLoader);
            }
        }
        // Stop resources
        resourcesStop();
    } 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) 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.tomcat.util.descriptor.web.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)

Example 3 with Loader

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

the class StandardContext method setLoader.

@Override
public void setLoader(Loader loader) {
    Lock writeLock = loaderLock.writeLock();
    writeLock.lock();
    Loader oldLoader = null;
    try {
        // Change components if necessary
        oldLoader = this.loader;
        if (oldLoader == loader)
            return;
        this.loader = loader;
        // Stop the old component if necessary
        if (getState().isAvailable() && (oldLoader != null) && (oldLoader instanceof Lifecycle)) {
            try {
                ((Lifecycle) oldLoader).stop();
            } catch (LifecycleException e) {
                log.error("StandardContext.setLoader: stop: ", e);
            }
        }
        // Start the new component if necessary
        if (loader != null)
            loader.setContext(this);
        if (getState().isAvailable() && (loader != null) && (loader instanceof Lifecycle)) {
            try {
                ((Lifecycle) loader).start();
            } catch (LifecycleException e) {
                log.error("StandardContext.setLoader: start: ", e);
            }
        }
    } finally {
        writeLock.unlock();
    }
    // Report this property change to interested listeners
    support.firePropertyChange("loader", oldLoader, loader);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 4 with Loader

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

the class StandardContext method destroyInternal.

/** Destroy needs to clean up the context completely.
     *
     * The problem is that undoing all the config in start() and restoring
     * a 'fresh' state is impossible. After stop()/destroy()/init()/start()
     * we should have the same state as if a fresh start was done - i.e
     * read modified web.xml, etc. This can only be done by completely
     * removing the context object and remapping a new one, or by cleaning
     * up everything.
     *
     * XXX Should this be done in stop() ?
     *
     */
@Override
protected void destroyInternal() throws LifecycleException {
    // have been set so the notification can't be created
    if (getObjectName() != null) {
        // Send j2ee.object.deleted notification
        Notification notification = new Notification("j2ee.object.deleted", this.getObjectName(), sequenceNumber.getAndIncrement());
        broadcaster.sendNotification(notification);
    }
    if (namingResources != null) {
        namingResources.destroy();
    }
    Loader loader = getLoader();
    if (loader instanceof Lifecycle) {
        ((Lifecycle) loader).destroy();
    }
    Manager manager = getManager();
    if (manager instanceof Lifecycle) {
        ((Lifecycle) manager).destroy();
    }
    if (resources != null) {
        resources.destroy();
    }
    super.destroyInternal();
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) 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) Notification(javax.management.Notification)

Example 5 with Loader

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

the class StandardContext method backgroundProcess.

@Override
public void backgroundProcess() {
    if (!getState().isAvailable())
        return;
    Loader loader = getLoader();
    if (loader != null) {
        try {
            loader.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.loader", loader), e);
        }
    }
    Manager manager = getManager();
    if (manager != null) {
        try {
            manager.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.manager", manager), e);
        }
    }
    WebResourceRoot resources = getResources();
    if (resources != null) {
        try {
            resources.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.resources", resources), e);
        }
    }
    InstanceManager instanceManager = getInstanceManager();
    if (instanceManager != null) {
        try {
            instanceManager.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.instanceManager", resources), e);
        }
    }
    super.backgroundProcess();
}
Also used : InstanceManager(org.apache.tomcat.InstanceManager) 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) 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) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Aggregations

Loader (org.apache.catalina.Loader)16 WebappLoader (org.apache.catalina.loader.WebappLoader)11 IOException (java.io.IOException)5 LifecycleException (org.apache.catalina.LifecycleException)5 Manager (org.apache.catalina.Manager)5 Lifecycle (org.apache.catalina.Lifecycle)4 WebResourceRoot (org.apache.catalina.WebResourceRoot)4 StandardManager (org.apache.catalina.session.StandardManager)4 DeploymentLoader (org.apache.openejb.config.DeploymentLoader)4 InstanceManager (org.apache.tomcat.InstanceManager)4 File (java.io.File)3 MalformedURLException (java.net.MalformedURLException)3 ListenerNotFoundException (javax.management.ListenerNotFoundException)3 Notification (javax.management.Notification)3 NamingException (javax.naming.NamingException)3 ServletException (javax.servlet.ServletException)3 Realm (org.apache.catalina.Realm)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2