jgroup.relacs.types
Class ViewImpl

java.lang.Object
  extended by jgroup.relacs.types.ViewImpl
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, View

public class ViewImpl
extends java.lang.Object
implements View, java.io.Externalizable

This class implements the jgroup.core.View interface.

Since:
Jgroup 0.1
Author:
Alberto Montresor, Hein Meling
See Also:
Serialized Form

Constructor Summary
ViewImpl()
          Default constructor for externalization
ViewImpl(int gid)
          Creates a view that contains no members; this kind of view is used only to detect group failures (failure of a single last member).
ViewImpl(int gid, long vid, int mergingViews, MemberId[] members)
          Creates a view composed by a set of hosts and members; used to create new view after receiving view messages.
ViewImpl(int gid, long vid, MemberId me)
          Creates a view composed by a single member and a single host; used to initialize members joining to a group.
ViewImpl(View v)
          Clones a view.
 
Method Summary
 java.lang.Object clone()
           
 MemberId[] commonMembers(MemberId[] otherMembers)
          Returns an array of MemberIds that are common to this view and the provided member array.
 MemberId[] commonMembers(View view)
          Returns an array of MemberIds that are common to this view and the provided view.
 boolean contains(MemberId memberId)
          Returns true if the given member is contained in the current view.
 boolean containsAll(View view)
          Returns true if this view contains all members of the provided view.
 boolean equals(java.lang.Object obj)
          Compares two Views for content equality.
 int getGid()
          Returns the identifier of the group for which this view has been generated.
 MemberId getLeader()
          Return the MemberId of the group leader (member in position 0).
 int getMemberPosition(MemberId id)
          Returns the position of the given member in this view.
 MemberId[] getMembers()
          Returns an array of MemberIds identifying the members included in this view.
 long getVid()
          Returns the identifier of this view
 boolean hasSameMembers(View prevView)
          Returns true if this view has exactly the same members are the provided view.
 boolean isLeader(MemberId member)
          Returns true if the given member is the group leader.
 boolean memberHasPosition(int pos, MemberId member)
          Returns true if the specified member is the member at the given position; otherwise false is returned.
 int mergingViews()
          Returns the number of views (or partitions) merging into this view.
 MemberId[] newMembers(View previousView)
          Returns an array of MemberIds that are new to this view; that is they were not in the previous view.
 MemberId[] oldMembers(View previousView)
          Returns an array of MemberIds that are not longer part of this view; that is they were members of the previous view but are no longer members of the this view.
 void readExternal(java.io.ObjectInput in)
          Restores the content of this object from the marshalled data contained in the specified input stream.
 int size()
          Returns the number of members in this view.
 java.lang.String toString()
          Prints the content of this view.
 void writeExternal(java.io.ObjectOutput out)
          Marshals the content of this object to the specified output stream.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ViewImpl

public ViewImpl()
Default constructor for externalization


ViewImpl

public ViewImpl(int gid)
Creates a view that contains no members; this kind of view is used only to detect group failures (failure of a single last member).


ViewImpl

public ViewImpl(int gid,
                long vid,
                MemberId me)
Creates a view composed by a single member and a single host; used to initialize members joining to a group.


ViewImpl

public ViewImpl(int gid,
                long vid,
                int mergingViews,
                MemberId[] members)
Creates a view composed by a set of hosts and members; used to create new view after receiving view messages.

Parameters:
mergingViews - The number of views merging into this one.

ViewImpl

public ViewImpl(View v)
Clones a view.

Method Detail

getGid

public int getGid()
Returns the identifier of the group for which this view has been generated.

Specified by:
getGid in interface View

getVid

public long getVid()
Returns the identifier of this view

Specified by:
getVid in interface View

mergingViews

public int mergingViews()
Returns the number of views (or partitions) merging into this view.

Specified by:
mergingViews in interface View

getMembers

public MemberId[] getMembers()
Returns an array of MemberIds identifying the members included in this view.

Specified by:
getMembers in interface View

getLeader

public MemberId getLeader()
Description copied from interface: View
Return the MemberId of the group leader (member in position 0).

Specified by:
getLeader in interface View

isLeader

public boolean isLeader(MemberId member)
Description copied from interface: View
Returns true if the given member is the group leader.

Specified by:
isLeader in interface View

commonMembers

public MemberId[] commonMembers(MemberId[] otherMembers)
Description copied from interface: View
Returns an array of MemberIds that are common to this view and the provided member array.

Specified by:
commonMembers in interface View

commonMembers

public MemberId[] commonMembers(View view)
Description copied from interface: View
Returns an array of MemberIds that are common to this view and the provided view.

Specified by:
commonMembers in interface View

newMembers

public MemberId[] newMembers(View previousView)
Description copied from interface: View
Returns an array of MemberIds that are new to this view; that is they were not in the previous view.

Specified by:
newMembers in interface View

oldMembers

public MemberId[] oldMembers(View previousView)
Description copied from interface: View
Returns an array of MemberIds that are not longer part of this view; that is they were members of the previous view but are no longer members of the this view.

Specified by:
oldMembers in interface View

contains

public boolean contains(MemberId memberId)
Description copied from interface: View
Returns true if the given member is contained in the current view. Otherwise, false is returned.

Specified by:
contains in interface View

containsAll

public boolean containsAll(View view)
Description copied from interface: View
Returns true if this view contains all members of the provided view. False is returned otherwise.

This is useful for checking if a new view is a contraction of the previous view, or if there are new members.

Specified by:
containsAll in interface View

hasSameMembers

public boolean hasSameMembers(View prevView)
Description copied from interface: View
Returns true if this view has exactly the same members are the provided view. False is returned otherwise.

Note that this is different from using Object.equals(), since this method will not check that the view identifiers are the same.

Specified by:
hasSameMembers in interface View

size

public int size()
Returns the number of members in this view.

Specified by:
size in interface View

getMemberPosition

public int getMemberPosition(MemberId id)
Description copied from interface: View
Returns the position of the given member in this view. If the member is not in this view, a negative value is returned.

Specified by:
getMemberPosition in interface View

memberHasPosition

public boolean memberHasPosition(int pos,
                                 MemberId member)
Returns true if the specified member is the member at the given position; otherwise false is returned.

Specified by:
memberHasPosition in interface View
Parameters:
pos - The position in the view to check for equality with the given member. A negative position value is considered to indicate a position from the end of the view array, while a positive value indicate a position from the beginning of the view array. A position value outside the range of the view, will always return false.
member - The member whose position to check.
Returns:
True if the given member is at the specified position in this view; false otherwise.

equals

public boolean equals(java.lang.Object obj)
Compares two Views for content equality.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object to compare with
Returns:
true if these Objects are equal; false otherwise.

toString

public java.lang.String toString()
Prints the content of this view.

Overrides:
toString in class java.lang.Object

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Restores the content of this object from the marshalled data contained in the specified input stream.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - the stream to be read
Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Marshals the content of this object to the specified output stream.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - the stream to be written
Throws:
java.io.IOException

clone

public java.lang.Object clone()
Specified by:
clone in interface View
Overrides:
clone in class java.lang.Object


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