Search in sources :

Example 1 with SimpleTcpCluster

use of org.apache.catalina.ha.tcp.SimpleTcpCluster in project tomcat by apache.

the class CatalinaClusterSF method storeChildren.

/**
     * Store the specified Cluster children.
     *
     * @param aWriter
     *            PrintWriter to which we are storing
     * @param indent
     *            Number of spaces to indent this element
     * @param aCluster
     *            Cluster whose properties are being stored
     *
     * @exception Exception
     *                if an exception occurs while storing
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aCluster, StoreDescription parentDesc) throws Exception {
    if (aCluster instanceof CatalinaCluster) {
        CatalinaCluster cluster = (CatalinaCluster) aCluster;
        if (cluster instanceof SimpleTcpCluster) {
            SimpleTcpCluster tcpCluster = (SimpleTcpCluster) cluster;
            // Store nested <Manager> element
            ClusterManager manager = tcpCluster.getManagerTemplate();
            if (manager != null) {
                storeElement(aWriter, indent, manager);
            }
        }
        // Store nested <Channel> element
        Channel channel = cluster.getChannel();
        if (channel != null) {
            storeElement(aWriter, indent, channel);
        }
        // Store nested <Deployer> element
        ClusterDeployer deployer = cluster.getClusterDeployer();
        if (deployer != null) {
            storeElement(aWriter, indent, deployer);
        }
        // Store nested <Valve> element
        // ClusterValve are not store at Hosts element, see
        Valve[] valves = cluster.getValves();
        storeElementArray(aWriter, indent, valves);
        if (aCluster instanceof SimpleTcpCluster) {
            // Store nested <Listener> elements
            LifecycleListener[] listeners = ((SimpleTcpCluster) cluster).findLifecycleListeners();
            storeElementArray(aWriter, indent, listeners);
            // Store nested <ClusterListener> elements
            ClusterListener[] mlisteners = ((SimpleTcpCluster) cluster).findClusterListeners();
            List<ClusterListener> clusterListeners = new ArrayList<>();
            for (ClusterListener clusterListener : mlisteners) {
                if (clusterListener != deployer) {
                    clusterListeners.add(clusterListener);
                }
            }
            storeElementArray(aWriter, indent, clusterListeners.toArray());
        }
    }
}
Also used : ClusterDeployer(org.apache.catalina.ha.ClusterDeployer) Channel(org.apache.catalina.tribes.Channel) ArrayList(java.util.ArrayList) LifecycleListener(org.apache.catalina.LifecycleListener) CatalinaCluster(org.apache.catalina.ha.CatalinaCluster) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) ClusterListener(org.apache.catalina.ha.ClusterListener) Valve(org.apache.catalina.Valve) ClusterManager(org.apache.catalina.ha.ClusterManager)

Example 2 with SimpleTcpCluster

use of org.apache.catalina.ha.tcp.SimpleTcpCluster 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 3 with SimpleTcpCluster

use of org.apache.catalina.ha.tcp.SimpleTcpCluster in project tomcat by apache.

the class TestStandardSessionIntegration method doTestInvalidate.

private void doTestInvalidate(boolean useClustering) throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    Tomcat.addServlet(ctx, "bug56578", new Bug56578Servlet());
    ctx.addServletMappingDecoded("/bug56578", "bug56578");
    if (useClustering) {
        tomcat.getEngine().setCluster(new SimpleTcpCluster());
        ctx.setDistributable(true);
        ctx.setManager(ctx.getCluster().createManager(""));
    }
    tomcat.start();
    ByteChunk res = getUrl("http://localhost:" + getPort() + "/bug56578");
    Assert.assertEquals("PASS", res.toString());
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) ByteChunk(org.apache.tomcat.util.buf.ByteChunk)

Aggregations

SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)3 CatalinaCluster (org.apache.catalina.ha.CatalinaCluster)2 ArrayList (java.util.ArrayList)1 Cluster (org.apache.catalina.Cluster)1 Container (org.apache.catalina.Container)1 Context (org.apache.catalina.Context)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Valve (org.apache.catalina.Valve)1 ClusterDeployer (org.apache.catalina.ha.ClusterDeployer)1 ClusterListener (org.apache.catalina.ha.ClusterListener)1 ClusterManager (org.apache.catalina.ha.ClusterManager)1 Tomcat (org.apache.catalina.startup.Tomcat)1 Channel (org.apache.catalina.tribes.Channel)1 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)1 TomEEClusterListener (org.apache.tomee.catalina.cluster.TomEEClusterListener)1