Interface CoordinationValue

All Known Implementing Classes:
Lease, Registration

public sealed interface CoordinationValue permits Registration, Lease
One decoded value of CoordinationCodec.TOPIC.

The interface has two implementations, and the kind of the key picks which one a value decodes to. Registration is the value of a registration key, and Lease is the value of a lease key. A record with a null value is a tombstone, and CoordinationCodec.decodeValue(RecordKind, byte[]) returns an empty Optional for it rather than a third implementation.

Example

Optional<CoordinationValue> value =
    CoordinationCodec.decodeValue(key.kind(), record.value());
if (value.orElse(null) instanceof Lease lease) {
    System.out.println(lease.member() + " holds the role until " + lease.deadline());
}
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the record kind whose key this value belongs under.
    Returns the member the value names.
  • Method Details

    • kind

      RecordKind kind()
      Returns the record kind whose key this value belongs under.
      Returns:
      RecordKind.REGISTRATION for a registration and RecordKind.LEASE for a lease
    • member

      MemberId member()
      Returns the member the value names.
      Returns:
      the member that registered, or the member that holds the role