Search in sources :

Example 6 with LifecycleListener

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

the class StandardHostSF method storeChildren.

/**
     * Store the specified Host properties and children
     * (Listener,Alias,Realm,Valve,Cluster, Context)
     *
     * @param aWriter
     *            PrintWriter to which we are storing
     * @param indent
     *            Number of spaces to indent this element
     * @param aHost
     *            Host whose properties are being stored
     *
     * @exception Exception
     *                if an exception occurs while storing
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aHost, StoreDescription parentDesc) throws Exception {
    if (aHost instanceof StandardHost) {
        StandardHost host = (StandardHost) aHost;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = ((Lifecycle) host).findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        // Store nested <Alias> elements
        String[] aliases = host.findAliases();
        getStoreAppender().printTagArray(aWriter, "Alias", indent + 2, aliases);
        // Store nested <Realm> element
        Realm realm = host.getRealm();
        if (realm != null) {
            Realm parentRealm = null;
            if (host.getParent() != null) {
                parentRealm = host.getParent().getRealm();
            }
            if (realm != parentRealm) {
                storeElement(aWriter, indent, realm);
            }
        }
        // Store nested <Valve> elements
        Valve[] valves = host.getPipeline().getValves();
        if (valves != null && valves.length > 0) {
            List<Valve> hostValves = new ArrayList<>();
            for (int i = 0; i < valves.length; i++) {
                if (!(valves[i] instanceof ClusterValve))
                    hostValves.add(valves[i]);
            }
            storeElementArray(aWriter, indent, hostValves.toArray());
        }
        // store all <Cluster> elements
        Cluster cluster = host.getCluster();
        if (cluster != null) {
            Cluster parentCluster = null;
            if (host.getParent() != null) {
                parentCluster = host.getParent().getCluster();
            }
            if (cluster != parentCluster) {
                storeElement(aWriter, indent, cluster);
            }
        }
        // store all <Context> elements
        Container[] children = host.findChildren();
        storeElementArray(aWriter, indent, children);
    }
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) ArrayList(java.util.ArrayList) Cluster(org.apache.catalina.Cluster) LifecycleListener(org.apache.catalina.LifecycleListener) ClusterValve(org.apache.catalina.ha.ClusterValve) Container(org.apache.catalina.Container) StandardHost(org.apache.catalina.core.StandardHost) ClusterValve(org.apache.catalina.ha.ClusterValve) Valve(org.apache.catalina.Valve) Realm(org.apache.catalina.Realm)

Example 7 with LifecycleListener

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

the class StandardServerSF method storeChildren.

/**
     * Store the specified server element children.
     *
     * @param aWriter Current output writer
     * @param indent Indentation level
     * @param aObject Server to store
     * @param parentDesc The element description
     * @throws Exception Configuration storing error
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aObject, StoreDescription parentDesc) throws Exception {
    if (aObject instanceof StandardServer) {
        StandardServer server = (StandardServer) aObject;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = ((Lifecycle) server).findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        /*LifecycleListener listener = null;
            for (int i = 0; listener == null && i < listeners.length; i++)
                if (listeners[i] instanceof ServerLifecycleListener)
                    listener = listeners[i];
            if (listener != null) {
                StoreDescription elementDesc = getRegistry()
                        .findDescription(
                                StandardServer.class.getName()
                                        + ".[ServerLifecycleListener]");
                if (elementDesc != null) {
                    elementDesc.getStoreFactory().store(aWriter, indent,
                            listener);
                }
            }*/
        // Store nested <GlobalNamingResources> element
        NamingResourcesImpl globalNamingResources = server.getGlobalNamingResources();
        StoreDescription elementDesc = getRegistry().findDescription(NamingResourcesImpl.class.getName() + ".[GlobalNamingResources]");
        if (elementDesc != null) {
            elementDesc.getStoreFactory().store(aWriter, indent, globalNamingResources);
        }
        // Store nested <Service> elements
        Service[] services = server.findServices();
        storeElementArray(aWriter, indent, services);
    }
}
Also used : StandardServer(org.apache.catalina.core.StandardServer) Lifecycle(org.apache.catalina.Lifecycle) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) Service(org.apache.catalina.Service) LifecycleListener(org.apache.catalina.LifecycleListener)

