org.apache.catalina.tribes.membership.StaticMember Java Examples

The following examples show how to use org.apache.catalina.tribes.membership.StaticMember. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TcpFailureDetector.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void memberAdded(Member member) {
    if ( membership == null ) setupMembership();
    boolean notify = false;
    synchronized (membership) {
        if (removeSuspects.containsKey(member)) {
            //previously marked suspect, system below picked up the member again
            removeSuspects.remove(member);
        } else if (membership.getMember(member) == null){
            //if we add it here, then add it upwards too
            //check to see if it is alive
            if (memberAlive(member)) {
                membership.memberAlive(member);
                notify = true;
            } else {
                if (member instanceof StaticMember) {
                    addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
                }
            }
        }
    }
    if ( notify ) super.memberAdded(member);
}
 
Example #2
Source File: TcpFailureDetector.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected void performForcedCheck() {
    //update all alive times
    Member[] members = super.getMembers();
    for (int i = 0; members != null && i < members.length; i++) {
        if (memberAlive(members[i])) {
            if (membership.memberAlive(members[i])) super.memberAdded(members[i]);
            addSuspects.remove(members[i]);
        } else {
            if (membership.getMember(members[i])!=null) {
                membership.removeMember(members[i]);
                removeSuspects.remove(members[i]);
                if (members[i] instanceof StaticMember) {
                    addSuspects.put(members[i], Long.valueOf(System.currentTimeMillis()));
                }
                super.memberDisappeared(members[i]);
            }
        } //end if
    } //for

}
 
Example #3
Source File: TcpFailureDetector.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected void performForcedCheck() {
    //update all alive times
    Member[] members = super.getMembers();
    for (int i = 0; members != null && i < members.length; i++) {
        if (memberAlive(members[i])) {
            if (membership.memberAlive((MemberImpl)members[i])) super.memberAdded(members[i]);
            addSuspects.remove(members[i]);
        } else {
            if (membership.getMember(members[i])!=null) {
                membership.removeMember((MemberImpl)members[i]);
                removeSuspects.remove(members[i]);
                if (members[i] instanceof StaticMember) {
                    addSuspects.put(members[i], Long.valueOf(System.currentTimeMillis()));
                }
                super.memberDisappeared(members[i]);
            }
        } //end if
    } //for

}
 
Example #4
Source File: TcpFailureDetector.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
protected void performForcedCheck() {
    //update all alive times
    Member[] members = super.getMembers();
    for (int i = 0; members != null && i < members.length; i++) {
        if (memberAlive(members[i])) {
            if (membership.memberAlive((MemberImpl)members[i])) super.memberAdded(members[i]);
            addSuspects.remove(members[i]);
        } else {
            if (membership.getMember(members[i])!=null) {
                membership.removeMember((MemberImpl)members[i]);
                removeSuspects.remove(members[i]);
                if (members[i] instanceof StaticMember) {
                    addSuspects.put(members[i], Long.valueOf(System.currentTimeMillis()));
                }
                super.memberDisappeared(members[i]);
            }
        } //end if
    } //for

}
 
Example #5
Source File: ChannelCoordinator.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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) return; //we have already started up all components
        if (svc == 0 ) return;//nothing to start

        if (svc == (svc & startLevel)) {
            throw new ChannelException(sm.getString("channelCoordinator.alreadyStarted",
                    Integer.toString(svc)));
        }

        //must start the receiver first so that we can coordinate the port it
        //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);
    }
}
 
Example #6
Source File: TcpFailureDetector.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public void memberDisappeared(Member member) {
    if ( membership == null ) setupMembership();
    boolean shutdown = Arrays.equals(member.getCommand(),Member.SHUTDOWN_PAYLOAD);
    if (shutdown) {
        synchronized (membership) {
            if (!membership.contains(member)) return;
            membership.removeMember(member);
            removeSuspects.remove(member);
            if (member instanceof StaticMember) {
                addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
            }
        }
        super.memberDisappeared(member);
    } else {
        boolean notify = false;
        if(log.isInfoEnabled())
            log.info(sm.getString("tcpFailureDetector.memberDisappeared.verify", member));
        synchronized (membership) {
            if (!membership.contains(member)) {
                if(log.isInfoEnabled())
                    log.info(sm.getString("tcpFailureDetector.already.disappeared", member));
                return;
            }
            //check to see if the member really is gone
            if (!memberAlive(member)) {
                //not correct, we need to maintain the map
                membership.removeMember(member);
                removeSuspects.remove(member);
                if (member instanceof StaticMember) {
                    addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
                }
                notify = true;
            } else {
                //add the member as suspect
                removeSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
            }
        }
        if ( notify ) {
            if(log.isInfoEnabled())
                log.info(sm.getString("tcpFailureDetector.member.disappeared", member));
            super.memberDisappeared(member);
        } else {
            if(log.isInfoEnabled())
                log.info(sm.getString("tcpFailureDetector.still.alive", member));
        }
    }
}
 
