Search in sources :

Example 1 with StaticMember

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

use of org.apache.catalina.tribes.membership.StaticMember in project tomcat70 by apache.

the class TcpFailureDetector method performBasicCheck.

protected void performBasicCheck() {
    // update all alive times
    Member[] members = super.getMembers();
    for (int i = 0; members != null && i < members.length; i++) {
        if (addSuspects.containsKey(members[i]) && membership.getMember(members[i]) == null) {
            // avoid temporary adding member.
            continue;
        }
        if (membership.memberAlive((MemberImpl) members[i])) {
            // we don't have this one in our membership, check to see if he/she is alive
            if (memberAlive(members[i])) {
                log.warn("Member added, even though we weren't notified:" + members[i]);
                super.memberAdded(members[i]);
            } else {
                membership.removeMember((MemberImpl) members[i]);
            }
        // end if
        }
    // end if
    }
    // for
    // check suspect members if they are still alive,
    // if not, simply issue the memberDisappeared message
    MemberImpl[] keys = removeSuspects.keySet().toArray(new MemberImpl[removeSuspects.size()]);
    for (int i = 0; i < keys.length; i++) {
        MemberImpl m = keys[i];
        if (membership.getMember(m) != null && (!memberAlive(m))) {
            membership.removeMember(m);
            if (m instanceof StaticMember) {
                addSuspects.put(m, Long.valueOf(System.currentTimeMillis()));
            }
            super.memberDisappeared(m);
            removeSuspects.remove(m);
            if (log.isInfoEnabled())
                log.info("Suspect member, confirmed dead.[" + m + "]");
        } else {
            if (removeSuspectsTimeout > 0) {
                long timeNow = System.currentTimeMillis();
                int timeIdle = (int) ((timeNow - removeSuspects.get(m).longValue()) / 1000L);
                if (timeIdle > removeSuspectsTimeout) {
                    // remove suspect member
                    removeSuspects.remove(m);
                }
            }
        }
    }
    // check add suspects members if they are alive now,
    // if they are, simply issue the memberAdded message
    keys = addSuspects.keySet().toArray(new MemberImpl[addSuspects.size()]);
    for (int i = 0; i < keys.length; i++) {
        MemberImpl m = keys[i];
        if (membership.getMember(m) == null && (memberAlive(m))) {
            membership.memberAlive(m);
            super.memberAdded(m);
            addSuspects.remove(m);
            if (log.isInfoEnabled())
                log.info("Suspect member, confirmed alive.[" + m + "]");
        }
    // end if
    }
}
Also used : StaticMember(org.apache.catalina.tribes.membership.StaticMember) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) Member(org.apache.catalina.tribes.Member) StaticMember(org.apache.catalina.tribes.membership.StaticMember)

Example 3 with StaticMember

use of org.apache.catalina.tribes.membership.StaticMember in project tomcat70 by apache.

the class ChannelCoordinator method internalStart.

/**
 * Starts up the channel. This can be called multiple times for individual services to start
 * The svc parameter can be the logical or value of any constants
 * @param svc int value of <BR>
 * DEFAULT - will start all services <BR>
 * MBR_RX_SEQ - starts the membership receiver <BR>
 * MBR_TX_SEQ - starts the membership broadcaster <BR>
 * SND_TX_SEQ - starts the replication transmitter<BR>
 * SND_RX_SEQ - starts the replication receiver<BR>
 * @throws ChannelException if a startup error occurs or the service is already started.
 */
