Search in sources :

Example 21 with GroupChannel

use of org.apache.catalina.tribes.group.GroupChannel in project tomcat by apache.

the class TestNonBlockingCoordinator method setUp.

@Before
public void setUp() throws Exception {
    LogManager.getLogManager().getLogger("org.apache.catalina.tribes.group.interceptors.TestNonBlockingCoordinator").setLevel(Level.ALL);
    try {
        log.info("Setup");
        channels = new GroupChannel[CHANNEL_COUNT];
        coordinators = new NonBlockingCoordinator[CHANNEL_COUNT];
        Thread[] threads = new Thread[CHANNEL_COUNT];
        for (int i = 0; i < CHANNEL_COUNT; i++) {
            channels[i] = new GroupChannel();
            ((ReceiverBase) channels[i].getChannelReceiver()).setHost("localhost");
            coordinators[i] = new NonBlockingCoordinator();
            channels[i].addInterceptor(coordinators[i]);
            TcpFailureDetector tcpFailureDetector = new TcpFailureDetector();
            // Double default timeout - mainly for loaded CI systems
            tcpFailureDetector.setReadTestTimeout(tcpFailureDetector.getReadTestTimeout() * 2);
            channels[i].addInterceptor(tcpFailureDetector);
            final int j = i;
            threads[i] = new Thread() {

                @Override
                public void run() {
                    try {
                        channels[j].start(Channel.DEFAULT);
                    } catch (Exception x) {
                        x.printStackTrace();
                    }
                }
            };
        }
        TesterUtil.addRandomDomain(channels);
        for (int i = 0; i < CHANNEL_COUNT; i++) {
            threads[i].start();
        }
        for (int i = 0; i < CHANNEL_COUNT; i++) {
            threads[i].join();
        }
        // Allow up to 30s for cluster to form once all the nodes have been
        // started
        int count = 0;
        Member member = null;
        boolean electionComplete = false;
        while (!electionComplete && count < 300) {
            electionComplete = true;
            member = coordinators[0].getCoordinator();
            if (member == null) {
                electionComplete = false;
            } else {
                for (int i = 0; i < CHANNEL_COUNT; i++) {
                    electionComplete = electionComplete && (member.equals(coordinators[i].getCoordinator()));
                }
            }
            Thread.sleep(100);
            count++;
        }
    } finally {
        LogManager.getLogManager().getLogger("org.apache.catalina.tribes.group.interceptors.TestNonBlockingCoordinator").setLevel(Level.INFO);
    }
}
Also used : ReceiverBase(org.apache.catalina.tribes.transport.ReceiverBase) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) Member(org.apache.catalina.tribes.Member) Before(org.junit.Before)

Example 22 with GroupChannel

use of org.apache.catalina.tribes.group.GroupChannel in project tomcat by apache.

the class TestMulticastPackages method setUp.

@Before
public void setUp() throws Exception {
    channel1 = new GroupChannel();
    channel1.addInterceptor(new MessageDispatchInterceptor());
    channel2 = new GroupChannel();
    channel2.addInterceptor(new MessageDispatchInterceptor());
    ThroughputInterceptor tint = new ThroughputInterceptor();
    tint.setInterval(500);
    ThroughputInterceptor tint2 = new ThroughputInterceptor();
    tint2.setInterval(500);
    // channel1.addInterceptor(tint);
    channel2.addInterceptor(tint2);
    listener1 = new Listener();
    ReceiverBase rb1 = (ReceiverBase) channel1.getChannelReceiver();
    ReceiverBase rb2 = (ReceiverBase) channel2.getChannelReceiver();
    rb1.setUdpPort(50000);
    rb2.setUdpPort(50000);
    channel2.addChannelListener(listener1);
    TesterUtil.addRandomDomain(new ManagedChannel[] { channel1, channel2 });
    channel1.start(Channel.DEFAULT);
    channel2.start(Channel.DEFAULT);
}
Also used : ReceiverBase(org.apache.catalina.tribes.transport.ReceiverBase) ChannelListener(org.apache.catalina.tribes.ChannelListener) MessageDispatchInterceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) ThroughputInterceptor(org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor) Before(org.junit.Before)

Example 23 with GroupChannel

use of org.apache.catalina.tribes.group.GroupChannel in project tomcat by apache.

the class TestUdpPackages method setUp.

@Before
public void setUp() throws Exception {
    channel1 = new GroupChannel();
    channel1.addInterceptor(new MessageDispatchInterceptor());
    channel2 = new GroupChannel();
    channel2.addInterceptor(new MessageDispatchInterceptor());
    ThroughputInterceptor tint = new ThroughputInterceptor();
    tint.setInterval(500);
    ThroughputInterceptor tint2 = new ThroughputInterceptor();
    tint2.setInterval(500);
    // channel1.addInterceptor(tint);
    channel2.addInterceptor(tint2);
    listener1 = new Listener();
    ReceiverBase rb1 = (ReceiverBase) channel1.getChannelReceiver();
    ReceiverBase rb2 = (ReceiverBase) channel2.getChannelReceiver();
    rb1.setUdpPort(50000);
    rb2.setUdpPort(50000);
    channel2.addChannelListener(listener1);
    TesterUtil.addRandomDomain(new ManagedChannel[] { channel1, channel2 });
    channel1.start(Channel.DEFAULT);
    channel2.start(Channel.DEFAULT);
}
Also used : ReceiverBase(org.apache.catalina.tribes.transport.ReceiverBase) ChannelListener(org.apache.catalina.tribes.ChannelListener) MessageDispatchInterceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) ThroughputInterceptor(org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor) Before(org.junit.Before)

