Class StaticMembershipProvider
- java.lang.Object
-
- org.apache.catalina.tribes.membership.MembershipProviderBase
-
- org.apache.catalina.tribes.membership.StaticMembershipProvider
-
- All Implemented Interfaces:
ChannelListener,RpcCallback,Heartbeat,MembershipProvider
public class StaticMembershipProvider extends MembershipProviderBase implements RpcCallback, ChannelListener, Heartbeat
Provider that manages static membership for a cluster.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStaticMembershipProvider.MemberMessageMessage sent between membership providers to coordinate membership state.protected classStaticMembershipProvider.PingThreadBackground thread that periodically sends ping messages to cluster members.
-
Field Summary
Fields Modifier and Type Field Description protected ChannelchannelThe channel associated with this provider.protected intconnectTimeoutSocket connection timeout in milliseconds.protected longexpirationTimeTime in milliseconds after which a member is considered expired.protected longpingIntervalInterval between ping messages in milliseconds.protected RpcChannelrpcChannelRPC channel for sending messages.protected longrpcTimeoutRPC operation timeout in milliseconds.protected booleanrunningWhether the ping thread is currently running.protected intsendOptionsSend options flag for channel messages.protected static StringManagersmString manager for this class.protected intstartLevelCurrent start level bitmask.protected java.util.ArrayList<StaticMember>staticMembersList of static members for this cluster.protected StaticMembershipProvider.PingThreadthreadBackground ping thread instance.protected booleanuseThreadWhether to use a background thread for pinging.-
Fields inherited from class org.apache.catalina.tribes.membership.MembershipProviderBase
executor, membership, membershipListener, service
-
-
Constructor Summary
Constructors Constructor Description StaticMembershipProvider()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccept(java.io.Serializable msg, Member sender)Invoked by the channel to determine if the listener will process this message or not.protected voidcheckExpired()Checks for and removes expired members.voidheartbeat()Heartbeat invocation for resources cleanup etcvoidinit(java.util.Properties properties)Initialize the membership provider with the specified configuration.voidleftOver(java.io.Serializable msg, Member sender)If the reply has already been sent to the requesting thread, the rpc callback can handle any data that comes in after the fact.protected voidmemberAdded(Member member)Handles the addition of a new member to the cluster.protected voidmemberAlive(Member member)Updates the alive status of a member.protected voidmemberDisappeared(Member member)Handles the disappearance of a member from the cluster.voidmessageReceived(java.io.Serializable msg, Member sender)Receive a message from the channelprotected voidping()Sends ping messages to all static members and checks for expired members.java.io.SerializablereplyRequest(java.io.Serializable msg, Member sender)Allows sending a response to a received message.voidsetChannel(Channel channel)Sets the channel for this provider.voidsetStaticMembers(java.util.ArrayList<StaticMember> staticMembers)Sets the static members for this cluster.protected MembersetupMember(Member mbr)Sets up a member after it joins.voidstart(int level)Start the membership provider.protected voidstartMembership(Member[] members)Sends start messages to the given members.booleanstop(int level)Stop the membership provider.protected voidstopMembership(Member[] members)Sends stop messages to the given members.-
Methods inherited from class org.apache.catalina.tribes.membership.MembershipProviderBase
getMember, getMembers, hasMembers, setMembershipListener, setMembershipService
-
-
-
-
Field Detail
-
sm
protected static final StringManager sm
String manager for this class.
-
channel
protected Channel channel
The channel associated with this provider.
-
rpcChannel
protected RpcChannel rpcChannel
RPC channel for sending messages.
-
staticMembers
protected java.util.ArrayList<StaticMember> staticMembers
List of static members for this cluster.
-
sendOptions
protected int sendOptions
Send options flag for channel messages.
-
expirationTime
protected long expirationTime
Time in milliseconds after which a member is considered expired.
-
connectTimeout
protected int connectTimeout
Socket connection timeout in milliseconds.
-
rpcTimeout
protected long rpcTimeout
RPC operation timeout in milliseconds.
-
startLevel
protected int startLevel
Current start level bitmask.
-
useThread
protected boolean useThread
Whether to use a background thread for pinging.
-
pingInterval
protected long pingInterval
Interval between ping messages in milliseconds.
-
running
protected volatile boolean running
Whether the ping thread is currently running.
-
thread
protected StaticMembershipProvider.PingThread thread
Background ping thread instance.
-
-
Method Detail
-
init
public void init(java.util.Properties properties) throws java.lang.ExceptionDescription copied from interface:MembershipProviderInitialize the membership provider with the specified configuration.- Specified by:
initin interfaceMembershipProvider- Overrides:
initin classMembershipProviderBase- Parameters:
properties- configuration- Throws:
java.lang.Exception- if an error occurs
-
start
public void start(int level) throws java.lang.ExceptionDescription copied from interface:MembershipProviderStart the membership provider.- Specified by:
startin interfaceMembershipProvider- Parameters:
level- the readiness level- Channel.DEFAULT - will start all services
- Channel.MBR_RX_SEQ - starts the membership receiver
- Channel.MBR_TX_SEQ - starts the membership broadcaster
- Throws:
java.lang.Exception- if an error occurs
-
stop
public boolean stop(int level) throws java.lang.ExceptionDescription copied from interface:MembershipProviderStop the membership provider.- Specified by:
stopin interfaceMembershipProvider- Parameters:
level- the readiness level- Channel.DEFAULT - will stop all services
- Channel.MBR_RX_SEQ - stops the membership receiver
- Channel.MBR_TX_SEQ - stops the membership broadcaster
- Returns:
trueif successful- Throws:
java.lang.Exception- if an error occurs
-
startMembership
protected void startMembership(Member[] members) throws ChannelException
Sends start messages to the given members.- Parameters:
members- the members to notify- Throws:
ChannelException- if sending fails
-
setupMember
protected Member setupMember(Member mbr)
Sets up a member after it joins. Override for customization.- Parameters:
mbr- the member to set up- Returns:
- the configured member
-
memberAdded
protected void memberAdded(Member member)
Handles the addition of a new member to the cluster.- Parameters:
member- the member that was added
-
memberDisappeared
protected void memberDisappeared(Member member)
Handles the disappearance of a member from the cluster.- Parameters:
member- the member that disappeared
-
memberAlive
protected void memberAlive(Member member)
Updates the alive status of a member.- Parameters:
member- the member to update
-
stopMembership
protected void stopMembership(Member[] members)
Sends stop messages to the given members.- Parameters:
members- the members to notify
-
messageReceived
public void messageReceived(java.io.Serializable msg, Member sender)Description copied from interface:ChannelListenerReceive a message from the channel- Specified by:
messageReceivedin interfaceChannelListener- Parameters:
msg- Serializablesender- - the source of the message
-
accept
public boolean accept(java.io.Serializable msg, Member sender)Description copied from interface:ChannelListenerInvoked by the channel to determine if the listener will process this message or not.- Specified by:
acceptin interfaceChannelListener- Parameters:
msg- Serializablesender- Member- Returns:
- boolean
-
replyRequest
public java.io.Serializable replyRequest(java.io.Serializable msg, Member sender)Description copied from interface:RpcCallbackAllows sending a response to a received message.- Specified by:
replyRequestin interfaceRpcCallback- Parameters:
msg- The messagesender- Member- Returns:
- Serializable object,
nullif no reply should be sent
-
leftOver
public void leftOver(java.io.Serializable msg, Member sender)Description copied from interface:RpcCallbackIf the reply has already been sent to the requesting thread, the rpc callback can handle any data that comes in after the fact.- Specified by:
leftOverin interfaceRpcCallback- Parameters:
msg- The messagesender- Member
-
heartbeat
public void heartbeat()
Description copied from interface:HeartbeatHeartbeat invocation for resources cleanup etc
-
ping
protected void ping() throws ChannelExceptionSends ping messages to all static members and checks for expired members.- Throws:
ChannelException- if pinging fails
-
checkExpired
protected void checkExpired()
Checks for and removes expired members.
-
setChannel
public void setChannel(Channel channel)
Sets the channel for this provider.- Parameters:
channel- the channel
-
setStaticMembers
public void setStaticMembers(java.util.ArrayList<StaticMember> staticMembers)
Sets the static members for this cluster.- Parameters:
staticMembers- the list of static members
-
-