Record Class EntryState

java.lang.Object
java.lang.Record
ai.badmonkey.agentspaces.space.crdt.EntryState
Record Components:
record - the immutable entry record as written (its lease field is superseded by lease)
adds - observed add dots
removes - observed remove dots
lease - the current lease, LWW by HLC
completed - monotone completion flag

public record EntryState(EntryRecord record, Set<Dot> adds, Set<Dot> removes, LwwRegister<LeaseInfo> lease, boolean completed) extends Record
The replicated state of one entry (spec ยง7.3): observed-remove add/remove dot sets, a last-writer-wins lease register, and a monotone completed flag. The completed flag is what makes double complete impossible to merge back in: once any replica records completion, every merge preserves it.

Immutable; every operation returns a new state, and merge(EntryState) is commutative, associative, and idempotent by construction.

  • Constructor Details

    • EntryState

      public EntryState(EntryRecord record, Set<Dot> adds, Set<Dot> removes, LwwRegister<LeaseInfo> lease, boolean completed)
      Creates an instance of a EntryState record class.
      Parameters:
      record - the value for the record record component
      adds - the value for the adds record component
      removes - the value for the removes record component
      lease - the value for the lease record component
      completed - the value for the completed record component
  • Method Details

    • added

      public static EntryState added(EntryRecord record, Dot addDot, LwwRegister<LeaseInfo> stamp)
      Creates the state for a freshly written entry.
      Parameters:
      record - the written record
      addDot - the writing replica's dot
      stamp - the write's lease register
      Returns:
      the new state
    • present

      public boolean present()
      Returns whether the entry is present: some add dot is unremoved and it is not completed.
    • withObservedRemoved

      public EntryState withObservedRemoved()
      Returns a state with all currently observed add dots removed (withdrawal).
    • withCompleted

      public EntryState withCompleted()
      Returns a state marked completed. Monotone: no operation clears it.
    • withLease

      public EntryState withLease(LwwRegister<LeaseInfo> leaseWrite)
      Returns a state with a lease write merged in (LWW by HLC).
      Parameters:
      leaseWrite - the lease write
      Returns:
      the updated state
    • merge

      public EntryState merge(EntryState other)
      Merges two replicas' states for the same entry.
      Parameters:
      other - the other replica's state
      Returns:
      the merged state
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • record

      public EntryRecord record()
      Returns the value of the record record component.
      Returns:
      the value of the record record component
    • adds

      public Set<Dot> adds()
      Returns the value of the adds record component.
      Returns:
      the value of the adds record component
    • removes

      public Set<Dot> removes()
      Returns the value of the removes record component.
      Returns:
      the value of the removes record component
    • lease

      public LwwRegister<LeaseInfo> lease()
      Returns the value of the lease record component.
      Returns:
      the value of the lease record component
    • completed

      public boolean completed()
      Returns the value of the completed record component.
      Returns:
      the value of the completed record component