Class TcpFailureDetector
- All Implemented Interfaces:
ChannelInterceptor, TcpFailureDetectorMBean, Heartbeat, MembershipListener
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:
- It intercepts memberDisappeared events
- It catches send errors
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelInterceptor
ChannelInterceptor.InterceptorEvent -
Field Summary
FieldsModifier and TypeFieldDescriptionMap of members suspected of rejoining and their detection time.protected longConnection timeout in milliseconds for member checks.protected MembershipThe membership tracker.protected booleanWhether to perform TCP read tests during member checks.protected booleanWhether to perform TCP send tests during member checks.protected longRead test timeout in milliseconds.Map of members suspected of being dead and their detection time.protected intTimeout in seconds for removing suspected dead members.protected static final StringManagerThe string manager for this package.protected static final byte[]Test payload sent during member liveness checks.Fields inherited from class ChannelInterceptorBase
optionFlag -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckMembers(boolean checkAll) Checks the status of cluster members.longReturns the connection timeout in milliseconds.getLocalMember(boolean incAlive) Intercepts theChannel.getLocalMember(boolean)methodIntercepts theChannel.getMember(Member)methodMember[]Intercepts theChannel.getMembers()methodbooleanReturns whether read tests are performed.booleanReturns whether send tests are performed.longReturns the read test timeout in milliseconds.intReturns the timeout for removing suspects.booleanIntercepts theChannel.hasMembers()methodvoidTheheartbeat()method gets invoked periodically to allow interceptors to clean up resources, time out object and perform actions that are unrelated to sending/receiving data.voidmemberAdded(Member member) A member was added to the groupprotected booleanmemberAlive(Member mbr) Checks whether the given member is alive using the default test parameters.protected booleanmemberAlive(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.voidmemberDisappeared(Member member) A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD datavoidThemessageReceivedis invoked when a message is received.protected voidPerforms a basic check of suspected members.protected voidPerforms a forced check of all cluster members.voidsendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) ThesendMessagemethod is called when a message is being sent to one more destinations.voidsetConnectTimeout(long connectTimeout) Sets the connection timeout in milliseconds.voidsetPerformReadTest(boolean performReadTest) Sets whether read tests should be performed.voidsetPerformSendTest(boolean performSendTest) Sets whether send tests should be performed.voidsetReadTestTimeout(long readTestTimeout) Sets the read test timeout in milliseconds.voidsetRemoveSuspectsTimeout(int removeSuspectsTimeout) Sets the timeout for removing suspects.protected voidInitializes the membership tracker if not already set up.Methods inherited from class ChannelInterceptorBase
fireInterceptorEvent, getChannel, getNext, getOptionFlag, getPrevious, okToProcess, setChannel, setNext, setOptionFlag, setPrevious, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TcpFailureDetectorMBean
getOptionFlag
-
Field Details
-
sm
The string manager for this package. -
TCP_FAIL_DETECT
protected static final byte[] TCP_FAIL_DETECTTest payload sent during member liveness checks. -
connectTimeout
protected long connectTimeoutConnection timeout in milliseconds for member checks. -
performSendTest
protected boolean performSendTestWhether to perform TCP send tests during member checks. -
performReadTest
protected boolean performReadTestWhether to perform TCP read tests during member checks. -
readTestTimeout
protected long readTestTimeoutRead test timeout in milliseconds. -
membership
The membership tracker. -
removeSuspects
-
addSuspects
-
removeSuspectsTimeout
protected int removeSuspectsTimeoutTimeout 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:ChannelInterceptorThesendMessagemethod 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 invokinggetNext().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:
sendMessagein interfaceChannelInterceptor- Overrides:
sendMessagein classChannelInterceptorBase- Parameters:
destination- Member[] - the destination for this messagemsg- ChannelMessage - the message to be sentpayload- InterceptorPayload - the payload, carrying an error handler and future useful data, can be null- Throws:
ChannelException- if a serialization error happens.- See Also:
-
messageReceived
Description copied from interface:ChannelInterceptorThemessageReceivedis invoked when a message is received.ChannelMessage.getAddress()is the sender, or the reply-to address if it has been overwritten.- Specified by:
messageReceivedin interfaceChannelInterceptor- Overrides:
messageReceivedin classChannelInterceptorBase- Parameters:
msg- ChannelMessage
-
memberAdded
Description copied from interface:MembershipListenerA member was added to the group- Specified by:
memberAddedin interfaceMembershipListener- Overrides:
memberAddedin classChannelInterceptorBase- Parameters:
member- Member - the member that was added
-
memberDisappeared
Description copied from interface:MembershipListenerA member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data- Specified by:
memberDisappearedin interfaceMembershipListener- Overrides:
memberDisappearedin classChannelInterceptorBase- Parameters:
member- Member- See Also:
-
hasMembers
public boolean hasMembers()Description copied from interface:ChannelInterceptorIntercepts theChannel.hasMembers()method- Specified by:
hasMembersin interfaceChannelInterceptor- Overrides:
hasMembersin classChannelInterceptorBase- Returns:
- boolean - if the channel has members in its membership group
- See Also:
-
getMembers
Description copied from interface:ChannelInterceptorIntercepts theChannel.getMembers()method- Specified by:
getMembersin interfaceChannelInterceptor- Overrides:
getMembersin classChannelInterceptorBase- Returns:
- the members
- See Also:
-
getMember
Description copied from interface:ChannelInterceptorIntercepts theChannel.getMember(Member)method- Specified by:
getMemberin interfaceChannelInterceptor- Overrides:
getMemberin classChannelInterceptorBase- Parameters:
mbr- Member- Returns:
- Member - the actual member information, including stay alive
- See Also:
-
getLocalMember
Description copied from interface:ChannelInterceptorIntercepts theChannel.getLocalMember(boolean)method- Specified by:
getLocalMemberin interfaceChannelInterceptor- Overrides:
getLocalMemberin classChannelInterceptorBase- Parameters:
incAlive- boolean- Returns:
- the member that represents this node
- See Also:
-
heartbeat
public void heartbeat()Description copied from interface:ChannelInterceptorTheheartbeat()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:
heartbeatin interfaceChannelInterceptor- Specified by:
heartbeatin interfaceHeartbeat- Overrides:
heartbeatin classChannelInterceptorBase
-
checkMembers
public void checkMembers(boolean checkAll) Description copied from interface:TcpFailureDetectorMBeanChecks the status of cluster members.- Specified by:
checkMembersin interfaceTcpFailureDetectorMBean- 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
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 checkmsgData- the test message datasendTest- whether to perform a send testreadTest- whether to perform a read testreadTimeout- the read timeout in millisecondsconTimeout- the connection timeout in millisecondsoptionFlag- the socket option flag- Returns:
- true if the member is alive
-
getReadTestTimeout
public long getReadTestTimeout()Description copied from interface:TcpFailureDetectorMBeanReturns the read test timeout in milliseconds.- Specified by:
getReadTestTimeoutin interfaceTcpFailureDetectorMBean- Returns:
- the read test timeout
-
getPerformSendTest
public boolean getPerformSendTest()Description copied from interface:TcpFailureDetectorMBeanReturns whether send tests are performed.- Specified by:
getPerformSendTestin interfaceTcpFailureDetectorMBean- Returns:
- true if send tests are enabled
-
getPerformReadTest
public boolean getPerformReadTest()Description copied from interface:TcpFailureDetectorMBeanReturns whether read tests are performed.- Specified by:
getPerformReadTestin interfaceTcpFailureDetectorMBean- Returns:
- true if read tests are enabled
-
getConnectTimeout
public long getConnectTimeout()Description copied from interface:TcpFailureDetectorMBeanReturns the connection timeout in milliseconds.- Specified by:
getConnectTimeoutin interfaceTcpFailureDetectorMBean- Returns:
- the connection timeout
-
getRemoveSuspectsTimeout
public int getRemoveSuspectsTimeout()Description copied from interface:TcpFailureDetectorMBeanReturns the timeout for removing suspects.- Specified by:
getRemoveSuspectsTimeoutin interfaceTcpFailureDetectorMBean- Returns:
- the remove suspects timeout
-
setPerformReadTest
public void setPerformReadTest(boolean performReadTest) Description copied from interface:TcpFailureDetectorMBeanSets whether read tests should be performed.- Specified by:
setPerformReadTestin interfaceTcpFailureDetectorMBean- Parameters:
performReadTest- true to enable read tests
-
setPerformSendTest
public void setPerformSendTest(boolean performSendTest) Description copied from interface:TcpFailureDetectorMBeanSets whether send tests should be performed.- Specified by:
setPerformSendTestin interfaceTcpFailureDetectorMBean- Parameters:
performSendTest- true to enable send tests
-
setReadTestTimeout
public void setReadTestTimeout(long readTestTimeout) Description copied from interface:TcpFailureDetectorMBeanSets the read test timeout in milliseconds.- Specified by:
setReadTestTimeoutin interfaceTcpFailureDetectorMBean- Parameters:
readTestTimeout- the timeout value
-
setConnectTimeout
public void setConnectTimeout(long connectTimeout) Description copied from interface:TcpFailureDetectorMBeanSets the connection timeout in milliseconds.- Specified by:
setConnectTimeoutin interfaceTcpFailureDetectorMBean- Parameters:
connectTimeout- the timeout value
-
setRemoveSuspectsTimeout
public void setRemoveSuspectsTimeout(int removeSuspectsTimeout) Description copied from interface:TcpFailureDetectorMBeanSets the timeout for removing suspects.- Specified by:
setRemoveSuspectsTimeoutin interfaceTcpFailureDetectorMBean- Parameters:
removeSuspectsTimeout- the timeout value
-