Class MemberId

java.lang.Object
io.krabka.streams.coordination.MemberId
All Implemented Interfaces:
Comparable<MemberId>

public final class MemberId extends Object implements Comparable<MemberId>
The validated identity of one member that competes for a role.

A member picks its own id and keeps that id across a reconnect, so the succession order survives a short network failure. The id is the compaction key of the registration record of the member, so two members of one role need two ids.

of(String) is the only way to build a member id, so every MemberId value is proof that the id is well formed. The factory rejects an empty id and an id longer than MAX_LENGTH bytes.

Example

MemberId me = MemberId.of(InetAddress.getLocalHost().getHostName());
transport.register(Role.of("controller"), me);
  • Field Details

    • MAX_LENGTH

      public static final int MAX_LENGTH
      The maximum length of a member id, in bytes.
      See Also:
  • Method Details

    • of

      public static MemberId of(String id)
      Parses a member id.
      Parameters:
      id - the member id, in UTF-8
      Returns:
      the validated member id
      Throws:
      CoordinationException - if the id is empty or holds more than MAX_LENGTH bytes
      NullPointerException - if the id is null
    • id

      public String id()
      Returns the member id.
      Returns:
      the id this member carries
    • compareTo

      public int compareTo(MemberId other)
      Orders two member ids by their text.
      Specified by:
      compareTo in interface Comparable<MemberId>
      Parameters:
      other - the member id to compare against
      Returns:
      a negative number, zero, or a positive number as this id sorts before, with, or after the other id
    • equals

      public boolean equals(Object other)
      Reports whether another object is a member id with the same text.
      Overrides:
      equals in class Object
      Parameters:
      other - the object to compare against
      Returns:
      true when the other object is a member id of this text
    • hashCode

      public int hashCode()
      Returns a hash of the member id.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of the id
    • toString

      public String toString()
      Returns the member id.
      Overrides:
      toString in class Object
      Returns:
      the id this member carries