org.jgroups
Class Membership

java.lang.Object
  extended by org.jgroups.Membership

public class Membership
extends java.lang.Object

Represents a membership of a cluster group. Class Membership is not exposed to clients and is used by JGroups internally. The membership object holds a list of Address objects that are in the same membership. Each unique address can only exist once.

Since:
2.0
Author:
Bela Ban

Constructor Summary
Membership()
          Creates a member ship object with zero members
Membership(java.util.Collection<Address> initial_members)
          Creates a Membership with a given initial members.
 
Method Summary
 void add(Address... mbrs)
           
 void add(Address new_member)
          Adds a new member to this membership.
 void add(java.util.Collection<Address> v)
          Adds a list of members to this membership
 void clear()
          Removes all the members from this membership
 boolean contains(Address member)
          Returns true if the provided member belongs to this membership
 Membership copy()
          Returns a copy of this membership
 Address elementAt(int index)
          Returns the component at the specified index
 java.util.List<Address> getMembers()
          Returns a copy (clone) of the members in this membership.
 void merge(java.util.Collection<Address> new_mems, java.util.Collection<Address> suspects)
          Merges membership with the new members and removes suspects.
 void remove(Address old_member)
          Removes an member from the membership.
 void remove(java.util.Collection<Address> v)
          Removes all the members contained in v from this membership
 void retainAll(java.util.Collection<Address> v)
           
 void set(java.util.Collection<Address> v)
          Clears the membership and adds all members of v This method will clear out all the old members of this membership by invoking the Clear method.
 void set(Membership m)
          Clears the membership and adds all members of a given membership parameter.
 int size()
          Returns the number of addresses in this membership
 void sort()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Membership

public Membership()
Creates a member ship object with zero members


Membership

public Membership(java.util.Collection<Address> initial_members)
Creates a Membership with a given initial members. The Address references are copied out of the vector, so that the vector passed in as parameters is not the same reference as the vector that the membership class is using

Parameters:
initial_members - - a list of members that belong to this membership
Method Detail

getMembers

public java.util.List<Address> getMembers()
Returns a copy (clone) of the members in this membership. The vector returned is immutable in reference to this object. ie, modifying the vector that is being returned in this method will not modify this membership object.

Returns:
a list of members

add

public void add(Address new_member)
Adds a new member to this membership. If the member already exist (Address.equals(Object) returns true then the member will not be added to the membership


add

public void add(Address... mbrs)

add

public final void add(java.util.Collection<Address> v)
Adds a list of members to this membership

Parameters:
v - - a vector containing Address objects
Throws:
java.lang.ClassCastException - if v contains objects that don't implement the Address interface

remove

public void remove(Address old_member)
Removes an member from the membership. If this member doesn't exist, no action will be performed on the existing membership

Parameters:
old_member - - the member to be removed

remove

public void remove(java.util.Collection<Address> v)
Removes all the members contained in v from this membership

Parameters:
v - a list of all the members to be removed

retainAll

public void retainAll(java.util.Collection<Address> v)

clear

public void clear()
Removes all the members from this membership


set

public void set(java.util.Collection<Address> v)
Clears the membership and adds all members of v This method will clear out all the old members of this membership by invoking the Clear method. Then it will add all the all members provided in the vector v

Parameters:
v - - a vector containing all the members this membership will contain

set

public void set(Membership m)
Clears the membership and adds all members of a given membership parameter. Prior to setting membership this method will clear out all the old members of this membership by invoking the clear method.

Parameters:
m - - a membership containing all the members this membership will contain

merge

public void merge(java.util.Collection<Address> new_mems,
                  java.util.Collection<Address> suspects)
Merges membership with the new members and removes suspects. The Merge method will remove all the suspects and add in the new members. It will do it in the order 1. Remove suspects 2. Add new members the order is very important to notice.

Parameters:
new_mems - - a vector containing a list of members (Address) to be added to this membership
suspects - - a vector containing a list of members (Address) to be removed from this membership

contains

public boolean contains(Address member)
Returns true if the provided member belongs to this membership

Parameters:
member -
Returns:
true if the member belongs to this membership

sort

public void sort()

copy

public Membership copy()
Returns a copy of this membership

Returns:
an exact copy of this membership

size

public int size()
Returns the number of addresses in this membership

Returns:
the number of addresses in this membership

elementAt

public Address elementAt(int index)
Returns the component at the specified index

Parameters:
index - - 0..size()-1
Throws:
java.lang.ArrayIndexOutOfBoundsException - - if the index is negative or not less than the current size of this Membership object.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 1998-2012 Bela Ban / Red Hat. All Rights Reserved.