jgroup.core
Class MemberTable

java.lang.Object
  extended by jgroup.core.MemberTable
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, MembershipListener

public class MemberTable
extends java.lang.Object
implements MembershipListener, java.io.Externalizable

This class is an helper utility that provides application developers with additional information about members of their current view. It can be used as a hash table, to associate application-dependent information to member identifier. Furthermore, it can be used to obtain information about the state of a member identifier with respect to both the current view and previous installed views (for example, method getStatus may be used to discover which members survived from the previous view). The table also maintains 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 endpoint, 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, Hein Meling
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface jgroup.core.MembershipListener
MembershipListener.AllowDuplicateViews
 
Field Summary
static int CRASHED
          State assigned to members that have been declared crashed because a member identifier from the same endpoint but with a new incarnation number has been inserted in the table.
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
 
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 getStatus(MemberId id)
          Returns the status associated with this member identifier.
 void hasLeft()
          No effect.
 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.
 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 readExternal(java.io.ObjectInput in)
           
 void remove(MemberId id)
           
 java.lang.String toString()
           
 java.lang.String toString(MemberId id)
           
 void viewChange(View view)
          Update the information in the table with the information maintained in the new view.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NOTMEMBER

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

See Also:
Constant Field Values

PARTITIONED

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

See Also:
Constant Field Values

CRASHED

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

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

SURVIVED

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

See Also:
Constant Field Values

MERGING

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

See Also:
Constant Field Values

NEWMEMBER

public static final int NEWMEMBER
State assigned to new members

See Also:
Constant Field Values
Constructor Detail

MemberTable

public MemberTable()
Build a new empty MemberTable. Also used as the default constructor for externalization.

Method Detail

getStatus

public int getStatus(MemberId id)
Returns the status associated with this 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.

Parameters:
id - The member identifer to which the value should be associated.
value - The value to associate with the given member.
Throws:
java.lang.IllegalArgumentException - If the specified member identifier does not exist within this member table.

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, or null if no such member exists within this MemberTable.

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. The array is sorted according to the member index in the most recent view; the crashed and partitioned members are placed at the end of the array with no particular order.


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 to be tested.

toString

public java.lang.String toString(MemberId id)

toString

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

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
Parameters:
view - The new view that has been installed.
See Also:
MembershipService

hasLeft

public void hasLeft()
No effect.

Specified by:
hasLeft in interface MembershipListener
See Also:
MembershipService

prepareChange

public void prepareChange()
No effect.

Specified by:
prepareChange in interface MembershipListener
See Also:
MembershipService

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright © 1998-2006 The Jgroup/ARM development team. All Rights Reserved.