use of io.atomix.protocols.raft.protocol.MetadataResponse in project atomix by atomix.
the class LeaderRole method onMetadata.
@Override
public CompletableFuture<MetadataResponse> onMetadata(MetadataRequest request) {
raft.checkThread();
logRequest(request);
if (transferring) {
return CompletableFuture.completedFuture(logResponse(MetadataResponse.builder().withStatus(RaftResponse.Status.ERROR).withError(RaftError.Type.ILLEGAL_MEMBER_STATE).build()));
}
CompletableFuture<MetadataResponse> future = new CompletableFuture<>();
Indexed<MetadataEntry> entry = new Indexed<>(raft.getLastApplied(), new MetadataEntry(raft.getTerm(), System.currentTimeMillis(), request.session()), 0);
raft.getServiceManager().<MetadataResult>apply(entry).whenComplete((result, error) -> {
if (error == null) {
future.complete(logResponse(MetadataResponse.builder().withStatus(RaftResponse.Status.OK).withSessions(result.sessions()).build()));
} else {
future.complete(logResponse(MetadataResponse.builder().withStatus(RaftResponse.Status.ERROR).withError(RaftError.Type.PROTOCOL_ERROR).build()));
}
});
return future;
}
Aggregations