Search in sources :

Example 1 with GroupChannel

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

the class CasTomcatEmbeddedServletContainerFactory method configureSessionClustering.

private void configureSessionClustering(final Tomcat tomcat) {
    if (!clusteringProperties.isSessionClusteringEnabled()) {
        LOGGER.debug("Tomcat session clustering/replication is turned off");
        return;
    }
    final SimpleTcpCluster cluster = new SimpleTcpCluster();
    cluster.setChannelSendOptions(clusteringProperties.getChannelSendOptions());
    final ClusterManagerBase manager = getClusteringManagerInstance();
    cluster.setManagerTemplate(manager);
    final GroupChannel channel = new GroupChannel();
    final NioReceiver receiver = new NioReceiver();
    receiver.setPort(clusteringProperties.getReceiverPort());
    receiver.setTimeout(clusteringProperties.getReceiverTimeout());
    receiver.setMaxThreads(clusteringProperties.getReceiverMaxThreads());
    receiver.setAddress(clusteringProperties.getReceiverAddress());
    receiver.setAutoBind(clusteringProperties.getReceiverAutoBind());
    channel.setChannelReceiver(receiver);
    final McastService membershipService = new McastService();
    membershipService.setPort(clusteringProperties.getMembershipPort());
    membershipService.setAddress(clusteringProperties.getMembershipAddress());
    membershipService.setFrequency(clusteringProperties.getMembershipFrequency());
    membershipService.setDropTime(clusteringProperties.getMembershipDropTime());
    membershipService.setRecoveryEnabled(clusteringProperties.isMembershipRecoveryEnabled());
    membershipService.setRecoveryCounter(clusteringProperties.getMembershipRecoveryCounter());
    membershipService.setLocalLoopbackDisabled(clusteringProperties.isMembershipLocalLoopbackDisabled());
    channel.setMembershipService(membershipService);
    final ReplicationTransmitter sender = new ReplicationTransmitter();
    sender.setTransport(new PooledParallelSender());
    channel.setChannelSender(sender);
    channel.addInterceptor(new TcpPingInterceptor());
    channel.addInterceptor(new TcpFailureDetector());
    channel.addInterceptor(new MessageDispatchInterceptor());
    final StaticMembershipInterceptor membership = new StaticMembershipInterceptor();
    final String[] memberSpecs = clusteringProperties.getClusterMembers().split(",", -1);
    for (final String spec : memberSpecs) {
        final ClusterMemberDesc memberDesc = new ClusterMemberDesc(spec);
        final StaticMember member = new StaticMember();
        member.setHost(memberDesc.getAddress());
        member.setPort(memberDesc.getPort());
        member.setDomain("CAS");
        member.setUniqueId(memberDesc.getUniqueId());
        membership.addStaticMember(member);
        channel.addInterceptor(membership);
        cluster.setChannel(channel);
    }
    cluster.addValve(new ReplicationValve());
    cluster.addValve(new JvmRouteBinderValve());
    cluster.addClusterListener(new ClusterSessionListener());
    tomcat.getEngine().setCluster(cluster);
}
Also used : NioReceiver(org.apache.catalina.tribes.transport.nio.NioReceiver) MessageDispatchInterceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor) StaticMembershipInterceptor(org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor) JvmRouteBinderValve(org.apache.catalina.ha.session.JvmRouteBinderValve) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) TcpFailureDetector(org.apache.catalina.tribes.group.interceptors.TcpFailureDetector) ToString(lombok.ToString) ReplicationTransmitter(org.apache.catalina.tribes.transport.ReplicationTransmitter) ReplicationValve(org.apache.catalina.ha.tcp.ReplicationValve) StaticMember(org.apache.catalina.tribes.membership.StaticMember) SimpleTcpCluster(org.apache.catalina.ha.tcp.SimpleTcpCluster) PooledParallelSender(org.apache.catalina.tribes.transport.nio.PooledParallelSender) TcpPingInterceptor(org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor) ClusterManagerBase(org.apache.catalina.ha.session.ClusterManagerBase) ClusterSessionListener(org.apache.catalina.ha.session.ClusterSessionListener) McastService(org.apache.catalina.tribes.membership.McastService)

Example 2 with GroupChannel

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

the class SimpleTcpCluster method startInternal.

