Class RoleState
The roster is in offset order, which is registration order. The lease is the last lease record of the role, and it is absent when no member holds the role or when a tombstone cleared it.
Build a state with fromRecords(Role, Iterable), or fold records one at a
time with RoleStateBuilder.
Example
RoleState state = RoleState.fromRecords(role, transport.readRoleRecords(role));
OptionalInt rank = state.rankOf(me);
Optional<MemberId> holder = state.holder();
-
Method Summary
Modifier and TypeMethodDescriptionstatic RoleStateempty()Returns the state of a role that has no record.Returns the roster entry of one member.booleanReports whether another object is a state with the same roster and lease.static RoleStatefromRecords(Role role, Iterable<CoordinationEntry> entries) Folds the records of one role into a role state.inthashCode()Returns a hash of the roster and the lease.holder()Returns the member the lease names.lease()Returns the lease of the role.Returns the challenge rank of one member.roster()Returns the candidates of the role, in registration order.toString()Returns the roster and the lease.
-
Method Details
-
empty
Returns the state of a role that has no record.- Returns:
- a state with an empty roster and no lease
-
fromRecords
Folds the records of one role into a role state.The caller reads the partition of the role in offset order and passes every record. The fold gives the same answer for another order, because it keeps the record of the highest offset for every key. It drops a record of another role, so a caller folds a partition that holds several roles and needs no filter of its own.
- Parameters:
role- the role to collectentries- the decoded records of the partition- Returns:
- the folded state of that role
- Throws:
NullPointerException- if the role or the entries are null
-
roster
Returns the candidates of the role, in registration order.- Returns:
- the roster, oldest registration first
-
lease
-
holder
Returns the member the lease names.The holder of an expired lease is still the holder. Ask
LeaseTiming.liveAt(long)whether the lease is live.- Returns:
- the holder, and empty when the role has no lease
-
entry
Returns the roster entry of one member.- Parameters:
member- the member to look up- Returns:
- the entry, and empty when the member did not register
-
rankOf
Returns the challenge rank of one member.The rank is the index of the member in the roster after the removal of the current holder, so the first standby takes rank 0. The holder itself keeps rank 0. A holder reaches the rank test only after its own lease expired, and it still owns the newest epoch at that point, so it reclaims the role for less churn than a failover costs.
- Parameters:
member- the member to rank- Returns:
- the rank, and empty when the member did not register
-
equals
-
hashCode
-
toString
-