Class LWWRegister<A>
- All Implemented Interfaces:
Serializable,ReplicatedData,ReplicatedDataSerialization
It is described in the paper A comprehensive study of Convergent and Commutative Replicated Data Types.
Merge takes the register with highest timestamp. Note that this
relies on synchronized clocks. LWWRegister should only be used when the choice of
value is not important for concurrent updates occurring within the clock skew.
Merge takes the register updated by the node with lowest address (UniqueAddress is ordered)
if the timestamps are exactly the same.
Instead of using timestamps based on System.currentTimeMillis() time it is possible to
use a timestamp value based on something else, for example an increasing version number
from a database record that is used for optimistic concurrency control.
The defaultClock is using max value of System.currentTimeMillis() and currentTimestamp + 1.
This means that the timestamp is increased for changes on the same node that occurs within
the same millisecond. It also means that it is safe to use the LWWRegister without
synchronized clocks when there is only one active writer, e.g. a Cluster Singleton. Such a
single writer should then first read current value with ReadMajority (or more) before
changing and writing the value with WriteMajority (or more).
For first-write-wins semantics you can use the reverseClock() instead of the
defaultClock()
This class is immutable, i.e. "modifying" methods return a new instance.
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <A> LWWRegister<A>apply(SelfUniqueAddress node, A initialValue) static <A> LWWRegister<A>apply(SelfUniqueAddress node, A initialValue, LWWRegister.Clock<A> clock) static <A> LWWRegister<A>create(A initialValue, SelfUniqueAddress node, LWWRegister.Clock<A> clock) Scala API Creates aLWWRegisterwith implicits, given deprecatedapplyfunctions using Cluster constrain overloading.static <A> LWWRegister<A>create(SelfUniqueAddress node, A initialValue) Java APIstatic <A> LWWRegister<A>create(SelfUniqueAddress node, A initialValue, LWWRegister.Clock<A> clock) Java APIstatic <A> LWWRegister.Clock<A>create$default$3(A initialValue) static <A> LWWRegister.Clock<A>The defaultLWWRegister.Clockis using max value ofSystem.currentTimeMillis()andcurrentTimestamp + 1.booleangetValue()Java APIinthashCode()merge(LWWRegister<A> that) INTERNAL APIstatic <A> LWWRegister.Clock<A>ThisLWWRegister.Clockcan be used for first-write-wins semantics.longtoString()static <A> scala.Option<A>unapply(LWWRegister<A> c) Extract thevalue().The currentvaluewas set by this node.value()withValue(SelfUniqueAddress node, A value) Change the value of the register.withValue(SelfUniqueAddress node, A value, LWWRegister.Clock<A> clock) Change the value of the register.withValueOf(A value, SelfUniqueAddress node, LWWRegister.Clock<A> clock) Change the value of the register.withValueOf$default$3(A value) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.pekko.cluster.ddata.ReplicatedData
merge
-
Method Details
-
defaultClock
The defaultLWWRegister.Clockis using max value ofSystem.currentTimeMillis()andcurrentTimestamp + 1. -
reverseClock
ThisLWWRegister.Clockcan be used for first-write-wins semantics. It is using min value of-System.currentTimeMillis()andcurrentTimestamp + 1, i.e. it is counting backwards. -
apply
-
apply
public static <A> LWWRegister<A> apply(SelfUniqueAddress node, A initialValue, LWWRegister.Clock<A> clock) -
create
public static <A> LWWRegister<A> create(A initialValue, SelfUniqueAddress node, LWWRegister.Clock<A> clock) Scala API Creates aLWWRegisterwith implicits, given deprecatedapplyfunctions using Cluster constrain overloading. -
create
public static <A> LWWRegister<A> create(SelfUniqueAddress node, A initialValue, LWWRegister.Clock<A> clock) Java API -
create
Java API -
create$default$3
-
unapply
Extract thevalue(). -
value
-
timestamp
public long timestamp() -
getValue
Java API -
withValue
Change the value of the register.You can provide your
clockimplementation instead of using timestamps based onSystem.currentTimeMillis()time. The timestamp can for example be an increasing version number from a database record that is used for optimistic concurrency control. -
withValue
Change the value of the register. -
withValueOf
Change the value of the register.You can provide your
clockimplementation instead of using timestamps based onSystem.currentTimeMillis()time. The timestamp can for example be an increasing version number from a database record that is used for optimistic concurrency control. -
updatedBy
The currentvaluewas set by this node. -
withValueOf$default$3
-
merge
INTERNAL API -
toString
-
equals
-
hashCode
public int hashCode()
-