jgroup
Class MemberTable

java.lang.Object
  |
  +--jgroup.MemberTable
All Implemented Interfaces:
Listener, MembershipListener

public class MemberTable
extends java.lang.Object
implements MembershipListener

This class is an helper utility that provides application developers with additional information about members of their current view. It can be used as an hash table, to associate application-dependent information to member identifier. It can be used to obtain information about the state of member identifier with respect to both the current view and previous installed views (for example, method getState may be used to discover which members survived from the previous view). The table maintains also information about the relative position of a member identifier in the member identifier array associated to the last installed view.

The table maintains information about a member until it crashes. A member is declared crashed when a member identifier from the same host, but with an higher incarnation identifier is inserted in the table. This means that the JVM hosting the member has crashed, and a new one has started. The state of crashed members is set to CRASHED. The information associated to the member is maintained until the next view change, after which the member identifier and all its associated information is removed from the table.

This class implements the MembershipListener interface, so it may be passed to the MembershipService to be notified whenever a view change occurs. Otherwise, the application developer may take care of updating the table by explicitly calling method viewChange.

Since:
Jgroup 0.9
Author:
Alberto Montresor

Inner Class Summary
private  class MemberTable.Record
          Data structure used to maintain an element in the hashtable and its status.
 
Field Summary
static int CRASHED
          State assigned to members that have been declared crashed because a member identifier from the same host but with a new incarnation number has been inserted in the table.
private  java.util.HashMap iptable
           
static int MERGING
          State assigned to members that merged the view after a previous partitioning
static int NEWMEMBER
          State assigned to new members
static int NOTMEMBER
          State assigned to member identifiers not included in the table
static int PARTITIONED
          State assigned to partitioned members for which no information is available.
static int RECOVERING
          State assigned to member identifiers whose incarnation number is greater than the incarnation number of other members previously contained in the table.
static int SURVIVED
          State assigned to members that survived from the previous view
private  java.util.HashMap table
           
 
Constructor Summary
MemberTable()
          Build a new empty MemberTable.
 
Method Summary
 java.lang.Object[] elements()
          Returns an array containing the values associated to all members contained in this MemberTable, including members crashed or partitioned.
 java.lang.Object get(MemberId id)
          Returns the value associated by this MemberTable to the specified member id.
 int getIndex(MemberId id)
          Returns the position of the specified member identifier in the last view for which method viewChange has been called; return -1 if the member is not member of that view.
 int getState(MemberId id)
          Returns the state associated to the member identifier.
 boolean isMember(MemberId id)
          Returns true if the specified member identifier is member of the last view for which method viewChange has been called; return false otherwise.
 void leaved()
          No effect.
 MemberId[] members()
          Returns an array containing the identifiers of all members contained in this MemberTable, including members crashed or partitioned.
 void prepareChange()
          No effect.
 void put(MemberId id, java.lang.Object value)
          Associates object value to the specified member identifier.
 void remove(MemberId id)
           
 void viewChange(View view)
          Update the information in the table with the information maintained in the new view.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

NOTMEMBER

public static final int NOTMEMBER
State assigned to member identifiers not included in the table

PARTITIONED

public static final int PARTITIONED
State assigned to partitioned members for which no information is available.

CRASHED

public static final int CRASHED
State assigned to members that have been declared crashed because a member identifier from the same host but with a new incarnation number has been inserted in the table.

RECOVERING

public static final int RECOVERING
State assigned to member identifiers whose incarnation number is greater than the incarnation number of other members previously contained in the table.

SURVIVED

public static final int SURVIVED
State assigned to members that survived from the previous view

MERGING

public static final int MERGING
State assigned to members that merged the view after a previous partitioning

NEWMEMBER

public static final int NEWMEMBER
State assigned to new members

table

private java.util.HashMap table

iptable

private java.util.HashMap iptable
Constructor Detail

MemberTable

public MemberTable()
Build a new empty MemberTable.
Method Detail

getState

public int getState(MemberId id)
Returns the state associated to the member identifier. The returned value is one of the integer constants defined in this class.

getIndex

public int getIndex(MemberId id)
Returns the position of the specified member identifier in the last view for which method viewChange has been called; return -1 if the member is not member of that view.

put

public void put(MemberId id,
                java.lang.Object value)
Associates object value to the specified member identifier. This association is maintained in the table until it is explicitly removed from the table, or the member is declared crashed. Values may be retrieved using method get.

get

public java.lang.Object get(MemberId id)
Returns the value associated by this MemberTable to the specified member id. Returns null if the map contains no mapping for this member id. A return value of null does not necessarily indicate that the map contains no mapping for the key; it is possible that the map explicitly maps the key to null.
Parameters:
id - the member identifier used as key
Returns:
the associated value

remove

public void remove(MemberId id)

elements

public java.lang.Object[] elements()
Returns an array containing the values associated to all members contained in this MemberTable, including members crashed or partitioned.

members

public MemberId[] members()
Returns an array containing the identifiers of all members contained in this MemberTable, including members crashed or partitioned.

isMember

public boolean isMember(MemberId id)
Returns true if the specified member identifier is member of the last view for which method viewChange has been called; return false otherwise.
Parameters:
id - the member whose membership is tested.

viewChange

public void viewChange(View view)
Update the information in the table with the information maintained in the new view.
Specified by:
viewChange in interface MembershipListener
Following copied from interface: jgroup.MembershipListener
Parameters:
view - the new view.
See Also:
MembershipService

leaved

public void leaved()
No effect.
Specified by:
leaved in interface MembershipListener
Following copied from interface: jgroup.MembershipListener
See Also:
MembershipService

prepareChange

public void prepareChange()
No effect.
Specified by:
prepareChange in interface MembershipListener
Following copied from interface: jgroup.MembershipListener
See Also:
MembershipService