public class VectorClock extends Object implements IdentifiedDataSerializable
See https://en.wikipedia.org/wiki/Vector_clock The vector clock may be read from different thread but concurrent updates must be synchronized externally. There is no guarantee for concurrent updates.
Constructor and Description |
---|
VectorClock() |
VectorClock(VectorClock from) |
Modifier and Type | Method and Description |
---|---|
Set<Map.Entry<String,Long>> |
entrySet()
Returns a set of replica logical timestamps for this vector clock.
|
boolean |
equals(Object o) |
int |
getFactoryId()
Returns DataSerializableFactory factory ID for this class.
|
int |
getId()
Returns type identifier for this class.
|
Long |
getTimestampForReplica(String replicaId)
Returns logical timestamp for given
replicaId . |
int |
hashCode() |
boolean |
isAfter(VectorClock other)
Returns
true if this vector clock is causally strictly after the
provided vector clock. |
boolean |
isEmpty()
Returns
true if this vector clock is empty (there are no logical
timestamps for any replica). |
void |
merge(VectorClock other)
Merges the provided vector clock into this one by taking the maximum of
the logical timestamps for each replica.
|
void |
readData(ObjectDataInput in)
Reads fields from the input stream
|
void |
setReplicaTimestamp(String replicaId,
long timestamp)
Sets the logical timestamp for the given
replicaId . |
String |
toString() |
void |
writeData(ObjectDataOutput out)
Writes object fields to output stream
|
public VectorClock()
public VectorClock(VectorClock from)
public Long getTimestampForReplica(String replicaId)
replicaId
.
This method may be called from different threads and the result reflects
the latest update on the vector clock.public void setReplicaTimestamp(String replicaId, long timestamp)
replicaId
.
This method is not thread safe and concurrent access must be synchronized
externally.public void merge(VectorClock other)
public boolean isAfter(VectorClock other)
true
if this vector clock is causally strictly after the
provided vector clock. This means that it the provided clock is neither
equal to, greater than or concurrent to this vector clock.
This method may be called from different threads and the result reflects
the latest update on the vector clock.public boolean isEmpty()
true
if this vector clock is empty (there are no logical
timestamps for any replica).
This method may be called from different threads and the result reflects
the latest update on the vector clock.public Set<Map.Entry<String,Long>> entrySet()
public void writeData(ObjectDataOutput out) throws IOException
DataSerializable
writeData
in interface DataSerializable
out
- outputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.public void readData(ObjectDataInput in) throws IOException
DataSerializable
readData
in interface DataSerializable
in
- inputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
input stream has been closed.public int getFactoryId()
IdentifiedDataSerializable
getFactoryId
in interface IdentifiedDataSerializable
public int getId()
IdentifiedDataSerializable
getId
in interface IdentifiedDataSerializable
Copyright © 2021 Hazelcast, Inc.. All Rights Reserved.