Class MembershipServiceBase
- java.lang.Object
-
- org.apache.catalina.tribes.membership.MembershipServiceBase
-
- All Implemented Interfaces:
MembershipListener
,MembershipService
- Direct Known Subclasses:
CloudMembershipService
,McastService
,StaticMembershipService
public abstract class MembershipServiceBase extends java.lang.Object implements MembershipService, MembershipListener
-
-
Field Summary
Fields Modifier and Type Field Description protected Channel
channel
protected MembershipListener
listener
protected java.util.Properties
properties
The implementation specific properties-
Fields inherited from interface org.apache.catalina.tribes.MembershipService
MBR_RX, MBR_TX
-
-
Constructor Summary
Constructors Constructor Description MembershipServiceBase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
broadcast(ChannelMessage message)
Broadcasts a message to all members.Member
findMemberByName(java.lang.String name)
Get a member.Channel
getChannel()
Return the channel that is related to this MembershipServiceMember
getMember(Member mbr)
Retrieve the specified member from the membership.Member[]
getMembers()
java.lang.String[]
getMembersByName()
java.util.Properties
getProperties()
boolean
hasMembers()
void
memberAdded(Member member)
A member was added to the groupvoid
memberDisappeared(Member member)
A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD datavoid
removeMembershipListener()
Removes the membership listener.void
setChannel(Channel channel)
Set the channel that is related to this MembershipServicevoid
setMembershipListener(MembershipListener listener)
Sets the membership listener, only one listener can be added.void
setProperties(java.util.Properties properties)
Sets the properties for the membership service.void
start()
Starts the membership service.-
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.MembershipService
getLocalMember, getMembershipProvider, setDomain, setLocalMemberProperties, setPayload, start, stop
-
-
-
-
Field Detail
-
properties
protected java.util.Properties properties
The implementation specific properties
-
listener
protected volatile MembershipListener listener
-
channel
protected Channel channel
-
-
Method Detail
-
setProperties
public void setProperties(java.util.Properties properties)
Sets the properties for the membership service. This must be called before thestart()
method is called. The properties are implementation specific.- Specified by:
setProperties
in interfaceMembershipService
- Parameters:
properties
- - to be used to configure the membership service.
-
getProperties
public java.util.Properties getProperties()
- Specified by:
getProperties
in interfaceMembershipService
- Returns:
- the properties for the configuration used.
-
hasMembers
public boolean hasMembers()
- Specified by:
hasMembers
in interfaceMembershipService
- Returns:
- true if the the group contains members
-
getMember
public Member getMember(Member mbr)
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
public Member[] getMembers()
- Specified by:
getMembers
in interfaceMembershipService
- Returns:
- a list of all the members in the cluster.
-
getMembersByName
public java.lang.String[] getMembersByName()
- Specified by:
getMembersByName
in interfaceMembershipService
- Returns:
- all members by name
-
findMemberByName
public Member findMemberByName(java.lang.String name)
Description copied from interface:MembershipService
Get a member.- Specified by:
findMemberByName
in interfaceMembershipService
- Parameters:
name
- The member name- Returns:
- the member
-
setMembershipListener
public void setMembershipListener(MembershipListener listener)
Description copied from interface:MembershipService
Sets the membership listener, only one listener can be added. If you call this method twice, the last listener will be used.- Specified by:
setMembershipListener
in interfaceMembershipService
- Parameters:
listener
- The listener
-
removeMembershipListener
public void removeMembershipListener()
Description copied from interface:MembershipService
Removes the membership listener.- Specified by:
removeMembershipListener
in interfaceMembershipService
-
memberAdded
public void memberAdded(Member member)
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
public void memberDisappeared(Member member)
Description copied from interface:MembershipListener
A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data- Specified by:
memberDisappeared
in interfaceMembershipListener
- Parameters:
member
- Member- See Also:
Member.SHUTDOWN_PAYLOAD
-
broadcast
public void broadcast(ChannelMessage message) throws ChannelException
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
-
getChannel
public Channel getChannel()
Description copied from interface:MembershipService
Return the channel that is related to this MembershipService- Specified by:
getChannel
in interfaceMembershipService
- Returns:
- Channel
-
setChannel
public void setChannel(Channel channel)
Description copied from interface:MembershipService
Set the channel that is related to this MembershipService- Specified by:
setChannel
in interfaceMembershipService
- Parameters:
channel
- The channel
-
start
public void start() throws java.lang.Exception
Description copied from interface:MembershipService
Starts the membership service. If a membership listeners is added the listener will start to receive membership events. Performs a start level 1 and 2- Specified by:
start
in interfaceMembershipService
- Throws:
java.lang.Exception
- if the service fails to start.
-
-