Search in sources :

Example 1 with MetadataResponse

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MetadataResponse(io.atomix.protocols.raft.protocol.MetadataResponse) MetadataEntry(io.atomix.protocols.raft.storage.log.entry.MetadataEntry) Indexed(io.atomix.storage.journal.Indexed)

Aggregations

MetadataResponse (io.atomix.protocols.raft.protocol.MetadataResponse)1 MetadataEntry (io.atomix.protocols.raft.storage.log.entry.MetadataEntry)1 Indexed (io.atomix.storage.journal.Indexed)1 CompletableFuture (java.util.concurrent.CompletableFuture)1