Class McastService
java.lang.Object
org.apache.catalina.tribes.membership.MembershipServiceBase
org.apache.catalina.tribes.membership.McastService
- All Implemented Interfaces:
McastServiceMBean, MembershipListener, MembershipService, MessageListener
public class McastService
extends MembershipServiceBase
implements MessageListener, McastServiceMBean
A membership implementation using simple multicast. This is the representation of a multicast membership
service. This class is responsible for maintaining a list of active cluster nodes in the cluster. If a node fails to
send out a heartbeat, the node will be dismissed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]The domain for multicast messages.protected McastServiceImplA handle to the actual low level implementationprotected MemberImplThe local memberprotected MessageListenerA message listener delegate for broadcastsprotected byte[]The payload for multicast messages.protected static final StringManagerThe string manager for this package.Fields inherited from class MembershipServiceBase
channel, listener, propertiesFields inherited from interface MembershipService
MBR_RX, MBR_TX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(ChannelMessage msg) Allows skipping processing of the specified message.voidbroadcast(ChannelMessage message) Broadcasts a message to all members.Get the multicast address.getBind()Get the bind address.byte[]Get the domain.longGet the drop time.longGet the heartbeat frequency.booleanGet whether local loopback is disabled.getLocalMember(boolean alive) Get the local member.Get the local member name.Get the MembershipProviderbyte[]Get the payload.intgetPort()Get the multicast port.intGet the recovery counter.booleanGet whether recovery is enabled.longGet the recovery sleep time.intGet the socket timeout.intgetTtl()Get the TTL.protected voidhasProperty(Properties properties, String name) Check if a required property is available.static voidSimple test programvoidReceive a message from the IO components in the Channel stackvoidRemove the message listener.voidsetAddress(String addr) Set the multicast address.voidSet the bind address.protected voidsetDefaults(Properties properties) Set default property values.voidsetDomain(byte[] domain) Set the associated domain.voidSet the domain from a string.voidsetDropTime(long time) Set the member drop time.voidsetFrequency(long time) Set the heartbeat frequency.voidsetLocalLoopbackDisabled(boolean localLoopbackDisabled) Set whether local loopback is disabled.voidsetLocalMemberProperties(String listenHost, int listenPort, int securePort, int udpPort) Sets the local member properties for broadcasting.voidsetMcastBindAddress(String bindaddr) Set the multicast bind address.voidsetMcastDropTime(long time) Set the multicast drop time.voidsetMessageListener(MessageListener listener) Set the message listener.voidsetPayload(byte[] payload) Set a payload to be broadcasted with each membership broadcast.voidsetPort(int port) Set the multicast port.voidsetProperties(Properties properties) Sets the properties for the membership service.voidsetRecoveryCounter(int recoveryCounter) Set the recovery counter.voidsetRecoveryEnabled(boolean recoveryEnabled) Set whether recovery is enabled.voidsetRecoverySleepTime(long recoverySleepTime) Set the recovery sleep time.voidsetSoTimeout(int mcastSoTimeout) Set the socket timeout.voidsetTtl(int mcastTTL) Set the TTL.voidstart(int level) Starts the membership service.voidstop(int svc) Stop broadcasting and listening to membership pingsMethods inherited from class MembershipServiceBase
findMemberByName, getChannel, getMember, getMembers, getMembersByName, getProperties, hasMembers, memberAdded, memberDisappeared, removeMembershipListener, setChannel, setMembershipListener, startMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface McastServiceMBean
findMemberByName, getMembersByName, getProperties, hasMembers
-
Field Details
-
sm
The string manager for this package. -
impl
A handle to the actual low level implementation -
msglistener
A message listener delegate for broadcasts -
localMember
The local member -
payload
protected byte[] payloadThe payload for multicast messages. -
domain
protected byte[] domainThe domain for multicast messages.
-
-
Constructor Details
-
McastService
public McastService()Create a membership service.
-
-
Method Details
-
setProperties
Sets the properties for the membership service.- Specified by:
setPropertiesin interfaceMembershipService- Overrides:
setPropertiesin classMembershipServiceBase- Parameters:
properties-
All are required
1. mcastPort - the port to listen to
2. mcastAddress - the mcast group address
4. bindAddress - the bind address if any - only one that can be null
5. memberDropTime - the time a member is gone before it is considered gone.
6. mcastFrequency - the frequency of sending messages
7. tcpListenPort - the port this member listens to
8. tcpListenHost - the bind address of this member- Throws:
IllegalArgumentException- if a property is missing.
-
getLocalMemberName
Description copied from interface:McastServiceMBeanGet the local member name.- Specified by:
getLocalMemberNamein interfaceMcastServiceMBean- Returns:
- the local member name
-
getLocalMember
Description copied from interface:MembershipServiceGet the local member.- Specified by:
getLocalMemberin interfaceMembershipService- Parameters:
alive-trueto set the alive time on the local member- Returns:
- the member object that defines this member
-
setLocalMemberProperties
public void setLocalMemberProperties(String listenHost, int listenPort, int securePort, int udpPort) Description copied from interface:MembershipServiceSets the local member properties for broadcasting.- Specified by:
setLocalMemberPropertiesin interfaceMembershipService- Parameters:
listenHost- Listen to hostlistenPort- Listen to portsecurePort- Use a secure portudpPort- Use UDP
-
setAddress
-
getAddress
Description copied from interface:McastServiceMBeanGet the multicast address.- Specified by:
getAddressin interfaceMcastServiceMBean- Returns:
- the address
-
setMcastBindAddress
Set the multicast bind address.- Parameters:
bindaddr- the bind address
-
setBind
-
getBind
Description copied from interface:McastServiceMBeanGet the bind address.- Specified by:
getBindin interfaceMcastServiceMBean- Returns:
- the bind address
-
setPort
public void setPort(int port) Set the multicast port.- Parameters:
port- the port
-
setRecoveryCounter
public void setRecoveryCounter(int recoveryCounter) Set the recovery counter.- Parameters:
recoveryCounter- the recovery counter
-
getRecoveryCounter
public int getRecoveryCounter()Description copied from interface:McastServiceMBeanGet the recovery counter.- Specified by:
getRecoveryCounterin interfaceMcastServiceMBean- Returns:
- the recovery counter
-
setRecoveryEnabled
public void setRecoveryEnabled(boolean recoveryEnabled) Set whether recovery is enabled.- Parameters:
recoveryEnabled- whether recovery is enabled
-
getRecoveryEnabled
public boolean getRecoveryEnabled()Description copied from interface:McastServiceMBeanGet whether recovery is enabled.- Specified by:
getRecoveryEnabledin interfaceMcastServiceMBean- Returns:
- whether recovery is enabled
-
setRecoverySleepTime
public void setRecoverySleepTime(long recoverySleepTime) Set the recovery sleep time.- Parameters:
recoverySleepTime- the recovery sleep time
-
getRecoverySleepTime
public long getRecoverySleepTime()Description copied from interface:McastServiceMBeanGet the recovery sleep time.- Specified by:
getRecoverySleepTimein interfaceMcastServiceMBean- Returns:
- the recovery sleep time
-
setLocalLoopbackDisabled
public void setLocalLoopbackDisabled(boolean localLoopbackDisabled) Set whether local loopback is disabled.- Parameters:
localLoopbackDisabled- whether local loopback is disabled
-
getLocalLoopbackDisabled
public boolean getLocalLoopbackDisabled()Description copied from interface:McastServiceMBeanGet whether local loopback is disabled.- Specified by:
getLocalLoopbackDisabledin interfaceMcastServiceMBean- Returns:
- whether local loopback is disabled
-
getPort
public int getPort()Description copied from interface:McastServiceMBeanGet the multicast port.- Specified by:
getPortin interfaceMcastServiceMBean- Returns:
- the port
-
setFrequency
public void setFrequency(long time) Set the heartbeat frequency.- Parameters:
time- the frequency in milliseconds
-
getFrequency
public long getFrequency()Description copied from interface:McastServiceMBeanGet the heartbeat frequency.- Specified by:
getFrequencyin interfaceMcastServiceMBean- Returns:
- the frequency
-
setMcastDropTime
public void setMcastDropTime(long time) Set the multicast drop time.- Parameters:
time- the drop time in milliseconds
-
setDropTime
public void setDropTime(long time) Set the member drop time.- Parameters:
time- the drop time in milliseconds
-
getDropTime
public long getDropTime()Description copied from interface:McastServiceMBeanGet the drop time.- Specified by:
getDropTimein interfaceMcastServiceMBean- Returns:
- the drop time
-
hasProperty
Check if a required property is available.- Parameters:
properties- The set of propertiesname- The property to check for
-
start
Description copied from interface:MembershipServiceStarts the membership service. If a membership listeners is added the listener will start to receive membership events.- Specified by:
startin interfaceMembershipService- Parameters:
level- - level MBR_RX starts listening for members, level MBR_TX starts broadcasting the server- Throws:
Exception- if the service fails to start.
-
stop
public void stop(int svc) Stop broadcasting and listening to membership pings- Specified by:
stopin interfaceMembershipService- Parameters:
svc- - level MBR_RX stops listening for members, level MBR_TX stops broadcasting the server
-
setMessageListener
Set the message listener.- Parameters:
listener- the listener
-
removeMessageListener
public void removeMessageListener()Remove the message listener. -
messageReceived
Description copied from interface:MessageListenerReceive a message from the IO components in the Channel stack- Specified by:
messageReceivedin interfaceMessageListener- Parameters:
msg- the message
-
accept
Description copied from interface:MessageListenerAllows skipping processing of the specified message.- Specified by:
acceptin interfaceMessageListener- Parameters:
msg- the message- Returns:
trueif the message will be processed
-
broadcast
Description copied from interface:MembershipServiceBroadcasts a message to all members.- Specified by:
broadcastin interfaceMembershipService- Overrides:
broadcastin classMembershipServiceBase- Parameters:
message- The message to broadcast- Throws:
ChannelException- Message broadcast failed
-
getSoTimeout
public int getSoTimeout()Description copied from interface:McastServiceMBeanGet the socket timeout.- Specified by:
getSoTimeoutin interfaceMcastServiceMBean- Returns:
- the socket timeout
-
setSoTimeout
public void setSoTimeout(int mcastSoTimeout) Set the socket timeout.- Parameters:
mcastSoTimeout- the timeout in milliseconds
-
getTtl
public int getTtl()Description copied from interface:McastServiceMBeanGet the TTL.- Specified by:
getTtlin interfaceMcastServiceMBean- Returns:
- the TTL
-
getPayload
public byte[] getPayload()Get the payload.- Returns:
- the payload
-
getDomain
public byte[] getDomain()Description copied from interface:McastServiceMBeanGet the domain.- Specified by:
getDomainin interfaceMcastServiceMBean- Returns:
- the domain
-
setTtl
public void setTtl(int mcastTTL) Set the TTL.- Parameters:
mcastTTL- the TTL value
-
setPayload
public void setPayload(byte[] payload) Description copied from interface:MembershipServiceSet a payload to be broadcasted with each membership broadcast.- Specified by:
setPayloadin interfaceMembershipService- Parameters:
payload- byte[]
-
setDomain
public void setDomain(byte[] domain) Description copied from interface:MembershipServiceSet the associated domain.- Specified by:
setDomainin interfaceMembershipService- Parameters:
domain- the domain
-
setDomain
Set the domain from a string.- Parameters:
domain- the domain string
-
getMembershipProvider
Description copied from interface:MembershipServiceGet the MembershipProvider- Specified by:
getMembershipProviderin interfaceMembershipService- Returns:
- MembershipProvider
-
setDefaults
Set default property values.- Parameters:
properties- the properties
-
main
-