Search in sources :

Example 1 with Channel

use of org.apache.catalina.tribes.Channel 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 Channel

use of org.apache.catalina.tribes.Channel in project tomcat by apache.

the class TestGroupChannelMemberArrival method testMemberArrival.

@Test
public void testMemberArrival() throws Exception {
    //purpose of this test is to make sure that we have received all the members
    //that we can expect before the start method returns
    Thread[] threads = new Thread[channels.length];
    for (int i = 0; i < channels.length; i++) {
        final Channel channel = channels[i];
        Thread t = new Thread() {

            @Override
            public void run() {
                try {
                    channel.start(Channel.DEFAULT);
                } catch (Exception x) {
                    throw new RuntimeException(x);
                }
            }
        };
        threads[i] = t;
    }
    for (int i = 0; i < threads.length; i++) {
        threads[i].start();
    }
    for (int i = 0; i < threads.length; i++) {
        threads[i].join();
    }
    Thread.sleep(5000);
    System.out.println(System.currentTimeMillis() + " All channels started.");
    StringBuilder arrivalLengthErrors = new StringBuilder();
    for (int i = listeners.length - 1; i >= 0; i--) {
        TestMbrListener listener = listeners[i];
        synchronized (listener.members) {
            if (channels.length - 1 != listener.members.size()) {
                arrivalLengthErrors.append("Checking member arrival length for [");
                arrivalLengthErrors.append(listener.name);
                arrivalLengthErrors.append("]. Was [");
                arrivalLengthErrors.append(listener.members.size());
                arrivalLengthErrors.append("] but should have been [");
                arrivalLengthErrors.append(channels.length - 1);
                arrivalLengthErrors.append("]");
                arrivalLengthErrors.append('\n');
            }
        }
    }
    // Note if this fails for all listeners check multicast is working with
    // org.apache.catalina.tribes.TesterMulticast
    Assert.assertTrue(arrivalLengthErrors.toString(), arrivalLengthErrors.length() == 0);
    System.out.println(System.currentTimeMillis() + " Members arrival counts checked.");
}
Also used : ManagedChannel(org.apache.catalina.tribes.ManagedChannel) Channel(org.apache.catalina.tribes.Channel) Test(org.junit.Test)

Example 3 with Channel

use of org.apache.catalina.tribes.Channel in project tomcat by apache.

the class ChannelSF method storeChildren.

/**
     * Store the specified Channel children.
     *
     * @param aWriter
     *            PrintWriter to which we are storing
     * @param indent
     *            Number of spaces to indent this element
     * @param aChannel
     *            Channel whose properties are being stored
     *
     * @exception Exception
     *                if an exception occurs while storing
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aChannel, StoreDescription parentDesc) throws Exception {
    if (aChannel instanceof Channel) {
        Channel channel = (Channel) aChannel;
        if (channel instanceof ManagedChannel) {
            ManagedChannel managedChannel = (ManagedChannel) channel;
            // Store nested <Membership> element
            MembershipService service = managedChannel.getMembershipService();
            if (service != null) {
                storeElement(aWriter, indent, service);
            }
            // Store nested <Sender> element
            ChannelSender sender = managedChannel.getChannelSender();
            if (sender != null) {
                storeElement(aWriter, indent, sender);
            }
            // Store nested <Receiver> element
            ChannelReceiver receiver = managedChannel.getChannelReceiver();
            if (receiver != null) {
                storeElement(aWriter, indent, receiver);
            }
            Iterator<ChannelInterceptor> interceptors = managedChannel.getInterceptors();
            while (interceptors.hasNext()) {
                ChannelInterceptor interceptor = interceptors.next();
                storeElement(aWriter, indent, interceptor);
            }
        }
    }
}
Also used : ChannelReceiver(org.apache.catalina.tribes.ChannelReceiver) ManagedChannel(org.apache.catalina.tribes.ManagedChannel) Channel(org.apache.catalina.tribes.Channel) MembershipService(org.apache.catalina.tribes.MembershipService) ChannelInterceptor(org.apache.catalina.tribes.ChannelInterceptor) ChannelSender(org.apache.catalina.tribes.ChannelSender) ManagedChannel(org.apache.catalina.tribes.ManagedChannel)

Example 4 with Channel

use of org.apache.catalina.tribes.Channel in project tomcat by apache.

the class TestDomainFilterInterceptor method testMemberArrival.

@Test
public void testMemberArrival() throws Exception {
    //purpose of this test is to make sure that we have received all the members
    //that we can expect before the start method returns
    Thread[] threads = new Thread[channels.length];
    for (int i = 0; i < channels.length; i++) {
        final Channel channel = channels[i];
        Thread t = new Thread() {

            @Override
            public void run() {
                try {
                    channel.start(Channel.DEFAULT);
                } catch (Exception x) {
                    throw new RuntimeException(x);
                }
            }
        };
        threads[i] = t;
    }
    for (int i = 0; i < threads.length; i++) threads[i].start();
    for (int i = 0; i < threads.length; i++) threads[i].join();
    System.out.println("All channels started.");
    for (int i = listeners.length - 1; i >= 0; i--) assertEquals("Checking member arrival length", 0, listeners[i].members.size());
}
Also used : GroupChannel(org.apache.catalina.tribes.group.GroupChannel) ManagedChannel(org.apache.catalina.tribes.ManagedChannel) Channel(org.apache.catalina.tribes.Channel) Test(org.junit.Test)

Aggregations

Channel (org.apache.catalina.tribes.Channel)4 ManagedChannel (org.apache.catalina.tribes.ManagedChannel)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Valve (org.apache.catalina.Valve)1 CatalinaCluster (org.apache.catalina.ha.CatalinaCluster)1 ClusterDeployer (org.apache.catalina.ha.ClusterDeployer)1 ClusterListener (org.apache.catalina.ha.ClusterListener)1 ClusterManager (org.apache.catalina.ha.ClusterManager)1 SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)1 ChannelInterceptor (org.apache.catalina.tribes.ChannelInterceptor)1 ChannelReceiver (org.apache.catalina.tribes.ChannelReceiver)1 ChannelSender (org.apache.catalina.tribes.ChannelSender)1 MembershipService (org.apache.catalina.tribes.MembershipService)1 GroupChannel (org.apache.catalina.tribes.group.GroupChannel)1