Package org.jgroups
Class View
java.lang.Object
org.jgroups.View
- All Implemented Interfaces:
Comparable<View>,Iterable<Address>,Constructable<View>,SizeStreamable,Streamable
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionView()Creates an empty view, should not be used, only used by (de-)serializationCreates a new viewView(ViewId view_id, Collection<Address> members) Creates a new viewCreates a new view. -
Method Summary
Modifier and TypeMethodDescriptionintbooleancontainsMember(Address mbr) Returns true if this view contains a certain memberbooleancontainsMembers(Address... mbrs) Returns true if all mbrs are elements of this view, false otherwisecreate()Creates an instance of the class implementing this interfacestatic Viewcreate(Address coord, long id, Collection<Address> members) static ViewbooleandeepEquals(View other) static Address[][]Returns the difference between 2 views from and to.booleangetCoord()Returns the creator of this view if this view was created with the empty constructur, null will be returnedReturns the member listAddress[]Returns the underlying array.Returns the view ID of this view if this view was created with the empty constructur, null will be returnedinthashCode()iterator()leftMembers(View one, View two) Returns a list of members which left from view one to twonewMembers(View old, View new_view) static StringvoidRead the state of the current object (including superclasses) from instream Note that the input stream must not be closedstatic booleansameMembers(View v1, View v2) Checks if two views have the same members regardless of order.static booleansameMembersOrdered(View v1, View v2) Checks if two views have the same members observing order.static booleansameViews(Collection<View> views) static booleanReturns true if all views are the same.intReturns the size (in bytes) of the marshalled objectintsize()Returns the number of members in this viewtoString()voidwriteTo(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, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
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
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
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
Creates a new view.- Parameters:
view_id- The new view-idmembers- The members. Note that the parameter is not copied.
-
View
Creates a new view- Parameters:
creator- The creator of this view (can not be null)id- The lamport timestamp of this viewmembers- Contains a list of all the members in the view, can be empty but not null.
-
-
Method Details
-
create
-
create
-
create
Description copied from interface:ConstructableCreates an instance of the class implementing this interface- Specified by:
createin interfaceConstructable<View>
-
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
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
-
getMembers
Returns the member list- Returns:
- an immutable list of the members
-
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
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
Returns true if all mbrs are elements of this view, false otherwise -
compareTo
- Specified by:
compareToin interfaceComparable<View>
-
equals
-
deepEquals
-
hashCode
public int hashCode() -
size
public int size()Returns the number of members in this view- Returns:
- the number of members in this view 0..n
-
toString
-
writeTo
Description copied from interface:StreamableWrite the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed- Specified by:
writeToin interfaceStreamable- Throws:
IOException
-
readFrom
Description copied from interface:StreamableRead the state of the current object (including superclasses) from instream Note that the input stream must not be closed- Specified by:
readFromin interfaceStreamable- Throws:
IOExceptionClassNotFoundException
-
serializedSize
public int serializedSize()Description copied from interface:SizeStreamableReturns the size (in bytes) of the marshalled object- Specified by:
serializedSizein interfaceSizeStreamable
-
leftMembers
Returns a list of members which left from view one to two- Parameters:
one-two-
-
newMembers
-
diff
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
-
sameViews
Returns true if all views are the same. Uses the view IDs for comparison -
sameViews
-
sameMembers
Checks if two views have the same members regardless of order. E.g. {A,B,C} and {B,A,C} returns true -
sameMembersOrdered
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
-