Class 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.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Membership.MbrEntry
      Entry for a member in the membership.
    • Constructor Summary

      Constructors 
      Constructor Description
      Membership​(Member local)
      Constructs a new membership.
      Membership​(Member local, boolean includeLocal)
      Constructs a new membership
      Membership​(Member local, java.util.Comparator<Member> comp)
      Constructs a new membership.
      Membership​(Member local, java.util.Comparator<Member> comp, boolean includeLocal)
      Constructs a new membership.
    • 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 memberComparator
      Membership clone()  
      boolean contains​(Member mbr)
      Check if the membership contains a member.
      Member[] expire​(long maxtime)
      Runs a refresh cycle and returns a list of members that has expired.
      Member getMember​(Member mbr)
      Get a member by reference.
      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.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY_MEMBERS

        protected static final Member[] EMPTY_MEMBERS
        Empty member array.
      • local

        protected final Member local
        The local member.
      • 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.
    • Constructor Detail

      • Membership

        public Membership​(Member local,
                          boolean includeLocal)
        Constructs a new membership
        Parameters:
        local - - has to be the name of the local member. Used to filter the local member from the cluster membership
        includeLocal - - TBA
      • Membership

        public Membership​(Member local)
        Constructs a new membership.
        Parameters:
        local - the local member
      • Membership

        public Membership​(Member local,
                          java.util.Comparator<Member> comp)
        Constructs a new membership.
        Parameters:
        local - the local member
        comp - the comparator
      • Membership

        public Membership​(Member local,
                          java.util.Comparator<Member> comp,
                          boolean includeLocal)
        Constructs a new membership.
        Parameters:
        local - the local member
        comp - the comparator
        includeLocal - whether to include the local member
    • Method Detail

      • clone

        public Membership clone()
        Overrides:
        clone in class java.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 array of expired members
      • hasMembers

        public boolean hasMembers()
        Returning that service has members or not.
        Returns:
        true if there are one or more members, otherwise false
      • getMember

        public Member getMember​(Member mbr)
        Get a member by reference.
        Parameters:
        mbr - the member reference
        Returns:
        the member or null if not found
      • contains

        public boolean contains​(Member mbr)
        Check if the membership contains a member.
        Parameters:
        mbr - the member
        Returns:
        true if the member is present
      • 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