org.apache.catalina.tribes.membership

## Class Membership

- java.lang.Object
- - org.apache.catalina.tribes.membership.Membership

- All Implemented Interfaces:
    Cloneable

      public class Membership
      extends Object
      implements 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 and Description
    --- | ---
    `protected static class` | `Membership.MbrEntry` Inner class that represents a member entry

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static Member[]` | `EMPTY_MEMBERS`
    `protected Member` | `local` The local member.
    `protected HashMap<Member,Membership.MbrEntry>` | `map` A map of all the members in the cluster.
    `protected 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 and Description
    `Membership(Member local)`
    `Membership(Member local, boolean includeLocal)` Constructs a new membership
    `Membership(Member local, Comparator<Member> comp)`
    `Membership(Member local, Comparator<Member> comp, boolean includeLocal)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Membership.MbrEntry` | `addMember(Member member)` Add a member to this component and sort array with memberComparator
    `Membership` | `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.

    - ### 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

    - #### local

          protected final Member local

      The local member.

    - #### map

          protected 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 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)

    - #### Membership

          public Membership(Member local,
                    Comparator<Member> comp)

    - #### Membership

          public Membership(Member local,
                    Comparator<Member> comp,
                    boolean includeLocal)

  - ### Method Detail

    - #### clone

          public Membership clone()

      Overrides:
        `clone` in class `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, otherwise `false`

    - #### getMember

          public Member getMember(Member mbr)

    - #### 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

Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.