Class TcpFailureDetector

  • All Implemented Interfaces:
    ChannelInterceptor, TcpFailureDetectorMBean, Heartbeat, MembershipListener

    public class TcpFailureDetector
    extends ChannelInterceptorBase
    implements TcpFailureDetectorMBean
    The TcpFailureDetector is a useful interceptor that adds reliability to the membership layer.

    If the network is busy, or the system is busy so that the membership receiver thread is not getting enough time to update its table, members can be "timed out" This failure detector will intercept the memberDisappeared message(unless its a true shutdown message) and connect to the member using TCP.

    The TcpFailureDetector works in two ways:

    1. It intercepts memberDisappeared events
    2. It catches send errors
    • Field Detail

      • sm

        protected static final StringManager sm
        The string manager for this package.
      • TCP_FAIL_DETECT

        protected static final byte[] TCP_FAIL_DETECT
        Test payload sent during member liveness checks.
      • connectTimeout

        protected long connectTimeout
        Connection timeout in milliseconds for member checks.
      • performSendTest

        protected boolean performSendTest
        Whether to perform TCP send tests during member checks.
      • performReadTest

        protected boolean performReadTest
        Whether to perform TCP read tests during member checks.
      • readTestTimeout

        protected long readTestTimeout
        Read test timeout in milliseconds.
      • membership

        protected Membership membership
        The membership tracker.
      • removeSuspects

        protected final java.util.HashMap<Member,​java.lang.Long> removeSuspects
        Map of members suspected of being dead and their detection time.
      • addSuspects

        protected final java.util.HashMap<Member,​java.lang.Long> addSuspects
        Map of members suspected of rejoining and their detection time.
      • removeSuspectsTimeout

        protected int removeSuspectsTimeout
        Timeout in seconds for removing suspected dead members.
    • Constructor Detail

      • TcpFailureDetector

        public TcpFailureDetector()
        Constructs a new TcpFailureDetector.
    • Method Detail

      • sendMessage

        public void sendMessage​(Member[] destination,
                                ChannelMessage msg,
                                InterceptorPayload payload)
                         throws ChannelException
        Description copied from interface: ChannelInterceptor
        The sendMessage method is called when a message is being sent to one more destinations. The interceptor can modify any of the parameters and then pass on the message down the stack by invoking getNext().sendMessage(destination,msg,payload).

        Alternatively the interceptor can stop the message from being sent by not invoking getNext().sendMessage(destination,msg,payload).

        If the message is to be sent asynchronous the application can be notified of completion and errors by passing in an error handler attached to a payload object.

        The ChannelMessage.getAddress contains Channel.getLocalMember, and can be overwritten to simulate a message sent from another node.

        Specified by:
        sendMessage in interface ChannelInterceptor
        Overrides:
        sendMessage in class ChannelInterceptorBase
        Parameters:
        destination - Member[] - the destination for this message
        msg - ChannelMessage - the message to be sent
        payload - InterceptorPayload - the payload, carrying an error handler and future useful data, can be null
        Throws:
        ChannelException - if a serialization error happens.
        See Also:
        ErrorHandler, InterceptorPayload
      • forgetMember

        public void forgetMember​(Member member)
        Forgets a member that is represented by another member from now on, for example a statically configured member whose node has been discovered dynamically. Unlike memberDisappeared(Member), the member is not kept as a suspect, so it is not added again by the member checks. If the member was a member of this detector, the interceptors above are told that it disappeared.
        Parameters:
        member - the member to forget
      • checkMembers

        public void checkMembers​(boolean checkAll)
        Description copied from interface: TcpFailureDetectorMBean
        Checks the status of cluster members.
        Specified by:
        checkMembers in interface TcpFailureDetectorMBean
        Parameters:
        checkAll - true to check all members, false to check only suspects
      • performForcedCheck

        protected void performForcedCheck()
        Performs a forced check of all cluster members. The TCP liveness checks run outside the membership monitor and the results are only applied after re-acquiring the monitor and re-checking that the current state still matches the decision.
      • performBasicCheck

        protected void performBasicCheck()
        Performs a basic check of suspected members. The TCP liveness checks run outside the membership monitor and the results are only applied after re-acquiring the monitor and re-checking that the current state still matches the decision.
      • expireRemoveSuspect

        protected void expireRemoveSuspect​(Member m)
        Removes the member from the remove suspects map if it has been suspect for longer than the configured timeout. Must be called while holding the membership monitor.
        Parameters:
        m - the member to expire
      • setupMembership

        protected void setupMembership()
        Initializes the membership tracker if not already set up.
      • memberAlive

        protected boolean memberAlive​(Member mbr)
        Checks whether the given member is alive using the default test parameters.
        Parameters:
        mbr - the member to check
        Returns:
        true if the member is alive
      • memberAlive

        protected boolean memberAlive​(Member mbr,
                                      byte[] msgData,
                                      boolean sendTest,
                                      boolean readTest,
                                      long readTimeout,
                                      long conTimeout,
                                      int optionFlag)
        Checks whether the given member is alive using the specified test parameters.
        Parameters:
        mbr - the member to check
        msgData - the test message data
        sendTest - whether to perform a send test
        readTest - whether to perform a read test
        readTimeout - the read timeout in milliseconds
        conTimeout - the connection timeout in milliseconds
        optionFlag - the socket option flag
        Returns:
        true if the member is alive