Record Class HlcTimestamp

java.lang.Object
java.lang.Record
ai.badmonkey.agentspaces.common.hlc.HlcTimestamp
Record Components:
physical - wall-clock component, epoch milliseconds
logical - logical counter within the same physical millisecond
node - identifier of the issuing node; never null
All Implemented Interfaces:
Comparable<HlcTimestamp>

public record HlcTimestamp(long physical, int logical, String node) extends Record implements Comparable<HlcTimestamp>
A hybrid logical clock (HLC) timestamp: a physical wall-clock component in epoch milliseconds, a logical counter that disambiguates events within the same millisecond, and the identifier of the node that issued the timestamp.

Timestamps order totally: first by physical time, then by logical counter, then by node identifier. The node component makes the ordering deterministic across the whole fleet, which the LEASE_RACE arbitration in the spec (ยง7.4) relies on.

The canonical string form is physical:logical:node, and that form is used for serialization.

  • Constructor Details

    • HlcTimestamp

      public HlcTimestamp(long physical, int logical, String node)
      Creates an instance of a HlcTimestamp record class.
      Parameters:
      physical - the value for the physical record component
      logical - the value for the logical record component
      node - the value for the node record component
  • Method Details

    • parse

      public static HlcTimestamp parse(String encoded)
      Parses the canonical physical:logical:node form.
      Parameters:
      encoded - the canonical string form
      Returns:
      the parsed timestamp
      Throws:
      IllegalArgumentException - if the input does not match the canonical form
    • encoded

      public String encoded()
      Returns the canonical physical:logical:node form.
    • compareTo

      public int compareTo(HlcTimestamp other)
      Specified by:
      compareTo in interface Comparable<HlcTimestamp>
    • toString

      public 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.
    • physical

      public long physical()
      Returns the value of the physical record component.
      Returns:
      the value of the physical record component
    • logical

      public int logical()
      Returns the value of the logical record component.
      Returns:
      the value of the logical record component
    • node

      public String node()
      Returns the value of the node record component.
      Returns:
      the value of the node record component