Search in sources :

Example 1 with Cluster

use of org.apache.catalina.Cluster 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 2 with Cluster

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

the class ContainerBase method backgroundProcess.

/**
     * Execute a periodic task, such as reloading, etc. This method will be
     * invoked inside the classloading context of this container. Unexpected
     * throwables will be caught and logged.
     */
@Override
public void backgroundProcess() {
    if (!getState().isAvailable())
        return;
    Cluster cluster = getClusterInternal();
    if (cluster != null) {
        try {
            cluster.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.cluster", cluster), e);
        }
    }
    Realm realm = getRealmInternal();
    if (realm != null) {
        try {
            realm.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.realm", realm), e);
        }
    }
    Valve current = pipeline.getFirst();
    while (current != null) {
        try {
            current.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("containerBase.backgroundProcess.valve", current), e);
        }
        current = current.getNext();
    }
    fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null);
}
Also used : Cluster(org.apache.catalina.Cluster) Valve(org.apache.catalina.Valve) Realm(org.apache.catalina.Realm) LifecycleException(org.apache.catalina.LifecycleException)

Example 3 with Cluster

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

the class ContainerBase method destroyInternal.

@Override
protected void destroyInternal() throws LifecycleException {
    Realm realm = getRealmInternal();
    if (realm instanceof Lifecycle) {
        ((Lifecycle) realm).destroy();
    }
    Cluster cluster = getClusterInternal();
    if (cluster instanceof Lifecycle) {
        ((Lifecycle) cluster).destroy();
    }
    // Stop the Valves in our pipeline (including the basic), if any
    if (pipeline instanceof Lifecycle) {
        ((Lifecycle) pipeline).destroy();
    }
    // Remove children now this container is being destroyed
    for (Container child : findChildren()) {
        removeChild(child);
    }
    // Required if the child is destroyed directly.
    if (parent != null) {
        parent.removeChild(this);
    }
    // If init fails, this may be null
    if (startStopExecutor != null) {
        startStopExecutor.shutdownNow();
    }
    super.destroyInternal();
}
Also used : Container(org.apache.catalina.Container) Lifecycle(org.apache.catalina.Lifecycle) Cluster(org.apache.catalina.Cluster) Realm(org.apache.catalina.Realm)

Example 4 with Cluster

use of org.apache.catalina.Cluster in project tomee by apache.

the class TomcatWebAppBuilder method manageCluster.

private void manageCluster(final Cluster cluster) {
    if (cluster == null || cluster instanceof SimpleTomEETcpCluster) {
        return;
    }
    Cluster current = cluster;
    if (cluster instanceof SimpleTcpCluster) {
        final Container container = cluster.getContainer();
        current = new SimpleTomEETcpCluster((SimpleTcpCluster) cluster);
        container.setCluster(current);
    }
    if (current instanceof CatalinaCluster) {
        final CatalinaCluster haCluster = (CatalinaCluster) current;
        TomEEClusterListener listener = SystemInstance.get().getComponent(TomEEClusterListener.class);
        if (listener == null) {
            listener = new TomEEClusterListener();
            SystemInstance.get().setComponent(TomEEClusterListener.class, listener);
        }
        // better to be a singleton
        haCluster.addClusterListener(listener);
        clusters.add(haCluster);
    }
}
Also used : Container(org.apache.catalina.Container) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) TomEEClusterListener(org.apache.tomee.catalina.cluster.TomEEClusterListener) Cluster(org.apache.catalina.Cluster) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster)

Example 5 with Cluster

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

the class StandardEngineSF method storeChildren.

/**
     * Store the specified Engine properties.
     *
     * @param aWriter
     *            PrintWriter to which we are storing
     * @param indent
     *            Number of spaces to indent this element
     * @param aEngine
     *            Object whose properties are being stored
     *
     * @exception Exception
     *                if an exception occurs while storing
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aEngine, StoreDescription parentDesc) throws Exception {
    if (aEngine instanceof StandardEngine) {
        StandardEngine engine = (StandardEngine) aEngine;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = ((Lifecycle) engine).findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        // Store nested <Realm> element
        Realm realm = engine.getRealm();
        Realm parentRealm = null;
        // TODO is this case possible? (see it a old Server 5.0 impl)
        if (engine.getParent() != null) {
            parentRealm = engine.getParent().getRealm();
        }
        if (realm != parentRealm) {
            storeElement(aWriter, indent, realm);
        }
        // Store nested <Valve> elements
        Valve[] valves = engine.getPipeline().getValves();
        if (valves != null && valves.length > 0) {
            List<Valve> engineValves = new ArrayList<>();
            for (int i = 0; i < valves.length; i++) {
                if (!(valves[i] instanceof ClusterValve))
                    engineValves.add(valves[i]);
            }
            storeElementArray(aWriter, indent, engineValves.toArray());
        }
        // store all <Cluster> elements
        Cluster cluster = engine.getCluster();
        if (cluster != null) {
            storeElement(aWriter, indent, cluster);
        }
        // store all <Host> elements
        Container[] children = engine.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) StandardEngine(org.apache.catalina.core.StandardEngine) ClusterValve(org.apache.catalina.ha.ClusterValve) Valve(org.apache.catalina.Valve) Realm(org.apache.catalina.Realm)

Aggregations

Cluster (org.apache.catalina.Cluster)8 Container (org.apache.catalina.Container)6 Lifecycle (org.apache.catalina.Lifecycle)6 Realm (org.apache.catalina.Realm)6 ArrayList (java.util.ArrayList)4 LifecycleException (org.apache.catalina.LifecycleException)4 Valve (org.apache.catalina.Valve)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Future (java.util.concurrent.Future)2 LifecycleListener (org.apache.catalina.LifecycleListener)2 ClusterValve (org.apache.catalina.ha.ClusterValve)2 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 StandardEngine (org.apache.catalina.core.StandardEngine)1 StandardHost (org.apache.catalina.core.StandardHost)1 CatalinaCluster (org.apache.catalina.ha.CatalinaCluster)1 SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)1 TomEEClusterListener (org.apache.tomee.catalina.cluster.TomEEClusterListener)1