io.atomix.protocols.raft.storage.log.entry.MetadataEntry Java Examples

The following examples show how to use io.atomix.protocols.raft.storage.log.entry.MetadataEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LeaderRole.java    From atomix with Apache License 2.0 5 votes vote down vote up
@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;
}