Class TcpPingInterceptor
- java.lang.Object
-
- org.apache.catalina.tribes.group.ChannelInterceptorBase
-
- org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor
-
- All Implemented Interfaces:
ChannelInterceptor,TcpPingInterceptorMBean,Heartbeat,MembershipListener
public class TcpPingInterceptor extends ChannelInterceptorBase implements TcpPingInterceptorMBean
Sends periodic TCP pings to cluster members for health monitoring.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classTcpPingInterceptor.PingThreadBackground thread that sends periodic pings.-
Nested classes/interfaces inherited from interface org.apache.catalina.tribes.ChannelInterceptor
ChannelInterceptor.InterceptorEvent
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.concurrent.atomic.AtomicIntegercntCounter for naming ping threads.protected longintervalPing interval in milliseconds.protected booleanrunningWhether the ping thread is currently running.protected static StringManagersmThe string manager for this package.protected booleanstaticOnlyWhether to ping only static members.protected static byte[]TCP_PING_DATATest payload sent during ping checks.protected TcpPingInterceptor.PingThreadthreadThe background ping thread.protected booleanuseThreadWhether to use a dedicated thread for pinging.-
Fields inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBase
optionFlag
-
-
Constructor Summary
Constructors Constructor Description TcpPingInterceptor()Constructs a new TcpPingInterceptor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetInterval()Returns the ping interval in milliseconds.booleangetStaticOnly()Returns whether static-only mode is enabled.booleangetUseThread()Returns whether a dedicated ping thread is used.voidheartbeat()Theheartbeat()method gets invoked periodically to allow interceptors to clean up resources, time out object and perform actions that are unrelated to sending/receiving data.voidmessageReceived(ChannelMessage msg)ThemessageReceivedis invoked when a message is received.protected voidsendPing()Sends a ping to cluster members.protected voidsendPingMessage(Member[] members)Sends a ping message to the specified members.voidsetInterval(long interval)Sets the ping interval in milliseconds.voidsetStaticOnly(boolean staticOnly)Sets whether to ping only static members.voidsetUseThread(boolean useThread)Sets whether to use a dedicated thread for pinging.voidstart(int svc)Starts up the channel.voidstop(int svc)Shuts down the channel.-
Methods inherited from class org.apache.catalina.tribes.group.ChannelInterceptorBase
fireInterceptorEvent, getChannel, getLocalMember, getMember, getMembers, getNext, getOptionFlag, getPrevious, hasMembers, memberAdded, memberDisappeared, okToProcess, sendMessage, setChannel, setNext, setOptionFlag, setPrevious
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.catalina.tribes.group.interceptors.TcpPingInterceptorMBean
getOptionFlag
-
-
-
-
Field Detail
-
sm
protected static final StringManager sm
The string manager for this package.
-
TCP_PING_DATA
protected static final byte[] TCP_PING_DATA
Test payload sent during ping checks.
-
interval
protected long interval
Ping interval in milliseconds.
-
useThread
protected boolean useThread
Whether to use a dedicated thread for pinging.
-
staticOnly
protected boolean staticOnly
Whether to ping only static members.
-
running
protected volatile boolean running
Whether the ping thread is currently running.
-
thread
protected TcpPingInterceptor.PingThread thread
The background ping thread.
-
cnt
protected static final java.util.concurrent.atomic.AtomicInteger cnt
Counter for naming ping threads.
-
-
Method Detail
-
start
public void start(int svc) throws ChannelExceptionDescription copied from interface:ChannelInterceptorStarts 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- Specified by:
startin interfaceChannelInterceptor- Overrides:
startin classChannelInterceptorBase- Parameters:
svc- one of:- Channel.DEFAULT - will start all services
- Channel.MBR_RX_SEQ - starts the membership receiver
- Channel.MBR_TX_SEQ - starts the membership broadcaster
- Channel.SND_TX_SEQ - starts the replication transmitter
- Channel.SND_RX_SEQ - starts the replication receiver
- Throws:
ChannelException- if a startup error occurs or the service is already started.- See Also:
Channel
-
stop
public void stop(int svc) throws ChannelExceptionDescription copied from interface:ChannelInterceptorShuts down the channel. This can be called multiple times for individual services to shut down. The svc parameter can be the logical or value of any constants- Specified by:
stopin interfaceChannelInterceptor- Overrides:
stopin classChannelInterceptorBase- Parameters:
svc- one of:- Channel.DEFAULT - will shut down all services
- Channel.MBR_RX_SEQ - stops the membership receiver
- Channel.MBR_TX_SEQ - stops the membership broadcaster
- Channel.SND_TX_SEQ - stops the replication transmitter
- Channel.SND_RX_SEQ - stops the replication receiver
- Throws:
ChannelException- if a startup error occurs or the service is already started.- See Also:
Channel
-
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
-
getInterval
public long getInterval()
Description copied from interface:TcpPingInterceptorMBeanReturns the ping interval in milliseconds.- Specified by:
getIntervalin interfaceTcpPingInterceptorMBean- Returns:
- the ping interval
-
setInterval
public void setInterval(long interval)
Sets the ping interval in milliseconds.- Parameters:
interval- the interval in milliseconds
-
setUseThread
public void setUseThread(boolean useThread)
Sets whether to use a dedicated thread for pinging.- Parameters:
useThread- true to use a dedicated thread
-
setStaticOnly
public void setStaticOnly(boolean staticOnly)
Sets whether to ping only static members.- Parameters:
staticOnly- true to ping only static members
-
getUseThread
public boolean getUseThread()
Description copied from interface:TcpPingInterceptorMBeanReturns whether a dedicated ping thread is used.- Specified by:
getUseThreadin interfaceTcpPingInterceptorMBean- Returns:
- true if a dedicated thread is used
-
getStaticOnly
public boolean getStaticOnly()
Returns whether static-only mode is enabled.- Returns:
- true if only static members are pinged
-
sendPing
protected void sendPing()
Sends a ping to cluster members.
-
sendPingMessage
protected void sendPingMessage(Member[] members)
Sends a ping message to the specified members.- Parameters:
members- the members to ping
-
messageReceived
public void messageReceived(ChannelMessage msg)
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
-
-