Package org.jgroups

Class View

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

public class View extends Object implements Comparable<View>, SizeStreamable, Iterable<Address>, Constructable<View>
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
  • Field Details

    • view_id

      protected ViewId view_id
      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 Address[] members
      An array containing all the members of the view. This array 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.
    • suppress_view_size

      protected static final boolean suppress_view_size
  • Constructor Details

    • View

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

      public View(ViewId view_id, Collection<Address> members)
      Creates a new view
      Parameters:
      view_id - 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(ViewId view_id, Address[] members)
      Creates a new view.
      Parameters:
      view_id - The new view-id
      members - The members. Note that the parameter is not copied.
    • View

      public View(Address creator, long id, 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 Details

    • create

      public static View create(Address coord, long id, Address... members)
    • create

      public static View create(Address coord, long id, Collection<Address> members)
    • create

      public Supplier<? extends View> create()
      Description copied from interface: Constructable
      Creates an instance of the class implementing this interface
      Specified by:
      create in interface Constructable<View>
    • getViewId

      public ViewId getViewId()
      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
    • 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
    • getCoord

      public Address getCoord()
    • getMembers

      public List<Address> getMembers()
      Returns the member list
      Returns:
      an immutable list of the members
    • getMembersRaw

      public Address[] getMembersRaw()
      Returns the underlying array. The caller must not modify the contents. Should not be used by application code ! This method may be removed at any time, so don't use it !
    • 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
    • containsMembers

      public boolean containsMembers(Address... mbrs)
      Returns true if all mbrs are elements of this view, false otherwise
    • compareTo

      public int compareTo(View o)
      Specified by:
      compareTo in interface Comparable<View>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • deepEquals

      public boolean deepEquals(View other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • size

      public int size()
      Returns the number of members in this view
      Returns:
      the number of members in this view 0..n
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • writeTo

      public void writeTo(DataOutput out) throws IOException
      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:
      IOException
    • readFrom

      public void readFrom(DataInput in) throws IOException, ClassNotFoundException
      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:
      IOException
      ClassNotFoundException
    • serializedSize

      public int serializedSize()
      Description copied from interface: SizeStreamable
      Returns the size (in bytes) of the marshalled object
      Specified by:
      serializedSize in interface SizeStreamable
    • leftMembers

      public static List<Address> leftMembers(View one, View two)
      Returns a list of members which left from view one to two
      Parameters:
      one -
      two -
    • newMembers

      public static List<Address> newMembers(View old, View new_view)
    • diff

      public static Address[][] diff(View from, View to)
      Returns the difference between 2 views from and to. It is assumed that view 'from' is logically prior to view 'to'.
      Parameters:
      from - The first view
      to - The second view
      Returns:
      an array of 2 Address arrays: index 0 has the addresses of the joined member, index 1 those of the left members
    • printDiff

      public static String printDiff(Address[][] diff)
    • sameViews

      public static boolean sameViews(View... views)
      Returns true if all views are the same. Uses the view IDs for comparison
    • sameViews

      public static boolean sameViews(Collection<View> views)
    • sameMembers

      public static boolean sameMembers(View v1, View v2)
      Checks if two views have the same members regardless of order. E.g. {A,B,C} and {B,A,C} returns true
    • sameMembersOrdered

      public static boolean sameMembersOrdered(View v1, View v2)
      Checks if two views have the same members observing order. E.g. {A,B,C} and {B,A,C} returns false, {A,C,B} and {A,C,B} returns true
    • iterator

      public Iterator<Address> iterator()
      Specified by:
      iterator in interface Iterable<Address>