final class LWWRegister[A] extends ReplicatedData with 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. 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 LWWRegister#reverseClock instead of the LWWRegister#defaultClock

This class is immutable, i.e. "modifying" methods return a new instance.

Annotations
@SerialVersionUID()
Source
LWWRegister.scala
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LWWRegister
  2. ReplicatedDataSerialization
  3. Serializable
  4. ReplicatedData
  5. AnyRef
  6. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. type T = LWWRegister[A]

    The type of the concrete implementation, e.g.

    The type of the concrete implementation, e.g. GSet[A]. To be specified by subclass.

    Definition Classes
    LWWRegisterReplicatedData

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from LWWRegister[A] toany2stringadd[LWWRegister[A]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (LWWRegister[A], B)
    Implicit
    This member is added by an implicit conversion from LWWRegister[A] toArrowAssoc[LWWRegister[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
  8. def ensuring(cond: (LWWRegister[A]) => Boolean, msg: => Any): LWWRegister[A]
    Implicit
    This member is added by an implicit conversion from LWWRegister[A] toEnsuring[LWWRegister[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  9. def ensuring(cond: (LWWRegister[A]) => Boolean): LWWRegister[A]
    Implicit
    This member is added by an implicit conversion from LWWRegister[A] toEnsuring[LWWRegister[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  10. def ensuring(cond: Boolean, msg: => Any): LWWRegister[A]
    Implicit
    This member is added by an implicit conversion from LWWRegister[A] toEnsuring[LWWRegister[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def ensuring(cond: Boolean): LWWRegister[A]
    Implicit
    This member is added by an implicit conversion from LWWRegister[A] toEnsuring[LWWRegister[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. def equals(o: Any): Boolean
    Definition Classes
    LWWRegister → AnyRef → Any
  14. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  15. def getValue(): A

    Java API

  16. def hashCode(): Int
    Definition Classes
    LWWRegister → AnyRef → Any
  17. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  18. def merge(that: LWWRegister[A]): LWWRegister[A]

    Monotonic merge function.

    Monotonic merge function.

    Definition Classes
    LWWRegisterReplicatedData
  19. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  21. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  22. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  23. val timestamp: Long
  24. def toString(): String
    Definition Classes
    LWWRegister → AnyRef → Any
  25. def updatedBy: UniqueAddress

    The current value was set by this node.

  26. val value: A
  27. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  28. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  29. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  30. def withValue(node: SelfUniqueAddress, value: A): LWWRegister[A]

    Change the value of the register.

  31. def withValue(node: SelfUniqueAddress, value: A, clock: Clock[A]): LWWRegister[A]

    Change the value of the register.

    Change the value of the register.

    You can provide your clock implementation instead of using timestamps based on System.currentTimeMillis() time. The timestamp can for example be an increasing version number from a database record that is used for optimistic concurrency control.

  32. def withValueOf(value: A)(implicit node: SelfUniqueAddress, clock: Clock[A] = defaultClock[A]): LWWRegister[A]

    Change the value of the register.

    Change the value of the register.

    You can provide your clock implementation instead of using timestamps based on System.currentTimeMillis() time. The timestamp can for example be an increasing version number from a database record that is used for optimistic concurrency control.

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

  2. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from LWWRegister[A] toStringFormat[LWWRegister[A]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @deprecated @inline()
    Deprecated

    (Since version 2.12.16) Use formatString.format(value) instead of value.formatted(formatString), or use the f"" string interpolator. In Java 15 and later, formatted resolves to the new method in String which has reversed parameters.

  3. def [B](y: B): (LWWRegister[A], B)
    Implicit
    This member is added by an implicit conversion from LWWRegister[A] toArrowAssoc[LWWRegister[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use -> instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.

Inherited from Serializable

Inherited from ReplicatedData

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd fromLWWRegister[A] to any2stringadd[LWWRegister[A]]

Inherited by implicit conversion StringFormat fromLWWRegister[A] to StringFormat[LWWRegister[A]]

Inherited by implicit conversion Ensuring fromLWWRegister[A] to Ensuring[LWWRegister[A]]

Inherited by implicit conversion ArrowAssoc fromLWWRegister[A] to ArrowAssoc[LWWRegister[A]]

Ungrouped