Class McastService
java.lang.Object
org.apache.catalina.tribes.membership.McastService
- All Implemented Interfaces:
McastServiceMBean
,MembershipListener
,MembershipService
,MessageListener
public class McastService
extends Object
implements MembershipService, MembershipListener, 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
Modifier and TypeFieldDescriptionprotected byte[]
protected static final Member[]
Return all the membersprotected McastServiceImpl
A handle to the actual low level implementationprotected MembershipListener
A membership listener delegate (should be the cluster :)protected MemberImpl
The local memberprotected MessageListener
A message listener delegate for broadcastsprotected byte[]
protected Properties
The implementation specific propertiesprotected static final StringManager
The string manager for this package.Fields inherited from interface org.apache.catalina.tribes.MembershipService
MBR_RX, MBR_TX
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
accept
(ChannelMessage msg) void
broadcast
(ChannelMessage message) Broadcasts a message to all members.findMemberByName
(String name) Return the member by namegetBind()
Return the channel that is related to this MembershipServicebyte[]
long
long
boolean
getLocalMember
(boolean alive) Get the local member.Retrieve the specified member from the membership.Member[]
String[]
Return all the members by namebyte[]
int
getPort()
int
boolean
long
int
int
getTtl()
boolean
has members?protected void
hasProperty
(Properties properties, String name) Check if a required property is available.static void
Simple test programvoid
memberAdded
(Member member) A member was added to the groupvoid
memberDisappeared
(Member member) Callback from the impl when a new member has been receivedvoid
Receive a message from the IO components in the Channel stackvoid
Remove the membership listenervoid
void
setAddress
(String addr) void
void
setChannel
(Channel channel) Set the channel that is related to this MembershipServiceprotected void
setDefaults
(Properties properties) void
setDomain
(byte[] domain) void
void
setDropTime
(long time) void
setFrequency
(long time) void
setLocalLoopbackDisabled
(boolean localLoopbackDisabled) void
setLocalMemberProperties
(String listenHost, int listenPort, int securePort, int udpPort) Sets the local member properties for broadcasting.void
setMcastBindAddress
(String bindaddr) void
setMcastDropTime
(long time) void
setMembershipListener
(MembershipListener listener) Add a membership listener, this version only supports one listener per service, so calling this method twice will result in only the second listener being active.void
setMessageListener
(MessageListener listener) void
setPayload
(byte[] payload) Set a payload to be broadcasted with each membership broadcast.void
setPort
(int port) void
setProperties
(Properties properties) Sets the properties for the membership service.void
setRecoveryCounter
(int recoveryCounter) void
setRecoveryEnabled
(boolean recoveryEnabled) void
setRecoverySleepTime
(long recoverySleepTime) void
setSoTimeout
(int mcastSoTimeout) void
setTtl
(int mcastTTL) void
start()
Start broadcasting and listening to membership pingsvoid
start
(int level) Starts the membership service.void
stop
(int svc) Stop broadcasting and listening to membership pings
-
Field Details
-
sm
The string manager for this package. -
properties
The implementation specific properties -
impl
A handle to the actual low level implementation -
listener
A membership listener delegate (should be the cluster :) -
msglistener
A message listener delegate for broadcasts -
localMember
The local member -
payload
protected byte[] payload -
domain
protected byte[] domain -
EMPTY_MEMBERS
Return all the members
-
-
Constructor Details
-
McastService
public McastService()Create a membership service.
-
-
Method Details
-
setProperties
Sets the properties for the membership service.- Specified by:
setProperties
in interfaceMembershipService
- 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.
-
getProperties
- Specified by:
getProperties
in interfaceMcastServiceMBean
- Specified by:
getProperties
in interfaceMembershipService
- Returns:
- the properties for the configuration used.
-
getLocalMemberName
- Specified by:
getLocalMemberName
in interfaceMcastServiceMBean
- Returns:
- the local member name
-
getLocalMember
Description copied from interface:MembershipService
Get the local member.- Specified by:
getLocalMember
in interfaceMembershipService
- Parameters:
alive
-true
to 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:MembershipService
Sets the local member properties for broadcasting.- Specified by:
setLocalMemberProperties
in interfaceMembershipService
- Parameters:
listenHost
- Listen to hostlistenPort
- Listen to portsecurePort
- Use a secure portudpPort
- Use UDP
-
setAddress
-
getAddress
- Specified by:
getAddress
in interfaceMcastServiceMBean
-
setMcastBindAddress
-
setBind
-
getBind
- Specified by:
getBind
in interfaceMcastServiceMBean
-
setPort
public void setPort(int port) -
setRecoveryCounter
public void setRecoveryCounter(int recoveryCounter) -
getRecoveryCounter
public int getRecoveryCounter()- Specified by:
getRecoveryCounter
in interfaceMcastServiceMBean
-
setRecoveryEnabled
public void setRecoveryEnabled(boolean recoveryEnabled) -
getRecoveryEnabled
public boolean getRecoveryEnabled()- Specified by:
getRecoveryEnabled
in interfaceMcastServiceMBean
-
setRecoverySleepTime
public void setRecoverySleepTime(long recoverySleepTime) -
getRecoverySleepTime
public long getRecoverySleepTime()- Specified by:
getRecoverySleepTime
in interfaceMcastServiceMBean
-
setLocalLoopbackDisabled
public void setLocalLoopbackDisabled(boolean localLoopbackDisabled) -
getLocalLoopbackDisabled
public boolean getLocalLoopbackDisabled()- Specified by:
getLocalLoopbackDisabled
in interfaceMcastServiceMBean
-
getPort
public int getPort()- Specified by:
getPort
in interfaceMcastServiceMBean
-
setFrequency
public void setFrequency(long time) -
getFrequency
public long getFrequency()- Specified by:
getFrequency
in interfaceMcastServiceMBean
-
setMcastDropTime
public void setMcastDropTime(long time) -
setDropTime
public void setDropTime(long time) -
getDropTime
public long getDropTime()- Specified by:
getDropTime
in interfaceMcastServiceMBean
-
hasProperty
Check if a required property is available.- Parameters:
properties
- The set of propertiesname
- The property to check for
-
start
Start broadcasting and listening to membership pings- Specified by:
start
in interfaceMembershipService
- Throws:
Exception
- if a IO error occurs
-
start
Description copied from interface:MembershipService
Starts the membership service. If a membership listeners is added the listener will start to receive membership events.- Specified by:
start
in interfaceMembershipService
- Parameters:
level
- - level MBR_RX starts listening for members, level MBR_TX starts broad casting the server- Throws:
Exception
- if the service fails to start.IllegalArgumentException
- if the level is incorrect.
-
stop
public void stop(int svc) Stop broadcasting and listening to membership pings- Specified by:
stop
in interfaceMembershipService
- Parameters:
svc
- - level MBR_RX stops listening for members, level MBR_TX stops broad casting the server
-
getMembersByName
Return all the members by name- Specified by:
getMembersByName
in interfaceMcastServiceMBean
- Specified by:
getMembersByName
in interfaceMembershipService
- Returns:
- all members by name
-
findMemberByName
Return the member by name- Specified by:
findMemberByName
in interfaceMcastServiceMBean
- Specified by:
findMemberByName
in interfaceMembershipService
- Parameters:
name
- The member name- Returns:
- the member
-
hasMembers
public boolean hasMembers()has members?- Specified by:
hasMembers
in interfaceMcastServiceMBean
- Specified by:
hasMembers
in interfaceMembershipService
- Returns:
- true if the the group contains members
-
getMember
Description copied from interface:MembershipService
Retrieve the specified member from the membership.- Specified by:
getMember
in interfaceMembershipService
- Parameters:
mbr
- The member to retrieve- Returns:
- the member
-
getMembers
- Specified by:
getMembers
in interfaceMembershipService
- Returns:
- a list of all the members in the cluster.
-
setMembershipListener
Add a membership listener, this version only supports one listener per service, so calling this method twice will result in only the second listener being active.- Specified by:
setMembershipListener
in interfaceMembershipService
- Parameters:
listener
- The listener
-
setMessageListener
-
removeMessageListener
public void removeMessageListener() -
removeMembershipListener
public void removeMembershipListener()Remove the membership listener- Specified by:
removeMembershipListener
in interfaceMembershipService
-
memberAdded
Description copied from interface:MembershipListener
A member was added to the group- Specified by:
memberAdded
in interfaceMembershipListener
- Parameters:
member
- Member - the member that was added
-
memberDisappeared
Callback from the impl when a new member has been received- Specified by:
memberDisappeared
in interfaceMembershipListener
- Parameters:
member
- The member- See Also:
-
messageReceived
Description copied from interface:MessageListener
Receive a message from the IO components in the Channel stack- Specified by:
messageReceived
in interfaceMessageListener
- Parameters:
msg
- ChannelMessage
-
accept
- Specified by:
accept
in interfaceMessageListener
-
broadcast
Description copied from interface:MembershipService
Broadcasts a message to all members.- Specified by:
broadcast
in interfaceMembershipService
- Parameters:
message
- The message to broadcast- Throws:
ChannelException
- Message broadcast failed
-
getSoTimeout
public int getSoTimeout()- Specified by:
getSoTimeout
in interfaceMcastServiceMBean
-
setSoTimeout
public void setSoTimeout(int mcastSoTimeout) -
getTtl
public int getTtl()- Specified by:
getTtl
in interfaceMcastServiceMBean
-
getPayload
public byte[] getPayload() -
getDomain
public byte[] getDomain()- Specified by:
getDomain
in interfaceMcastServiceMBean
-
setTtl
public void setTtl(int mcastTTL) -
setPayload
public void setPayload(byte[] payload) Description copied from interface:MembershipService
Set a payload to be broadcasted with each membership broadcast.- Specified by:
setPayload
in interfaceMembershipService
- Parameters:
payload
- byte[]
-
setDomain
public void setDomain(byte[] domain) - Specified by:
setDomain
in interfaceMembershipService
-
setDomain
-
getChannel
Description copied from interface:MembershipService
Return the channel that is related to this MembershipService- Specified by:
getChannel
in interfaceMembershipService
- Returns:
- Channel
-
setChannel
Description copied from interface:MembershipService
Set the channel that is related to this MembershipService- Specified by:
setChannel
in interfaceMembershipService
- Parameters:
channel
- The channel
-
setDefaults
-
main
Simple test program- Parameters:
args
- Command-line arguments- Throws:
Exception
- If an error occurs
-