Package org.jgroups.util
Class Digest
- java.lang.Object
-
- org.jgroups.util.Digest
-
- All Implemented Interfaces:
java.lang.Iterable<Digest.Entry>
,Constructable<Digest>
,SizeStreamable
,Streamable
- Direct Known Subclasses:
MutableDigest
public class Digest extends java.lang.Object implements SizeStreamable, java.lang.Iterable<Digest.Entry>, Constructable<Digest>
A message digest containing - for each member - the highest seqno delivered (hd) and the highest seqno received (hr). The seqnos are stored according to the order of the members in the associated membership, ie. seqnos[0] is the hd for member members[0], seqnos[1] is the hr for the same member, seqnos[2] is the hd for members[1] and so on. Field 'members' may refer to the View.members, e.g. in a JoinRsp where we ship a view and a digest referring to the view's membership. This is done to conserve memory. This class is immutable except for 2 cases:- The contents are read when unmarshalling (readFrom())
- The membership is set with members(). This must only be done directly after unmarshalling
- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Digest.Entry
Keeps track of one members plus its highest delivered and received seqnosprotected class
Digest.MyIterator
-
Constructor Summary
Constructors Constructor Description Digest()
Used for serializationDigest(java.util.Map<Address,long[]> map)
Creates a new digest from an existing map by copying the keys and values from mapDigest(Address[] members)
Only used internally, don't use !Digest(Address[] members, long[] seqnos)
Digest(Address sender, long highest_delivered, long highest_received)
Digest(Digest digest)
Only used for testing
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
capacity()
protected void
checkPostcondition()
boolean
contains(Address mbr)
boolean
containsAll(Address... members)
Digest
copy()
java.util.function.Supplier<? extends Digest>
create()
Creates an instance of the class implementing this interfaceprotected void
createArrays(java.util.Map<Address,long[]> map)
boolean
equals(java.lang.Object obj)
2 digests are equal if their memberships match and all highest-delivered and highest-received seqnos matchprotected int
find(Address mbr)
long[]
get(Address member)
Returns the highest delivered and received seqnos associated with a member.Address[]
getMembersRaw()
Don't use, this method is reserved for Bela ! :-)java.util.Iterator<Digest.Entry>
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 closedvoid
readFrom(java.io.DataInput in, boolean read_addrs)
int
serializedSize()
Returns the size (in bytes) of the marshalled objectlong
serializedSize(boolean with_members)
java.lang.String
toString()
java.lang.String
toString(Address[] order, boolean print_highest_received)
java.lang.String
toString(Digest order)
void
writeTo(java.io.DataOutput out)
Write the entire state of the current object (including superclasses) to outstream.void
writeTo(java.io.DataOutput out, boolean write_addrs)
-
-
-
Field Detail
-
members
protected Address[] members
-
seqnos
protected long[] seqnos
-
-
Constructor Detail
-
Digest
public Digest()
Used for serialization
-
Digest
public Digest(Address[] members, long[] seqnos)
-
Digest
public Digest(Address[] members)
Only used internally, don't use !
-
Digest
public Digest(Digest digest)
Only used for testing
-
Digest
public Digest(java.util.Map<Address,long[]> map)
Creates a new digest from an existing map by copying the keys and values from map
-
Digest
public Digest(Address sender, long highest_delivered, long highest_received)
-
-
Method Detail
-
create
public java.util.function.Supplier<? extends Digest> create()
Description copied from interface:Constructable
Creates an instance of the class implementing this interface- Specified by:
create
in interfaceConstructable<Digest>
-
getMembersRaw
public Address[] getMembersRaw()
Don't use, this method is reserved for Bela ! :-)
-
capacity
public int capacity()
-
contains
public boolean contains(Address mbr)
-
containsAll
public boolean containsAll(Address... members)
-
equals
public boolean equals(java.lang.Object obj)
2 digests are equal if their memberships match and all highest-delivered and highest-received seqnos match- Overrides:
equals
in classjava.lang.Object
-
get
public long[] get(Address member)
Returns the highest delivered and received seqnos associated with a member.- Parameters:
member
-- Returns:
- An array of 2 elements: highest_delivered and highest_received seqnos
-
iterator
public java.util.Iterator<Digest.Entry> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<Digest.Entry>
-
copy
public Digest copy()
-
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
-
writeTo
public void writeTo(java.io.DataOutput out, boolean write_addrs) throws java.io.IOException
- 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
-
readFrom
public void readFrom(java.io.DataInput in, boolean read_addrs) throws java.io.IOException, java.lang.ClassNotFoundException
- 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
-
serializedSize
public long serializedSize(boolean with_members)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
public java.lang.String toString(Digest order)
-
toString
public java.lang.String toString(Address[] order, boolean print_highest_received)
-
find
protected int find(Address mbr)
-
createArrays
protected void createArrays(java.util.Map<Address,long[]> map)
-
checkPostcondition
protected void checkPostcondition()
-
-