TcpFailureDetector (Apache Tomcat 11.0.25 API Documentation)
Description: declaration: package: org.apache.catalina.tribes.group.interceptors, class: TcpFailureDetector

# Class TcpFailureDetector

java.lang.Object
org.apache.catalina.tribes.group.ChannelInterceptorBase
org.apache.catalina.tribes.group.interceptors.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

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from interface ChannelInterceptor

  `ChannelInterceptor.InterceptorEvent`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final HashMap<Member,Long>`
  `addSuspects`
  Map of members suspected of rejoining and their detection time.
  `protected long`
  `connectTimeout`
  Connection timeout in milliseconds for member checks.
  `protected Membership`
  `membership`
  The membership tracker.
  `protected boolean`
  `performReadTest`
  Whether to perform TCP read tests during member checks.
  `protected boolean`
  `performSendTest`
  Whether to perform TCP send tests during member checks.
  `protected long`
  `readTestTimeout`
  Read test timeout in milliseconds.
  `protected final HashMap<Member,Long>`
  `removeSuspects`
  Map of members suspected of being dead and their detection time.
  `protected int`
  `removeSuspectsTimeout`
  Timeout in seconds for removing suspected dead members.
  `protected static final StringManager`
  `sm`
  The string manager for this package.
  `protected static final byte[]`
  `TCP_FAIL_DETECT`
  Test payload sent during member liveness checks.

  ### Fields inherited from class ChannelInterceptorBase

  `optionFlag`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TcpFailureDetector()`
  Constructs a new TcpFailureDetector.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `checkMembers(boolean checkAll)`
  Checks the status of cluster members.
  `long`
  `getConnectTimeout()`
  Returns the connection timeout in milliseconds.
  `Member`
  `getLocalMember(boolean incAlive)`
  Intercepts the `Channel.getLocalMember(boolean)` method
  `Member`
  `getMember(Member mbr)`
  Intercepts the `Channel.getMember(Member)` method
  `Member[]`
  `getMembers()`
  Intercepts the `Channel.getMembers()` method
  `boolean`
  `getPerformReadTest()`
  Returns whether read tests are performed.
  `boolean`
  `getPerformSendTest()`
  Returns whether send tests are performed.
  `long`
  `getReadTestTimeout()`
  Returns the read test timeout in milliseconds.
  `int`
  `getRemoveSuspectsTimeout()`
  Returns the timeout for removing suspects.
  `boolean`
  `hasMembers()`
  Intercepts the `Channel.hasMembers()` method
  `void`
  `heartbeat()`
  The `heartbeat()` method gets invoked periodically to allow interceptors to clean up resources, time out object and perform actions that are unrelated to sending/receiving data.
  `void`
  `memberAdded(Member member)`
  A member was added to the group
  `protected boolean`
  `memberAlive(Member mbr)`
  Checks whether the given member is alive using the default test parameters.
  `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.
  `void`
  `memberDisappeared(Member member)`
  A member was removed from the group
  If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data
  `void`
  `messageReceived(ChannelMessage msg)`
  The `messageReceived` is invoked when a message is received.
  `protected void`
  `performBasicCheck()`
  Performs a basic check of suspected members.
  `protected void`
  `performForcedCheck()`
  Performs a forced check of all cluster members.
  `void`
  `sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)`
  The `sendMessage` method is called when a message is being sent to one more destinations.
  `void`
  `setConnectTimeout(long connectTimeout)`
  Sets the connection timeout in milliseconds.
  `void`
  `setPerformReadTest(boolean performReadTest)`
  Sets whether read tests should be performed.
  `void`
  `setPerformSendTest(boolean performSendTest)`
  Sets whether send tests should be performed.
  `void`
  `setReadTestTimeout(long readTestTimeout)`
  Sets the read test timeout in milliseconds.
  `void`
  `setRemoveSuspectsTimeout(int removeSuspectsTimeout)`
  Sets the timeout for removing suspects.
  `protected void`
  `setupMembership()`
  Initializes the membership tracker if not already set up.

  ### Methods inherited from class ChannelInterceptorBase

  `fireInterceptorEvent, getChannel, getNext, getOptionFlag, getPrevious, okToProcess, setChannel, setNext, setOptionFlag, setPrevious, start, stop`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface TcpFailureDetectorMBean

  `getOptionFlag`

- ## Field Details

  - ### 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 HashMap<Member,Long> removeSuspects
    Map of members suspected of being dead and their detection time.

  - ### addSuspects

    protected final HashMap<Member,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 Details

  - ### TcpFailureDetector

    public TcpFailureDetector()
    Constructs a new TcpFailureDetector.

- ## Method Details

  - ### 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`

  - ### messageReceived

    public void messageReceived(ChannelMessage msg)
    Description copied from interface: `ChannelInterceptor`
    The `messageReceived` is invoked when a message is received. `ChannelMessage.getAddress()` is the sender, or the reply-to address if it has been overwritten.
    Specified by:
      `messageReceived` in interface `ChannelInterceptor`
    Overrides:
      `messageReceived` in class `ChannelInterceptorBase`
    Parameters:
      `msg` - ChannelMessage

  - ### memberAdded

    public void memberAdded(Member member)
    Description copied from interface: `MembershipListener`
    A member was added to the group
    Specified by:
      `memberAdded` in interface `MembershipListener`
    Overrides:
      `memberAdded` in class `ChannelInterceptorBase`
    Parameters:
      `member` - Member - the member that was added

  - ### memberDisappeared

    public void memberDisappeared(Member member)
    Description copied from interface: `MembershipListener`
    A member was removed from the group
    If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data
    Specified by:
      `memberDisappeared` in interface `MembershipListener`
    Overrides:
      `memberDisappeared` in class `ChannelInterceptorBase`
    Parameters:
      `member` - Member
    See Also:
      - `Member.SHUTDOWN_PAYLOAD`

  - ### hasMembers

    public boolean hasMembers()
    Description copied from interface: `ChannelInterceptor`
    Intercepts the `Channel.hasMembers()` method
    Specified by:
      `hasMembers` in interface `ChannelInterceptor`
    Overrides:
      `hasMembers` in class `ChannelInterceptorBase`
    Returns:
      boolean - if the channel has members in its membership group
    See Also:
      - `Channel.hasMembers()`

  - ### getMembers

    public Member[] getMembers()
    Description copied from interface: `ChannelInterceptor`
    Intercepts the `Channel.getMembers()` method
    Specified by:
      `getMembers` in interface `ChannelInterceptor`
    Overrides:
      `getMembers` in class `ChannelInterceptorBase`
    Returns:
      the members
    See Also:
      - `Channel.getMembers()`

  - ### getMember

    public Member getMember(Member mbr)
    Description copied from interface: `ChannelInterceptor`
    Intercepts the `Channel.getMember(Member)` method
    Specified by:
      `getMember` in interface `ChannelInterceptor`
    Overrides:
      `getMember` in class `ChannelInterceptorBase`
    Parameters:
      `mbr` - Member
    Returns:
      Member - the actual member information, including stay alive
    See Also:
      - `Channel.getMember(Member)`

  - ### getLocalMember

    public Member getLocalMember(boolean incAlive)
    Description copied from interface: `ChannelInterceptor`
    Intercepts the `Channel.getLocalMember(boolean)` method
    Specified by:
      `getLocalMember` in interface `ChannelInterceptor`
    Overrides:
      `getLocalMember` in class `ChannelInterceptorBase`
    Parameters:
      `incAlive` - boolean
    Returns:
      the member that represents this node
    See Also:
      - `Channel.getLocalMember(boolean)`

  - ### heartbeat

    public void heartbeat()
    Description copied from interface: `ChannelInterceptor`
    The `heartbeat()` method gets invoked periodically to allow interceptors to clean up resources, time out object and perform actions that are unrelated to sending/receiving data.
    Specified by:
      `heartbeat` in interface `ChannelInterceptor`
    Specified by:
      `heartbeat` in interface `Heartbeat`
    Overrides:
      `heartbeat` in class `ChannelInterceptorBase`

  - ### 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.

  - ### performBasicCheck

    protected void performBasicCheck()
    Performs a basic check of suspected members.

  - ### 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

  - ### getReadTestTimeout

    public long getReadTestTimeout()
    Description copied from interface: `TcpFailureDetectorMBean`
    Returns the read test timeout in milliseconds.
    Specified by:
      `getReadTestTimeout` in interface `TcpFailureDetectorMBean`
    Returns:
      the read test timeout

  - ### getPerformSendTest

    public boolean getPerformSendTest()
    Description copied from interface: `TcpFailureDetectorMBean`
    Returns whether send tests are performed.
    Specified by:
      `getPerformSendTest` in interface `TcpFailureDetectorMBean`
    Returns:
      true if send tests are enabled

  - ### getPerformReadTest

    public boolean getPerformReadTest()
    Description copied from interface: `TcpFailureDetectorMBean`
    Returns whether read tests are performed.
    Specified by:
      `getPerformReadTest` in interface `TcpFailureDetectorMBean`
    Returns:
      true if read tests are enabled

  - ### getConnectTimeout

    public long getConnectTimeout()
    Description copied from interface: `TcpFailureDetectorMBean`
    Returns the connection timeout in milliseconds.
    Specified by:
      `getConnectTimeout` in interface `TcpFailureDetectorMBean`
    Returns:
      the connection timeout

  - ### getRemoveSuspectsTimeout

    public int getRemoveSuspectsTimeout()
    Description copied from interface: `TcpFailureDetectorMBean`
    Returns the timeout for removing suspects.
    Specified by:
      `getRemoveSuspectsTimeout` in interface `TcpFailureDetectorMBean`
    Returns:
      the remove suspects timeout

  - ### setPerformReadTest

    public void setPerformReadTest(boolean performReadTest)
    Description copied from interface: `TcpFailureDetectorMBean`
    Sets whether read tests should be performed.
    Specified by:
      `setPerformReadTest` in interface `TcpFailureDetectorMBean`
    Parameters:
      `performReadTest` - true to enable read tests

  - ### setPerformSendTest

    public void setPerformSendTest(boolean performSendTest)
    Description copied from interface: `TcpFailureDetectorMBean`
    Sets whether send tests should be performed.
    Specified by:
      `setPerformSendTest` in interface `TcpFailureDetectorMBean`
    Parameters:
      `performSendTest` - true to enable send tests

  - ### setReadTestTimeout

    public void setReadTestTimeout(long readTestTimeout)
    Description copied from interface: `TcpFailureDetectorMBean`
    Sets the read test timeout in milliseconds.
    Specified by:
      `setReadTestTimeout` in interface `TcpFailureDetectorMBean`
    Parameters:
      `readTestTimeout` - the timeout value

  - ### setConnectTimeout

    public void setConnectTimeout(long connectTimeout)
    Description copied from interface: `TcpFailureDetectorMBean`
    Sets the connection timeout in milliseconds.
    Specified by:
      `setConnectTimeout` in interface `TcpFailureDetectorMBean`
    Parameters:
      `connectTimeout` - the timeout value

  - ### setRemoveSuspectsTimeout

    public void setRemoveSuspectsTimeout(int removeSuspectsTimeout)
    Description copied from interface: `TcpFailureDetectorMBean`
    Sets the timeout for removing suspects.
    Specified by:
      `setRemoveSuspectsTimeout` in interface `TcpFailureDetectorMBean`
    Parameters:
      `removeSuspectsTimeout` - the timeout value