Class LWWRegister<A>
- java.lang.Object
- 
- org.apache.pekko.cluster.ddata.LWWRegister<A>
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- ReplicatedData,- ReplicatedDataSerialization
 
 public final class LWWRegister<A> extends java.lang.Object implements ReplicatedData, ReplicatedDataSerialization Implements a 'Last Writer Wins Register' CRDT, also called a 'LWW-Register'.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. LWWRegistershould 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 ( UniqueAddressis 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 defaultClockis using max value ofSystem.currentTimeMillis()andcurrentTimestamp + 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 theLWWRegisterwithout synchronized clocks when there is only one active writer, e.g. a Cluster Singleton. Such a single writer should then first read current value withReadMajority(or more) before changing and writing the value withWriteMajority(or more).For first-write-wins semantics you can use the reverseClock()instead of thedefaultClock()This class is immutable, i.e. "modifying" methods return a new instance. - See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static interfaceLWWRegister.Clock<A>
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <A> LWWRegister<A>apply(A initialValue, Cluster node, LWWRegister.Clock<A> clock)Deprecated.Use `apply` that takes a `SelfUniqueAddress` parameter instead.static <A> LWWRegister<A>apply(SelfUniqueAddress node, A initialValue)static <A> LWWRegister<A>apply(SelfUniqueAddress node, A initialValue, LWWRegister.Clock<A> clock)static <A> LWWRegister.Clock<A>apply$default$3(A initialValue)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(Cluster node, A initialValue)Deprecated.Use `create` that takes a `SelfUniqueAddress` parameter instead.static <A> LWWRegister<A>create(Cluster node, A initialValue, LWWRegister.Clock<A> clock)Deprecated.Use `create` that takes a `SelfUniqueAddress` parameter instead.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>defaultClock()The defaultLWWRegister.Clockis using max value ofSystem.currentTimeMillis()andcurrentTimestamp + 1.booleanequals(java.lang.Object o)AgetValue()Java APIinthashCode()LWWRegister<A>merge(LWWRegister<A> that)INTERNAL APIstatic <A> LWWRegister.Clock<A>reverseClock()ThisLWWRegister.Clockcan be used for first-write-wins semantics.longtimestamp()java.lang.StringtoString()static <A> scala.Option<A>unapply(LWWRegister<A> c)Extract thevalue().UniqueAddressupdatedBy()The currentvaluewas set by this node.Avalue()LWWRegister<A>withValue(A value, Cluster node, LWWRegister.Clock<A> clock)Deprecated.Use `withValueOf` that takes a `SelfUniqueAddress` parameter instead.LWWRegister<A>withValue(Cluster node, A value)Deprecated.Use `withValue` that takes a `SelfUniqueAddress` parameter instead.LWWRegister<A>withValue(Cluster node, A value, LWWRegister.Clock<A> clock)Deprecated.Use `withValue` that takes a `SelfUniqueAddress` parameter instead.LWWRegister<A>withValue(SelfUniqueAddress node, A value)Change the value of the register.LWWRegister<A>withValue(SelfUniqueAddress node, A value, LWWRegister.Clock<A> clock)Change the value of the register.LWWRegister.Clock<A>withValue$default$3(A value)LWWRegister<A>withValueOf(A value, SelfUniqueAddress node, LWWRegister.Clock<A> clock)Change the value of the register.LWWRegister.Clock<A>withValueOf$default$3(A value)- 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.apache.pekko.cluster.ddata.ReplicatedDatamerge
 
- 
 
- 
- 
- 
Method Detail- 
defaultClockpublic static <A> LWWRegister.Clock<A> defaultClock() The defaultLWWRegister.Clockis using max value ofSystem.currentTimeMillis()andcurrentTimestamp + 1.
 - 
reverseClockpublic static <A> LWWRegister.Clock<A> 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.
 - 
applypublic static <A> LWWRegister<A> apply(SelfUniqueAddress node, A initialValue) 
 - 
applypublic static <A> LWWRegister<A> apply(SelfUniqueAddress node, A initialValue, LWWRegister.Clock<A> clock) 
 - 
applypublic static <A> LWWRegister<A> apply(A initialValue, Cluster node, LWWRegister.Clock<A> clock) Deprecated.Use `apply` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
 - 
apply$default$3public static <A> LWWRegister.Clock<A> apply$default$3(A initialValue) 
 - 
createpublic static <A> LWWRegister<A> create(A initialValue, SelfUniqueAddress node, LWWRegister.Clock<A> clock) Scala API Creates aLWWRegisterwith implicits, given deprecatedapplyfunctions using Cluster constrain overloading.
 - 
createpublic static <A> LWWRegister<A> create(Cluster node, A initialValue) Deprecated.Use `create` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.Java API
 - 
createpublic static <A> LWWRegister<A> create(Cluster node, A initialValue, LWWRegister.Clock<A> clock) Deprecated.Use `create` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.Java API
 - 
createpublic static <A> LWWRegister<A> create(SelfUniqueAddress node, A initialValue, LWWRegister.Clock<A> clock) Java API
 - 
createpublic static <A> LWWRegister<A> create(SelfUniqueAddress node, A initialValue) Java API
 - 
create$default$3public static <A> LWWRegister.Clock<A> create$default$3(A initialValue) 
 - 
unapplypublic static <A> scala.Option<A> unapply(LWWRegister<A> c) Extract thevalue().
 - 
valuepublic A value() 
 - 
timestamppublic long timestamp() 
 - 
getValuepublic A getValue() Java API
 - 
withValuepublic LWWRegister<A> withValue(SelfUniqueAddress node, A value, LWWRegister.Clock<A> clock) 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.
 - 
withValuepublic LWWRegister<A> withValue(SelfUniqueAddress node, A value) Change the value of the register.
 - 
withValueOfpublic LWWRegister<A> withValueOf(A value, SelfUniqueAddress node, LWWRegister.Clock<A> clock) 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.
 - 
withValuepublic LWWRegister<A> withValue(A value, Cluster node, LWWRegister.Clock<A> clock) Deprecated.Use `withValueOf` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
 - 
withValuepublic LWWRegister<A> withValue(Cluster node, A value) Deprecated.Use `withValue` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
 - 
withValuepublic LWWRegister<A> withValue(Cluster node, A value, LWWRegister.Clock<A> clock) Deprecated.Use `withValue` that takes a `SelfUniqueAddress` parameter instead. Since Akka 2.5.20.
 - 
updatedBypublic UniqueAddress updatedBy() The currentvaluewas set by this node.
 - 
withValueOf$default$3public LWWRegister.Clock<A> withValueOf$default$3(A value) 
 - 
withValue$default$3public LWWRegister.Clock<A> withValue$default$3(A value) 
 - 
mergepublic LWWRegister<A> merge(LWWRegister<A> that) INTERNAL API
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
equalspublic boolean equals(java.lang.Object o) - Overrides:
- equalsin class- java.lang.Object
 
 - 
hashCodepublic int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 
- 
 
-