Record Class CoordinationKey

java.lang.Object
java.lang.Record
io.krabka.streams.coordination.CoordinationKey
Record Components:
kind - the record the key names
role - the role the record belongs to
member - the member for a registration key, and empty for a lease key

public record CoordinationKey(RecordKind kind, Role role, Optional<MemberId> member) extends Record
The decoded key of one record of CoordinationCodec.TOPIC.

The key is the compaction key, so the topic keeps the last record of every role and every member. The key also carries the record kind, so one topic holds both kinds and a reader picks the value layout from the key it already read.

The member is present for RecordKind.REGISTRATION and absent for RecordKind.LEASE. A lease belongs to the role and not to one member, and the frozen layout writes the empty string in that position. registration(Role, MemberId) and lease(Role) build a key that keeps this rule.

Example

CoordinationKey mine = CoordinationKey.registration(Role.of("controller"), me);
CoordinationKey theirs = CoordinationKey.lease(Role.of("controller"));
byte[] bytes = CoordinationCodec.encodeKey(theirs);
  • Constructor Details

    • CoordinationKey

      public CoordinationKey(RecordKind kind, Role role, Optional<MemberId> member)
      Rejects a null component and a key whose member does not match its kind.
      Parameters:
      kind - the record the key names
      role - the role the record belongs to
      member - the member for a registration key, and empty for a lease key
  • Method Details

    • registration

      public static CoordinationKey registration(Role role, MemberId member)
      Builds the key of the registration of one member of a role.
      Parameters:
      role - the role the member competes for
      member - the member that registers
      Returns:
      the registration key of that member
    • lease

      public static CoordinationKey lease(Role role)
      Builds the key of the lease of a role.
      Parameters:
      role - the role the lease belongs to
      Returns:
      the lease key of that role, which carries no member
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • kind

      public RecordKind kind()
      Returns the value of the kind record component.
      Returns:
      the value of the kind record component
    • role

      public Role role()
      Returns the value of the role record component.
      Returns:
      the value of the role record component
    • member

      public Optional<MemberId> member()
      Returns the value of the member record component.
      Returns:
      the value of the member record component