/**
 * Start Cluster and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {
    if (log.isInfoEnabled())
        log.info("Cluster is about to start");
    try {
        checkDefaults();
        registerClusterValve();
        channel.addMembershipListener(this);
        channel.addChannelListener(this);
        if (channel instanceof GroupChannel)
            ((GroupChannel) channel).setName(getClusterName() + "-Channel");
        channel.start(channelStartOptions);
        if (clusterDeployer != null)
            clusterDeployer.start();
        registerMember(channel.getLocalMember(false));
    } catch (Exception x) {
        log.error("Unable to start cluster.", x);
        throw new LifecycleException(x);
    }
    setState(LifecycleState.STARTING);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) LifecycleException(org.apache.catalina.LifecycleException)

Example 3 with GroupChannel

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

the class ChannelCreator method createChannel.

public static Channel createChannel(String[] args) throws Exception {
    String bind = "auto";
    int port = 4001;
    String mbind = null;
    boolean gzip = false;
    int tcpseltimeout = 5000;
    int tcpthreadcount = 4;
    int acktimeout = 15000;
    String mcastaddr = "228.0.0.5";
    int mcastport = 45565;
    long mcastfreq = 500;
    long mcastdrop = 2000;
    boolean order = false;
    int ordersize = Integer.MAX_VALUE;
    boolean frag = false;
    int fragsize = 1024;
    int autoBind = 10;
    ArrayList<Member> staticMembers = new ArrayList<Member>();
    Properties transportProperties = new Properties();
    String transport = "org.apache.catalina.tribes.transport.nio.PooledParallelSender";
    String receiver = "org.apache.catalina.tribes.transport.nio.NioReceiver";
    boolean async = false;
    // 50MB
    int asyncsize = 1024 * 1024 * 50;
    boolean throughput = false;
    boolean failuredetect = false;
    for (int i = 0; i < args.length; i++) {
        if ("-bind".equals(args[i])) {
            bind = args[++i];
        } else if ("-port".equals(args[i])) {
            port = Integer.parseInt(args[++i]);
        } else if ("-autobind".equals(args[i])) {
            autoBind = Integer.parseInt(args[++i]);
        } else if ("-tcpselto".equals(args[i])) {
            tcpseltimeout = Integer.parseInt(args[++i]);
        } else if ("-tcpthreads".equals(args[i])) {
            tcpthreadcount = Integer.parseInt(args[++i]);
        } else if ("-gzip".equals(args[i])) {
            gzip = true;
        } else if ("-async".equals(args[i])) {
            async = true;
        } else if ("-failuredetect".equals(args[i])) {
            failuredetect = true;
        } else if ("-asyncsize".equals(args[i])) {
            asyncsize = Integer.parseInt(args[++i]);
            System.out.println("Setting MessageDispatchInterceptor.maxQueueSize=" + asyncsize);
        } else if ("-static".equals(args[i])) {
            String d = args[++i];
            String h = d.substring(0, d.indexOf(':'));
            String p = d.substring(h.length() + 1);
            MemberImpl m = new MemberImpl(h, Integer.parseInt(p), 2000);
            staticMembers.add(m);
        } else if ("-throughput".equals(args[i])) {
            throughput = true;
        } else if ("-order".equals(args[i])) {
            order = true;
        } else if ("-ordersize".equals(args[i])) {
            ordersize = Integer.parseInt(args[++i]);
            System.out.println("Setting OrderInterceptor.maxQueue=" + ordersize);
        } else if ("-frag".equals(args[i])) {
            frag = true;
        } else if ("-fragsize".equals(args[i])) {
            fragsize = Integer.parseInt(args[++i]);
            System.out.println("Setting FragmentationInterceptor.maxSize=" + fragsize);
        } else if ("-ackto".equals(args[i])) {
            acktimeout = Integer.parseInt(args[++i]);
        } else if ("-transport".equals(args[i])) {
            transport = args[++i];
        } else if (args[i] != null && args[i].startsWith("transport.")) {
            String key = args[i];
            String val = args[++i];
            transportProperties.setProperty(key, val);
        } else if ("-receiver".equals(args[i])) {
            receiver = args[++i];
        } else if ("-maddr".equals(args[i])) {
            mcastaddr = args[++i];
        } else if ("-mport".equals(args[i])) {
            mcastport = Integer.parseInt(args[++i]);
        } else if ("-mfreq".equals(args[i])) {
            mcastfreq = Long.parseLong(args[++i]);
        } else if ("-mdrop".equals(args[i])) {
            mcastdrop = Long.parseLong(args[++i]);
        } else if ("-mbind".equals(args[i])) {
            mbind = args[++i];
        }
    }
    System.out.println("Creating receiver class=" + receiver);
    Class<?> cl = Class.forName(receiver, true, ChannelCreator.class.getClassLoader());
    ReceiverBase rx = (ReceiverBase) cl.newInstance();
    rx.setAddress(bind);
    rx.setPort(port);
    rx.setSelectorTimeout(tcpseltimeout);
    rx.setMaxThreads(tcpthreadcount);
    rx.setMinThreads(tcpthreadcount);
    rx.getBind();
    rx.setRxBufSize(43800);
    rx.setTxBufSize(25188);
    rx.setAutoBind(autoBind);
    ReplicationTransmitter ps = new ReplicationTransmitter();
    System.out.println("Creating transport class=" + transport);
    MultiPointSender sender = (MultiPointSender) Class.forName(transport, true, ChannelCreator.class.getClassLoader()).newInstance();
    sender.setTimeout(acktimeout);
    sender.setMaxRetryAttempts(2);
    sender.setRxBufSize(43800);
    sender.setTxBufSize(25188);
    Iterator<Object> i = transportProperties.keySet().iterator();
    while (i.hasNext()) {
        String key = (String) i.next();
        IntrospectionUtils.setProperty(sender, key, transportProperties.getProperty(key));
    }
    ps.setTransport(sender);
    McastService service = new McastService();
    service.setAddress(mcastaddr);
    if (mbind != null)
        service.setMcastBindAddress(mbind);
    service.setFrequency(mcastfreq);
    service.setMcastDropTime(mcastdrop);
    service.setPort(mcastport);
    ManagedChannel channel = new GroupChannel();
    channel.setChannelReceiver(rx);
    channel.setChannelSender(ps);
    channel.setMembershipService(service);
    if (throughput)
        channel.addInterceptor(new ThroughputInterceptor());
    if (gzip)
        channel.addInterceptor(new GzipInterceptor());
    if (frag) {
        FragmentationInterceptor fi = new FragmentationInterceptor();
        fi.setMaxSize(fragsize);
        channel.addInterceptor(fi);
    }
    if (order) {
        OrderInterceptor oi = new OrderInterceptor();
        oi.setMaxQueue(ordersize);
        channel.addInterceptor(oi);
    }
    if (async) {
        MessageDispatchInterceptor mi = new MessageDispatch15Interceptor();
        mi.setMaxQueueSize(asyncsize);
        channel.addInterceptor(mi);
        System.out.println("Added MessageDispatchInterceptor");
    }
    if (failuredetect) {
        TcpFailureDetector tcpfi = new TcpFailureDetector();
        channel.addInterceptor(tcpfi);
    }
    if (staticMembers.size() > 0) {
        StaticMembershipInterceptor smi = new StaticMembershipInterceptor();
        for (int x = 0; x < staticMembers.size(); x++) {
            smi.addStaticMember(staticMembers.get(x));
        }
        channel.addInterceptor(smi);
    }
    byte[] domain = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    ((McastService) channel.getMembershipService()).setDomain(domain);
    DomainFilterInterceptor filter = new DomainFilterInterceptor();
    filter.setDomain(domain);
    channel.addInterceptor(filter);
    return channel;
}
Also used : ReceiverBase(org.apache.catalina.tribes.transport.ReceiverBase) MultiPointSender(org.apache.catalina.tribes.transport.MultiPointSender) StaticMembershipInterceptor(org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor) ArrayList(java.util.ArrayList) FragmentationInterceptor(org.apache.catalina.tribes.group.interceptors.FragmentationInterceptor) TcpFailureDetector(org.apache.catalina.tribes.group.interceptors.TcpFailureDetector) Properties(java.util.Properties) GzipInterceptor(org.apache.catalina.tribes.group.interceptors.GzipInterceptor) OrderInterceptor(org.apache.catalina.tribes.group.interceptors.OrderInterceptor) ManagedChannel(org.apache.catalina.tribes.ManagedChannel) Member(org.apache.catalina.tribes.Member) DomainFilterInterceptor(org.apache.catalina.tribes.group.interceptors.DomainFilterInterceptor) MessageDispatchInterceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) ReplicationTransmitter(org.apache.catalina.tribes.transport.ReplicationTransmitter) MessageDispatch15Interceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor) ThroughputInterceptor(org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor) McastService(org.apache.catalina.tribes.membership.McastService)

Example 4 with GroupChannel

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

the class TestDataIntegrity method setUp.

@Before
public void setUp() throws Exception {
    channel1 = new GroupChannel();
    channel1.addInterceptor(new MessageDispatch15Interceptor());
    channel2 = new GroupChannel();
    channel2.addInterceptor(new MessageDispatch15Interceptor());
    listener1 = new Listener();
    channel2.addChannelListener(listener1);
    TesterUtil.addRandomDomain(new ManagedChannel[] { channel1, channel2 });
    channel1.start(Channel.DEFAULT);
    channel2.start(Channel.DEFAULT);
}
Also used : ChannelListener(org.apache.catalina.tribes.ChannelListener) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) MessageDispatch15Interceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor) Before(org.junit.Before)

Example 5 with GroupChannel

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

the class TestNonBlockingCoordinator method setUp.

@Before
public void setUp() throws Exception {
    System.out.println("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();
        coordinators[i] = new NonBlockingCoordinator();
        channels[i].addInterceptor(coordinators[i]);
        channels[i].addInterceptor(new TcpFailureDetector());
        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 < CHANNEL_COUNT; i++) {
        threads[i].start();
    }
    for (int i = 0; i < CHANNEL_COUNT; i++) {
        threads[i].join();
    }
    Thread.sleep(1000);
}
Also used : GroupChannel(org.apache.catalina.tribes.group.GroupChannel) Before(org.junit.Before)

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