LWWRegister

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.

Companion:
object
Source:
LWWRegister.scala
trait Serializable
class Object
trait Matchable
class Any

Type members

Types

Value members

Concrete methods

override def equals(o: Any): Boolean
Definition Classes
Any
Source:
LWWRegister.scala
def getValue(): A

Java API

Java API

Source:
LWWRegister.scala
override def hashCode: Int
Definition Classes
Any
Source:
LWWRegister.scala
override def merge(that: LWWRegister[A]): LWWRegister[A]
Definition Classes
Source:
LWWRegister.scala
override def toString: String
Definition Classes
Any
Source:
LWWRegister.scala

The current value was set by this node.

The current value was set by this node.

Source:
LWWRegister.scala
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.

Source:
LWWRegister.scala
def withValue(node: SelfUniqueAddress, value: A): LWWRegister[A]

Change the value of the register.

Change the value of the register.

Source:
LWWRegister.scala
def withValueOf(value: A)(implicit node: SelfUniqueAddress, 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.

Source:
LWWRegister.scala

Deprecated methods

@deprecated("Use `withValueOf` that takes a `SelfUniqueAddress` parameter instead.", since = "2.5.20")
def withValue(value: A)(implicit node: Cluster, clock: Clock[A]): LWWRegister[A]
Deprecated
[Since version 2.5.20]
Source:
LWWRegister.scala
@deprecated("Use `withValue` that takes a `SelfUniqueAddress` parameter instead.", since = "2.5.20")
def withValue(node: Cluster, value: A): LWWRegister[A]
Deprecated
[Since version 2.5.20]
Source:
LWWRegister.scala
@deprecated("Use `withValue` that takes a `SelfUniqueAddress` parameter instead.", since = "2.5.20")
def withValue(node: Cluster, value: A, clock: Clock[A]): LWWRegister[A]
Deprecated
[Since version 2.5.20]
Source:
LWWRegister.scala

Concrete fields