Example #7
Source File: TcpFailureDetector.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public void memberDisappeared(Member member) {
    if ( membership == null ) setupMembership();
    boolean notify = false;
    boolean shutdown = Arrays.equals(member.getCommand(),Member.SHUTDOWN_PAYLOAD);
    if (shutdown) {
        synchronized (membership) {
            if (!membership.contains(member)) return;
            membership.removeMember( (MemberImpl) member);
            removeSuspects.remove(member);
            if (member instanceof StaticMember) {
                addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
            }
        }
        super.memberDisappeared(member);
    } else {
        if(log.isInfoEnabled())
            log.info("Received memberDisappeared["+member+"] message. Will verify.");
        synchronized (membership) {
            if (!membership.contains(member)) {
                if(log.isInfoEnabled())
                    log.info("Verification complete. Member already disappeared["+member+"]");
                return;
            }
            //check to see if the member really is gone
            if (!memberAlive(member)) {
                //not correct, we need to maintain the map
                membership.removeMember( (MemberImpl) member);
                removeSuspects.remove(member);
                if (member instanceof StaticMember) {
                    addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
                }
                notify = true;
            } else {
                //add the member as suspect
                removeSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
            }
        }
        if ( notify ) {
            if(log.isInfoEnabled())
                log.info("Verification complete. Member disappeared["+member+"]");
            super.memberDisappeared(member);
        } else {
            if(log.isInfoEnabled()) 
                log.info("Verification complete. Member still alive["+member+"]");
        }
    }
}
 
Example #8
Source File: ChannelCoordinator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * 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) return; //we have already started up all components
        if (svc == 0 ) return;//nothing to start
        
        if (svc == (svc & startLevel)) throw new ChannelException("Channel already started for level:"+svc);

        //must start the receiver first so that we can coordinate the port it
        //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);
    }
}
 
Example #9
Source File: TcpFailureDetector.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void memberDisappeared(Member member) {
    if ( membership == null ) setupMembership();
    boolean notify = false;
    boolean shutdown = Arrays.equals(member.getCommand(),Member.SHUTDOWN_PAYLOAD);
    if (shutdown) {
        synchronized (membership) {
            if (!membership.contains(member)) return;
            membership.removeMember( (MemberImpl) member);
            removeSuspects.remove(member);
            if (member instanceof StaticMember) {
                addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
            }
        }
        super.memberDisappeared(member);
    } else {
        if(log.isInfoEnabled())
            log.info("Received memberDisappeared["+member+"] message. Will verify.");
        synchronized (membership) {
            if (!membership.contains(member)) {
                if(log.isInfoEnabled())
                    log.info("Verification complete. Member already disappeared["+member+"]");
                return;
            }
            //check to see if the member really is gone
            if (!memberAlive(member)) {
                //not correct, we need to maintain the map
                membership.removeMember( (MemberImpl) member);
                removeSuspects.remove(member);
                if (member instanceof StaticMember) {
                    addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
                }
                notify = true;
            } else {
                //add the member as suspect
                removeSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
            }
        }
        if ( notify ) {
            if(log.isInfoEnabled())
                log.info("Verification complete. Member disappeared["+member+"]");
            super.memberDisappeared(member);
        } else {
            if(log.isInfoEnabled()) 
                log.info("Verification complete. Member still alive["+member+"]");
        }
    }
}
 
Example #10
Source File: StaticMembershipInterceptor.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public void setLocalMember(Member member) {
    this.localMember = member;
    ((StaticMember)localMember).setLocal(true);
}