Class Membership
- java.lang.Object
-
- org.apache.catalina.tribes.membership.Membership
-
- All Implemented Interfaces:
java.lang.Cloneable
public class Membership extends java.lang.Object implements java.lang.Cloneable
A membership implementation using simple multicast. This is the representation of a multicast membership. 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.- Author:
- Peter Rossbach
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Membership.MbrEntry
Inner class that represents a member entry
-
Field Summary
Fields Modifier and Type Field Description protected static Member[]
EMPTY_MEMBERS
protected Member
local
The local member.protected java.util.HashMap<Member,Membership.MbrEntry>
map
A map of all the members in the cluster.protected java.util.Comparator<Member>
memberComparator
Comparator for sorting members by alive time.protected Member[]
members
A list of all the members in the cluster.
-
Constructor Summary
Constructors Constructor Description Membership(Member local)
Membership(Member local, boolean includeLocal)
Constructs a new membershipMembership(Member local, java.util.Comparator<Member> comp)
Membership(Member local, java.util.Comparator<Member> comp, boolean includeLocal)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Membership.MbrEntry
addMember(Member member)
Add a member to this component and sort array with memberComparatorMembership
clone()
boolean
contains(Member mbr)
Member[]
expire(long maxtime)
Runs a refresh cycle and returns a list of members that has expired.Member
getMember(Member mbr)
Member[]
getMembers()
Returning a list of all the members in the membership.boolean
hasMembers()
Returning that service has members or not.boolean
memberAlive(Member member)
Notify the membership that this member has announced itself.void
removeMember(Member member)
Remove a member from this component.void
reset()
Reset the membership and start over fresh. i.e., delete all the members and wait for them to ping again and join this membership.
-
-
-
Field Detail
-
EMPTY_MEMBERS
protected static final Member[] EMPTY_MEMBERS
-
local
protected final Member local
The local member.
-
map
protected java.util.HashMap<Member,Membership.MbrEntry> map
A map of all the members in the cluster.
-
members
protected volatile Member[] members
A list of all the members in the cluster.
-
memberComparator
protected final java.util.Comparator<Member> memberComparator
Comparator for sorting members by alive time.
-
-
Method Detail
-
clone
public Membership clone()
- Overrides:
clone
in classjava.lang.Object
-
reset
public void reset()
Reset the membership and start over fresh. i.e., delete all the members and wait for them to ping again and join this membership.
-
memberAlive
public boolean memberAlive(Member member)
Notify the membership that this member has announced itself.- Parameters:
member
- - the member that just pinged us- Returns:
- - true if this member is new to the cluster, false otherwise.
- false if this member is the local member or updated.
-
addMember
public Membership.MbrEntry addMember(Member member)
Add a member to this component and sort array with memberComparator- Parameters:
member
- The member to add- Returns:
- The member entry created for this new member.
-
removeMember
public void removeMember(Member member)
Remove a member from this component.- Parameters:
member
- The member to remove
-
expire
public Member[] expire(long maxtime)
Runs a refresh cycle and returns a list of members that has expired. This also removes the members from the membership, in such a way that getMembers() = getMembers() - expire()- Parameters:
maxtime
- - the max time a member can remain unannounced before it is considered dead.- Returns:
- the list of expired members
-
hasMembers
public boolean hasMembers()
Returning that service has members or not.- Returns:
true
if there are one or more members, otherwisefalse
-
contains
public boolean contains(Member mbr)
-
getMembers
public Member[] getMembers()
Returning a list of all the members in the membership. We not need a copy: add and remove generate new arrays.- Returns:
- An array of the current members
-
-