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
Fields Modifier and Type Field Description protected byte[]domainThe domain for multicast messages.protected McastServiceImplimplA handle to the actual low level implementationprotected MemberImpllocalMemberThe local memberprotected MessageListenermsglistenerA message listener delegate for broadcastsprotected byte[]payloadThe payload for multicast messages.protected static StringManagersmThe string manager for this package.-
Fields inherited from class org.apache.catalina.tribes.membership.MembershipServiceBase
channel, listener, properties
-
Fields inherited from interface org.apache.catalina.tribes.MembershipService
MBR_RX, MBR_TX
-
-
Constructor Summary
Constructors Constructor Description McastService()Create a membership service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccept(ChannelMessage msg)Allows skipping processing of the specified message.voidbroadcast(ChannelMessage message)Broadcasts a message to all members.java.lang.StringgetAddress()Get the multicast address.java.lang.StringgetBind()Get the bind address.byte[]getDomain()Get the domain.longgetDropTime()Get the drop time.longgetFrequency()Get the heartbeat frequency.booleangetLocalLoopbackDisabled()Get whether local loopback is disabled.MembergetLocalMember(boolean alive)Get the local member.java.lang.StringgetLocalMemberName()Get the local member name.MembershipProvidergetMembershipProvider()Get the MembershipProviderbyte[]getPayload()Get the payload.intgetPort()Get the multicast port.intgetRecoveryCounter()Get the recovery counter.booleangetRecoveryEnabled()Get whether recovery is enabled.longgetRecoverySleepTime()Get the recovery sleep time.intgetSoTimeout()Get the socket timeout.intgetTtl()Get the TTL.protected voidhasProperty(java.util.Properties properties, java.lang.String name)Check if a required property is available.static voidmain(java.lang.String[] args)Simple test programvoidmessageReceived(ChannelMessage msg)Receive a message from the IO components in the Channel stackvoidremoveMessageListener()Remove the message listener.voidsetAddress(java.lang.String addr)Set the multicast address.voidsetBind(java.lang.String bindaddr)Set the bind address.protected voidsetDefaults(java.util.Properties properties)Set default property values.voidsetDomain(byte[] domain)Set the associated domain.voidsetDomain(java.lang.String domain)Set 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(java.lang.String listenHost, int listenPort, int securePort, int udpPort)Sets the local member properties for broadcasting.voidsetMcastBindAddress(java.lang.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(java.util.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 pings-
Methods inherited from class org.apache.catalina.tribes.membership.MembershipServiceBase
findMemberByName, getChannel, getMember, getMembers, getMembersByName, getProperties, hasMembers, memberAdded, memberDisappeared, removeMembershipListener, setChannel, setMembershipListener, start
-
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.membership.McastServiceMBean
findMemberByName, getMembersByName, getProperties, hasMembers
-
-
-
-
Field Detail
-
sm
protected static final StringManager sm
The string manager for this package.
-
impl
protected McastServiceImpl impl
A handle to the actual low level implementation
-
msglistener
protected MessageListener msglistener
A message listener delegate for broadcasts
-
localMember
protected MemberImpl localMember
The local member
-
payload
protected byte[] payload
The payload for multicast messages.
-
domain
protected byte[] domain
The domain for multicast messages.
-
-
Method Detail
-
setProperties
public void setProperties(java.util.Properties properties)
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:
java.lang.IllegalArgumentException- if a property is missing.
-
getLocalMemberName
public java.lang.String getLocalMemberName()
Description copied from interface:McastServiceMBeanGet the local member name.- Specified by:
getLocalMemberNamein interfaceMcastServiceMBean- Returns:
- the local member name
-
getLocalMember
public Member getLocalMember(boolean alive)
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(java.lang.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
public void setAddress(java.lang.String addr)
Set the multicast address.- Parameters:
addr- the address
-
getAddress
public java.lang.String getAddress()
Description copied from interface:McastServiceMBeanGet the multicast address.- Specified by:
getAddressin interfaceMcastServiceMBean- Returns:
- the address
-
setMcastBindAddress
public void setMcastBindAddress(java.lang.String bindaddr)
Set the multicast bind address.- Parameters:
bindaddr- the bind address
-
setBind
public void setBind(java.lang.String bindaddr)
Set the bind address.- Parameters:
bindaddr- the bind address
-
getBind
public java.lang.String 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
protected void hasProperty(java.util.Properties properties, java.lang.String name)Check if a required property is available.- Parameters:
properties- The set of propertiesname- The property to check for
-
start
public void start(int level) throws java.lang.ExceptionDescription 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:
java.lang.Exception- if the service fails to start.java.lang.IllegalArgumentException- if the level is incorrect.
-
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
public void setMessageListener(MessageListener listener)
Set the message listener.- Parameters:
listener- the listener
-
removeMessageListener
public void removeMessageListener()
Remove the message listener.
-
messageReceived
public void messageReceived(ChannelMessage msg)
Description copied from interface:MessageListenerReceive a message from the IO components in the Channel stack- Specified by:
messageReceivedin interfaceMessageListener- Parameters:
msg- the message
-
accept
public boolean accept(ChannelMessage msg)
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
public void broadcast(ChannelMessage message) throws ChannelException
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
public void setDomain(java.lang.String domain)
Set the domain from a string.- Parameters:
domain- the domain string
-
getMembershipProvider
public MembershipProvider getMembershipProvider()
Description copied from interface:MembershipServiceGet the MembershipProvider- Specified by:
getMembershipProviderin interfaceMembershipService- Returns:
- MembershipProvider
-
setDefaults
protected void setDefaults(java.util.Properties properties)
Set default property values.- Parameters:
properties- the properties
-
main
public static void main(java.lang.String[] args) throws java.lang.ExceptionSimple test program- Parameters:
args- Command-line arguments- Throws:
java.lang.Exception- If an error occurs
-
-