Interface LWWRegister<T>

  • Type Parameters:
    T -
    All Superinterfaces:
    Crdt

    public interface LWWRegister<T>
    extends Crdt
    A Last-Write-Wins Register.

    This uses a clock value to determine which of two concurrent writes should win. When both clock values are the same, an ordering defined over the node addresses is used to break the tie.

    By default, the clock used is the clock of the node that set the value. This can be affected by clock skew, which means two successive writes delegated to two separate nodes could result in the first one winning. This can be avoided by using a custom clock with a domain specific clock value, if such a causally ordered value is available.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  LWWRegister.Clock
      A clock.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      T get()
      Get the current value of the register.
      default T set​(T value)
      Set the current value of the register, using the default clock.
      T set​(T value, LWWRegister.Clock clock, long customClockValue)
      Set the current value of the register, using the given custom clock and clock value if required.
    • Method Detail

      • get

        T get()
        Get the current value of the register.
        Returns:
        The current value of the register.
      • set

        default T set​(T value)
        Set the current value of the register, using the default clock.
        Parameters:
        value - The value of the register to set.
        Returns:
        The old value of the register.
      • set

        T set​(T value,
              LWWRegister.Clock clock,
              long customClockValue)
        Set the current value of the register, using the given custom clock and clock value if required.
        Parameters:
        value - The value of the register to set.
        clock - The clock to use.
        customClockValue - The custom clock value to use if the clock selected is a custom clock. This is ignored if the clock is not a custom clock.
        Returns:
        The old value of the register.