Example 24 with GroupChannel

use of org.apache.catalina.tribes.group.GroupChannel in project tomcat by apache.

the class TestOrderInterceptor method setUp.

@Before
public void setUp() throws Exception {
    System.out.println("Setup");
    channels = new GroupChannel[channelCount];
    orderitcs = new OrderInterceptor[channelCount];
    mangleitcs = new MangleOrderInterceptor[channelCount];
    test = new TestListener[channelCount];
    threads = new Thread[channelCount];
    for (int i = 0; i < channelCount; i++) {
        channels[i] = new GroupChannel();
        ((ReceiverBase) channels[i].getChannelReceiver()).setHost("localhost");
        orderitcs[i] = new OrderInterceptor();
        mangleitcs[i] = new MangleOrderInterceptor();
        orderitcs[i].setExpire(Long.MAX_VALUE);
        channels[i].addInterceptor(orderitcs[i]);
        channels[i].addInterceptor(mangleitcs[i]);
        test[i] = new TestListener(i);
        channels[i].addChannelListener(test[i]);
        final int j = i;
        threads[i] = new Thread() {

            @Override
            public void run() {
                try {
                    channels[j].start(Channel.DEFAULT);
                    Thread.sleep(50);
                } catch (Exception x) {
                    x.printStackTrace();
                }
            }
        };
    }
    TesterUtil.addRandomDomain(channels);
    for (int i = 0; i < channelCount; i++) {
        threads[i].start();
    }
    int totalSleep = 0;
    for (int i = 0; i < channelCount; i++) {
        Member[] m = channels[i].getMembers();
        while (m == null || m.length < channelCount - 1) {
            totalSleep += 50;
            if (totalSleep > 60000) {
                Assert.fail("Cluster took more than 60s to start");
            }
            Thread.sleep(50);
            m = channels[i].getMembers();
        }
    }
}
Also used : ReceiverBase(org.apache.catalina.tribes.transport.ReceiverBase) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) Member(org.apache.catalina.tribes.Member) ChannelException(org.apache.catalina.tribes.ChannelException) Before(org.junit.Before)

Example 25 with GroupChannel

use of org.apache.catalina.tribes.group.GroupChannel in project tomcat by apache.

the class SimpleTcpCluster method checkDefaults.

protected void checkDefaults() {
    if (clusterListeners.size() == 0 && managerTemplate instanceof DeltaManager) {
        addClusterListener(new ClusterSessionListener());
    }
    if (valves.size() == 0) {
        addValve(new JvmRouteBinderValve());
        addValve(new ReplicationValve());
    }
    if (clusterDeployer != null) {
        clusterDeployer.setCluster(this);
    }
    if (channel == null) {
        channel = new GroupChannel();
    }
    if (channel instanceof GroupChannel && !((GroupChannel) channel).getInterceptors().hasNext()) {
        channel.addInterceptor(new MessageDispatchInterceptor());
        channel.addInterceptor(new TcpFailureDetector());
    }
    if (heartbeatBackgroundEnabled) {
        channel.setHeartbeat(false);
    }
}
Also used : JvmRouteBinderValve(org.apache.catalina.ha.session.JvmRouteBinderValve) MessageDispatchInterceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) TcpFailureDetector(org.apache.catalina.tribes.group.interceptors.TcpFailureDetector) DeltaManager(org.apache.catalina.ha.session.DeltaManager) ClusterSessionListener(org.apache.catalina.ha.session.ClusterSessionListener)

Aggregations

GroupChannel (org.apache.catalina.tribes.group.GroupChannel)28 Before (org.junit.Before)16 ReceiverBase (org.apache.catalina.tribes.transport.ReceiverBase)9 ChannelListener (org.apache.catalina.tribes.ChannelListener)8 MessageDispatchInterceptor (org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor)8 TcpFailureDetector (org.apache.catalina.tribes.group.interceptors.TcpFailureDetector)6 ThroughputInterceptor (org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor)6 MessageDispatch15Interceptor (org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor)5 McastService (org.apache.catalina.tribes.membership.McastService)5 ClusterSessionListener (org.apache.catalina.ha.session.ClusterSessionListener)4 JvmRouteBinderValve (org.apache.catalina.ha.session.JvmRouteBinderValve)4 SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)4 Member (org.apache.catalina.tribes.Member)4 StaticMembershipInterceptor (org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor)4 ReplicationTransmitter (org.apache.catalina.tribes.transport.ReplicationTransmitter)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 lombok.val (lombok.val)2 DeltaManager (org.apache.catalina.ha.session.DeltaManager)2