org.jgroups
Class View

java.lang.Object
  extended by org.jgroups.View
All Implemented Interfaces:
java.lang.Comparable<View>, java.lang.Iterable<Address>, Streamable
Direct Known Subclasses:
MergeView

public class View
extends java.lang.Object
implements java.lang.Comparable<View>, Streamable, java.lang.Iterable<Address>

A view is a local representation of the current membership of a group. Only one view is installed in a channel at a time. Views contain the address of its creator, an ID and a list of member addresses. These addresses are ordered, and the first address is always the coordinator of the view. This way, each member of the group knows who the new coordinator will be if the current one crashes or leaves the group. The views are sent between members using the VIEW_CHANGE event

Since:
2.0
Author:
Bela Ban

Field Summary
protected  java.util.List<Address> members
          A list containing all the members of the view.This list is always ordered, with the coordinator being the first member.
protected  ViewId vid
          A view is uniquely identified by its ViewID.
 
Constructor Summary
View()
          Creates an empty view, should not be used, only used by (de-)serialization
View(Address creator, long id, java.util.List<Address> members)
          Creates a new view
View(ViewId vid, java.util.List<Address> members)
          Creates a new view
 
Method Summary
 int compareTo(View o)
           
 boolean containsMember(Address mbr)
          Returns true, if this view contains a certain member
 View copy()
           
 boolean equals(java.lang.Object obj)
           
 Address getCreator()
          Returns the creator of this view if this view was created with the empty constructur, null will be returned
 java.util.List<Address> getMembers()
          Returns a reference to the List of members (ordered) Do NOT change this list, hence your will invalidate the view Make a copy if you have to modify it.
 ViewId getVid()
          Returns the view ID of this view if this view was created with the empty constructur, null will be returned
 ViewId getViewId()
           
 int hashCode()
           
 java.util.Iterator<Address> iterator()
           
 void readFrom(java.io.DataInput in)
          Read the state of the current object (including superclasses) from instream Note that the input stream must not be closed
 int serializedSize()
           
 int size()
          Returns the number of members in this view
 java.lang.String toString()
           
 void writeTo(java.io.DataOutput out)
          Write the entire state of the current object (including superclasses) to outstream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

vid

protected ViewId vid
A view is uniquely identified by its ViewID. The view id contains the creator address and a Lamport time. The Lamport time is the highest timestamp seen or sent from a view. if a view change comes in with a lower Lamport time, the event is discarded.


members

protected java.util.List<Address> members
A list containing all the members of the view.This list is always ordered, with the coordinator being the first member. the second member will be the new coordinator if the current one disappears or leaves the group.

Constructor Detail

View

public View()
Creates an empty view, should not be used, only used by (de-)serialization


View

public View(ViewId vid,
            java.util.List<Address> members)
Creates a new view

Parameters:
vid - The view id of this view (can not be null)
members - Contains a list of all the members in the view, can be empty but not null.

View

public View(Address creator,
            long id,
            java.util.List<Address> members)
Creates a new view

Parameters:
creator - The creator of this view (can not be null)
id - The lamport timestamp of this view
members - Contains a list of all the members in the view, can be empty but not null.
Method Detail

getVid

public ViewId getVid()
Returns the view ID of this view if this view was created with the empty constructur, null will be returned

Returns:
the view ID of this view

getViewId

public ViewId getViewId()

getCreator

public Address getCreator()
Returns the creator of this view if this view was created with the empty constructur, null will be returned

Returns:
the creator of this view in form of an Address object

getMembers

public java.util.List<Address> getMembers()
Returns a reference to the List of members (ordered) Do NOT change this list, hence your will invalidate the view Make a copy if you have to modify it.

Returns:
a reference to the ordered list of members in this view

containsMember

public boolean containsMember(Address mbr)
Returns true, if this view contains a certain member

Parameters:
mbr - - the address of the member,
Returns:
true if this view contains the member, false if it doesn't if the argument mbr is null, this operation returns false

compareTo

public int compareTo(View o)
Specified by:
compareTo in interface java.lang.Comparable<View>

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

size

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

Returns:
the number of members in this view 0..n

copy

public View copy()

toString

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

writeTo

public void writeTo(java.io.DataOutput out)
             throws java.lang.Exception
Description copied from interface: Streamable
Write the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed

Specified by:
writeTo in interface Streamable
Throws:
java.lang.Exception

readFrom

public void readFrom(java.io.DataInput in)
              throws java.lang.Exception
Description copied from interface: Streamable
Read the state of the current object (including superclasses) from instream Note that the input stream must not be closed

Specified by:
readFrom in interface Streamable
Throws:
java.lang.Exception

serializedSize

public int serializedSize()

iterator

public java.util.Iterator<Address> iterator()
Specified by:
iterator in interface java.lang.Iterable<Address>


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