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);
}
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
}
}
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);
}
}
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
}
}
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);
}
}
Aggregations