Example 8 with LifecycleListener

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

the class StandardServiceSF method storeChildren.

/**
     * Store the specified service element children.
     *
     * @param aWriter Current output writer
     * @param indent Indentation level
     * @param aService Service to store
     * @param parentDesc The element description
     * @throws Exception Configuration storing error
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aService, StoreDescription parentDesc) throws Exception {
    if (aService instanceof StandardService) {
        StandardService service = (StandardService) aService;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = ((Lifecycle) service).findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        // Store nested <Executor> elements
        Executor[] executors = service.findExecutors();
        storeElementArray(aWriter, indent, executors);
        Connector[] connectors = service.findConnectors();
        storeElementArray(aWriter, indent, connectors);
        // Store nested <Engine> element
        Engine container = service.getContainer();
        if (container != null) {
            StoreDescription elementDesc = getRegistry().findDescription(container.getClass());
            if (elementDesc != null) {
                IStoreFactory factory = elementDesc.getStoreFactory();
                factory.store(aWriter, indent, container);
            }
        }
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) Executor(org.apache.catalina.Executor) Lifecycle(org.apache.catalina.Lifecycle) StandardService(org.apache.catalina.core.StandardService) LifecycleListener(org.apache.catalina.LifecycleListener) Engine(org.apache.catalina.Engine)

Example 9 with LifecycleListener

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

the class ContainerMBean method removeLifecycleListeners.

/**
     * Remove a LifecycleEvent listeners from this component.
     *
     * @param type The ClassName of the listeners to be removed.
     * Note that all the listeners having given ClassName will be removed.
     * @throws MBeanException propagated from the managed resource access
     */
public void removeLifecycleListeners(String type) throws MBeanException {
    Container container = doGetManagedResource();
    LifecycleListener[] listeners = container.findLifecycleListeners();
    for (LifecycleListener listener : listeners) {
        if (listener.getClass().getName().equals(type)) {
            container.removeLifecycleListener(listener);
        }
    }
}
Also used : Container(org.apache.catalina.Container) LifecycleListener(org.apache.catalina.LifecycleListener)

Example 10 with LifecycleListener

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

the class ContainerMBean method addLifecycleListener.

/**
     * Add a LifecycleEvent listener to this component.
     *
     * @param type ClassName of the listener to add
     * @throws MBeanException if adding the listener failed
    */
public void addLifecycleListener(String type) throws MBeanException {
    LifecycleListener listener = (LifecycleListener) newInstance(type);
    Container container = doGetManagedResource();
    container.addLifecycleListener(listener);
}
Also used : Container(org.apache.catalina.Container) LifecycleListener(org.apache.catalina.LifecycleListener)

Aggregations

LifecycleListener (org.apache.catalina.LifecycleListener)22 Container (org.apache.catalina.Container)6 Valve (org.apache.catalina.Valve)6 File (java.io.File)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Lifecycle (org.apache.catalina.Lifecycle)5 JarFile (java.util.jar.JarFile)4 Context (org.apache.catalina.Context)4 StandardContext (org.apache.catalina.core.StandardContext)4 Realm (org.apache.catalina.Realm)3 ClusterValve (org.apache.catalina.ha.ClusterValve)3 FileInputStream (java.io.FileInputStream)2 Cluster (org.apache.catalina.Cluster)2 LifecycleException (org.apache.catalina.LifecycleException)2 Manager (org.apache.catalina.Manager)2 Connector (org.apache.catalina.connector.Connector)2 StandardHost (org.apache.catalina.core.StandardHost)2 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)2 BufferedOutputStream (java.io.BufferedOutputStream)1