Package org.jgroups

Class View

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

    public class View
    extends java.lang.Object
    implements java.lang.Comparable<View>, SizeStreamable, java.lang.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
    Author:
    Bela Ban
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Address[] members
      An array containing all the members of the view.
      protected static boolean suppress_view_size  
      protected ViewId view_id
      A view is uniquely identified by its ViewID.
    • Constructor Summary

      Constructors 
      Constructor Description
      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 view_id, java.util.Collection<Address> members)
      Creates a new view
      View​(ViewId view_id, Address[] members)
      Creates a new view.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(View o)  
      boolean containsMember​(Address mbr)
      Returns true if this view contains a certain member
      boolean containsMembers​(Address... mbrs)
      Returns true if all mbrs are elements of this view, false otherwise
      java.util.function.Supplier<? extends View> create()
      Creates an instance of the class implementing this interface
      static View create​(Address coord, long id, java.util.Collection<Address> members)  
      static View create​(Address coord, long id, Address... members)  
      boolean deepEquals​(View other)  
      static Address[][] diff​(View from, View to)
      Returns the difference between 2 views from and to.
      boolean equals​(java.lang.Object obj)  
      Address getCoord()  
      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 the member list
      Address[] getMembersRaw()
      Returns the underlying array.
      ViewId getViewId()
      Returns the view ID of this view if this view was created with the empty constructur, null will be returned
      int hashCode()  
      java.util.Iterator<Address> iterator()  
      static java.util.List<Address> leftMembers​(View one, View two)
      Returns a list of members which left from view one to two
      static java.util.List<Address> newMembers​(View old, View new_view)  
      static java.lang.String printDiff​(Address[][] diff)  
      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
      static boolean sameMembers​(View v1, View v2)
      Checks if two views have the same members regardless of order.
      static boolean sameMembersOrdered​(View v1, View v2)
      Checks if two views have the same members observing order.
      static boolean sameViews​(java.util.Collection<View> views)  
      static boolean sameViews​(View... views)
      Returns true if all views are the same.
      int serializedSize()
      Returns the size (in bytes) of the marshalled object
      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
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • 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 Detail

      • View

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

        public View​(ViewId view_id,
                    java.util.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,
                    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

      • create

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

        public java.util.function.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 java.util.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 java.lang.Comparable<View>
      • equals

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

        public boolean deepEquals​(View other)
      • 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
      • toString

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

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

        public void readFrom​(java.io.DataInput in)
                      throws java.io.IOException,
                             java.lang.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:
        java.io.IOException
        java.lang.ClassNotFoundException
      • leftMembers

        public static java.util.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 java.util.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 java.lang.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​(java.util.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 java.util.Iterator<Address> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<Address>