protected synchronized void internalStart(int svc) throws ChannelException {
    try {
        boolean valid = false;
        // make sure we don't pass down any flags that are unrelated to the bottom layer
        svc = svc & Channel.DEFAULT;
        // we have already started up all components
        if (startLevel == Channel.DEFAULT)
            return;
        // nothing to start
        if (svc == 0)
            return;
        if (svc == (svc & startLevel))
            throw new ChannelException("Channel already started for level:" + svc);
        // listens to with the local membership settings
        if (Channel.SND_RX_SEQ == (svc & Channel.SND_RX_SEQ)) {
            clusterReceiver.setMessageListener(this);
            if (clusterReceiver instanceof ReceiverBase) {
                ((ReceiverBase) clusterReceiver).setChannel(getChannel());
            }
            clusterReceiver.start();
            // synchronize, big time FIXME
            Member localMember = getChannel().getLocalMember(false);
            if (localMember instanceof StaticMember) {
                // static member
                StaticMember staticMember = (StaticMember) localMember;
                staticMember.setHost(getClusterReceiver().getHost());
                staticMember.setPort(getClusterReceiver().getPort());
                staticMember.setSecurePort(getClusterReceiver().getSecurePort());
            } else {
                // multicast member
                membershipService.setLocalMemberProperties(getClusterReceiver().getHost(), getClusterReceiver().getPort(), getClusterReceiver().getSecurePort(), getClusterReceiver().getUdpPort());
            }
            valid = true;
        }
        if (Channel.SND_TX_SEQ == (svc & Channel.SND_TX_SEQ)) {
            if (clusterSender instanceof ReplicationTransmitter) {
                ((ReplicationTransmitter) clusterSender).setChannel(getChannel());
            }
            valid = true;
            clusterSender.start();
        }
        if (Channel.MBR_RX_SEQ == (svc & Channel.MBR_RX_SEQ)) {
            membershipService.setMembershipListener(this);
            if (membershipService instanceof McastService) {
                ((McastService) membershipService).setMessageListener(this);
                ((McastService) membershipService).setChannel(getChannel());
            }
            membershipService.start(MembershipService.MBR_RX);
            valid = true;
        }
        if (Channel.MBR_TX_SEQ == (svc & Channel.MBR_TX_SEQ)) {
            if (membershipService instanceof McastService) {
                ((McastService) membershipService).setChannel(getChannel());
            }
            membershipService.start(MembershipService.MBR_TX);
            valid = true;
        }
        if (!valid) {
            throw new IllegalArgumentException("Invalid start level, valid levels are:SND_RX_SEQ,SND_TX_SEQ,MBR_TX_SEQ,MBR_RX_SEQ");
        }
        startLevel = (startLevel | svc);
    } catch (ChannelException cx) {
        throw cx;
    } catch (Exception x) {
        throw new ChannelException(x);
    }
}
Also used : ReceiverBase(org.apache.catalina.tribes.transport.ReceiverBase) StaticMember(org.apache.catalina.tribes.membership.StaticMember) Member(org.apache.catalina.tribes.Member) StaticMember(org.apache.catalina.tribes.membership.StaticMember) ReplicationTransmitter(org.apache.catalina.tribes.transport.ReplicationTransmitter) ChannelException(org.apache.catalina.tribes.ChannelException) ChannelException(org.apache.catalina.tribes.ChannelException) McastService(org.apache.catalina.tribes.membership.McastService)

Example 4 with StaticMember

use of org.apache.catalina.tribes.membership.StaticMember in project tomcat by apache.

the class TcpFailureDetector method performBasicCheck.

protected void performBasicCheck() {
    // update all alive times
    Member[] members = super.getMembers();
    for (int i = 0; members != null && i < members.length; i++) {
        if (addSuspects.containsKey(members[i]) && membership.getMember(members[i]) == null) {
            // avoid temporary adding member.
            continue;
        }
        if (membership.memberAlive(members[i])) {
            // we don't have this one in our membership, check to see if the member is alive
            if (memberAlive(members[i])) {
                log.warn(sm.getString("tcpFailureDetector.performBasicCheck.memberAdded", members[i]));
                super.memberAdded(members[i]);
            } else {
                membership.removeMember(members[i]);
            }
        // end if
        }
    // end if
    }
    // for
    // check suspect members if they are still alive,
    // if not, simply issue the memberDisappeared message
    Member[] keys = removeSuspects.keySet().toArray(new Member[0]);
    for (Member m : keys) {
        if (membership.getMember(m) != null && (!memberAlive(m))) {
            membership.removeMember(m);
            if (m instanceof StaticMember) {
                addSuspects.put(m, Long.valueOf(System.currentTimeMillis()));
            }
            super.memberDisappeared(m);
            removeSuspects.remove(m);
            if (log.isInfoEnabled()) {
                log.info(sm.getString("tcpFailureDetector.suspectMember.dead", m));
            }
        } else {
            if (removeSuspectsTimeout > 0) {
                long timeNow = System.currentTimeMillis();
                int timeIdle = (int) ((timeNow - removeSuspects.get(m).longValue()) / 1000L);
                if (timeIdle > removeSuspectsTimeout) {
                    // remove suspect member
                    removeSuspects.remove(m);
                }
            }
        }
    }
    // check add suspects members if they are alive now,
    // if they are, simply issue the memberAdded message
    keys = addSuspects.keySet().toArray(new Member[0]);
    for (Member m : keys) {
        if (membership.getMember(m) == null && (memberAlive(m))) {
            membership.memberAlive(m);
            super.memberAdded(m);
            addSuspects.remove(m);
            if (log.isInfoEnabled()) {
                log.info(sm.getString("tcpFailureDetector.suspectMember.alive", m));
            }
        }
    // end if
    }
}
Also used : StaticMember(org.apache.catalina.tribes.membership.StaticMember) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) Member(org.apache.catalina.tribes.Member) StaticMember(org.apache.catalina.tribes.membership.StaticMember)

Example 5 with StaticMember

use of org.apache.catalina.tribes.membership.StaticMember in project tomcat by apache.

the class ChannelCoordinator method internalStart.

