Interface CoordinationValue
- All Known Implementing Classes:
Lease, Registration
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 Details
-
kind
RecordKind kind()Returns the record kind whose key this value belongs under.- Returns:
RecordKind.REGISTRATIONfor a registration andRecordKind.LEASEfor a lease
-
member
MemberId member()Returns the member the value names.- Returns:
- the member that registered, or the member that holds the role
-