Class RoleStateBuilder
RoleState.
The builder keeps the record of the highest offset for every key, which is what log compaction keeps. A later registration for a member replaces the earlier one and moves the member to the tail of the roster. A registration tombstone removes the member. A lease tombstone clears the lease.
The builder drops a record of another role, so a caller folds a partition that holds several roles and needs no filter of its own.
The key carries the identity, because the key is the compaction key. The builder takes the member and the record kind from the key, and it takes neither from the value.
One builder is not safe for concurrent use. Confine it to one thread.
Example
RoleStateBuilder builder = new RoleStateBuilder(Role.of("controller"));
for (CoordinationEntry entry : transport.readRoleRecords(builder.role())) {
builder.apply(entry);
}
RoleState state = builder.build();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(CoordinationEntry entry) Applies one record of the coordination partition.build()Builds the role state, with the roster in offset order.role()Returns the role that this fold collects.
-
Constructor Details
-
RoleStateBuilder
Creates an empty fold for one role.- Parameters:
role- the role to collect- Throws:
NullPointerException- if the role is null
-
-
Method Details
-
role
Returns the role that this fold collects.- Returns:
- the role the builder was created for
-
apply
Applies one record of the coordination partition.The builder drops a record of another role, and it drops a value whose kind does not match the kind of its key.
CoordinationCodecreads the kind from the key, so a decoder cannot produce such a pair.- Parameters:
entry- the decoded record and the offset it sits at- Returns:
- this builder, so a caller chains calls
- Throws:
NullPointerException- if the entry is null
-
build
Builds the role state, with the roster in offset order.- Returns:
- the folded state of the role
-