/**
 * Starts up the channel. This can be called multiple times for individual services to start
 * The svc parameter can be the logical or value of any constants
 * @param svc int value of <BR>
 * DEFAULT - will start all services <BR>
 * MBR_RX_SEQ - starts the membership receiver <BR>
 * MBR_TX_SEQ - starts the membership broadcaster <BR>
 * SND_TX_SEQ - starts the replication transmitter<BR>
 * SND_RX_SEQ - starts the replication receiver<BR>
 * @throws ChannelException if a startup error occurs or the service is already started.
 */
protected synchronized void internalStart(int svc) throws ChannelException {
    try {
        boolean valid = false;
        // make sure we don't pass down any flags that are unrelated to the bottom layer
        svc = svc & Channel.DEFAULT;
        if (startLevel == Channel.DEFAULT) {
            // we have already started up all components
            return;
        }
        if (svc == 0) {
            // nothing to start
            return;
        }
        if (svc == (svc & startLevel)) {
            throw new ChannelException(sm.getString("channelCoordinator.alreadyStarted", Integer.toString(svc)));
        }
        // listens to with the local membership settings
        if (Channel.SND_RX_SEQ == (svc & Channel.SND_RX_SEQ)) {
            clusterReceiver.setMessageListener(this);
            clusterReceiver.setChannel(getChannel());
            clusterReceiver.start();
            // synchronize, big time FIXME
            Member localMember = getChannel().getLocalMember(false);
            if (localMember instanceof StaticMember) {
                // static member
                StaticMember staticMember = (StaticMember) localMember;
                staticMember.setHost(getClusterReceiver().getHost());
                staticMember.setPort(getClusterReceiver().getPort());
                staticMember.setSecurePort(getClusterReceiver().getSecurePort());
            } else {
                // multicast member
                membershipService.setLocalMemberProperties(getClusterReceiver().getHost(), getClusterReceiver().getPort(), getClusterReceiver().getSecurePort(), getClusterReceiver().getUdpPort());
            }
            valid = true;
        }
        if (Channel.SND_TX_SEQ == (svc & Channel.SND_TX_SEQ)) {
            clusterSender.setChannel(getChannel());
            clusterSender.start();
            valid = true;
        }
        if (Channel.MBR_RX_SEQ == (svc & Channel.MBR_RX_SEQ)) {
            membershipService.setMembershipListener(this);
            membershipService.setChannel(getChannel());
            if (membershipService instanceof McastService) {
                ((McastService) membershipService).setMessageListener(this);
            }
            membershipService.start(MembershipService.MBR_RX);
            valid = true;
        }
        if (Channel.MBR_TX_SEQ == (svc & Channel.MBR_TX_SEQ)) {
            membershipService.setChannel(getChannel());
            membershipService.start(MembershipService.MBR_TX);
            valid = true;
        }
        if (!valid) {
            throw new IllegalArgumentException(sm.getString("channelCoordinator.invalid.startLevel"));
        }
        startLevel = (startLevel | svc);
    } catch (ChannelException cx) {
        throw cx;
    } catch (Exception x) {
        throw new ChannelException(x);
    }
}
Also used : StaticMember(org.apache.catalina.tribes.membership.StaticMember) Member(org.apache.catalina.tribes.Member) StaticMember(org.apache.catalina.tribes.membership.StaticMember) ChannelException(org.apache.catalina.tribes.ChannelException) ChannelException(org.apache.catalina.tribes.ChannelException) McastService(org.apache.catalina.tribes.membership.McastService)

Aggregations

StaticMember (org.apache.catalina.tribes.membership.StaticMember)5 Member (org.apache.catalina.tribes.Member)4 McastService (org.apache.catalina.tribes.membership.McastService)3 ChannelException (org.apache.catalina.tribes.ChannelException)2 FaultyMember (org.apache.catalina.tribes.ChannelException.FaultyMember)2 ReplicationTransmitter (org.apache.catalina.tribes.transport.ReplicationTransmitter)2 ToString (lombok.ToString)1 ClusterManagerBase (org.apache.catalina.ha.session.ClusterManagerBase)1 ClusterSessionListener (org.apache.catalina.ha.session.ClusterSessionListener)1 JvmRouteBinderValve (org.apache.catalina.ha.session.JvmRouteBinderValve)1 ReplicationValve (org.apache.catalina.ha.tcp.ReplicationValve)1 SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster)1 GroupChannel (org.apache.catalina.tribes.group.GroupChannel)1 MessageDispatchInterceptor (org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor)1 StaticMembershipInterceptor (org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor)1 TcpFailureDetector (org.apache.catalina.tribes.group.interceptors.TcpFailureDetector)1 TcpPingInterceptor (org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor)1 MemberImpl (org.apache.catalina.tribes.membership.MemberImpl)1 ReceiverBase (org.apache.catalina.tribes.transport.ReceiverBase)1 NioReceiver (org.apache.catalina.tribes.transport.nio.NioReceiver)1