Package org.jgroups
Class View
- java.lang.Object
-
- org.jgroups.View
-
- All Implemented Interfaces:
java.lang.Comparable<View>
,java.lang.Iterable<Address>
,Constructable<View>
,SizeStreamable
,Streamable
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-)serializationView(Address creator, long id, java.util.List<Address> members)
Creates a new viewView(ViewId view_id, java.util.Collection<Address> members)
Creates a new viewView(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 memberboolean
containsMembers(Address... mbrs)
Returns true if all mbrs are elements of this view, false otherwisejava.util.function.Supplier<? extends View>
create()
Creates an instance of the class implementing this interfacestatic 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 returnedjava.util.List<Address>
getMembers()
Returns the member listAddress[]
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 returnedint
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 twostatic 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 closedstatic 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 objectint
size()
Returns the number of members in this viewjava.lang.String
toString()
void
writeTo(java.io.DataOutput out)
Write the entire state of the current object (including superclasses) to outstream.
-
-
-
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-idmembers
- The members. Note that the parameter is not copied.
-
-
Method Detail
-
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 interfaceConstructable<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 interfacejava.lang.Comparable<View>
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
deepEquals
public boolean deepEquals(View other)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.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 classjava.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 interfaceStreamable
- 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 interfaceStreamable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
serializedSize
public int serializedSize()
Description copied from interface:SizeStreamable
Returns the size (in bytes) of the marshalled object- Specified by:
serializedSize
in interfaceSizeStreamable
-
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
-
-
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 viewto
- 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
-
-