io.atomix.protocols.raft.protocol.MetadataRequest Java Examples

The following examples show how to use io.atomix.protocols.raft.protocol.MetadataRequest. 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: PassiveRole.java    From atomix with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> onMetadata(MetadataRequest request) {
  raft.checkThread();
  logRequest(request);

  if (raft.getLeader() == null) {
    return CompletableFuture.completedFuture(logResponse(MetadataResponse.builder()
        .withStatus(RaftResponse.Status.ERROR)
        .withError(RaftError.Type.NO_LEADER)
        .build()));
  } else {
    return forward(request, raft.getProtocol()::metadata)
        .exceptionally(error -> MetadataResponse.builder()
            .withStatus(RaftResponse.Status.ERROR)
            .withError(RaftError.Type.NO_LEADER)
            .build())
        .thenApply(this::logResponse);
  }
}
 
Example #2
Source File: DefaultRaftMetadataClient.java    From atomix with Apache License 2.0 6 votes vote down vote up
/**
 * Requests metadata from the cluster.
 *
 * @return A completable future to be completed with cluster metadata.
 */
private CompletableFuture<MetadataResponse> getMetadata() {
  CompletableFuture<MetadataResponse> future = new CompletableFuture<>();
  connection.metadata(MetadataRequest.builder().build()).whenComplete((response, error) -> {
    if (error == null) {
      if (response.status() == RaftResponse.Status.OK) {
        future.complete(response);
      } else {
        future.completeExceptionally(response.error().createException());
      }
    } else {
      future.completeExceptionally(error);
    }
  });
  return future;
}
 
Example #3
Source File: InactiveRole.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> onMetadata(MetadataRequest request) {
  logRequest(request);
  return Futures.completedFuture(logResponse(MetadataResponse.builder()
      .withStatus(Status.ERROR)
      .withError(RaftError.Type.UNAVAILABLE)
      .build()));
}
 
Example #4
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;
}
 
Example #5
Source File: RaftSessionConnection.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a metadata request to the given node.
 *
 * @param request the request to send
 * @return a future to be completed with the response
 */
public CompletableFuture<MetadataResponse> metadata(MetadataRequest request) {
  CompletableFuture<MetadataResponse> future = new CompletableFuture<>();
  if (context.isCurrentContext()) {
    sendRequest(request, protocol::metadata, future);
  } else {
    context.execute(() -> sendRequest(request, protocol::metadata, future));
  }
  return future;
}
 
Example #6
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId, MetadataRequest request) {
  return sendAndReceive(context.metadataSubject, request, memberId);
}
 
Example #7
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerMetadataHandler(Function<MetadataRequest, CompletableFuture<MetadataResponse>> handler) {
  this.metadataHandler = handler;
}
 
Example #8
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId, MetadataRequest request) {
  return getServer(memberId).thenCompose(listener -> listener.metadata(encode(request))).thenApply(this::decode);
}
 
Example #9
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerMetadataHandler(Function<MetadataRequest, CompletableFuture<MetadataResponse>> handler) {
  registerHandler("metadata", handler);
}
 
Example #10
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId, MetadataRequest request) {
  return sendAndReceive(memberId, "metadata", request);
}
 
Example #11
Source File: LocalRaftClientProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId, MetadataRequest request) {
  return getServer(memberId).thenCompose(protocol -> protocol.metadata(encode(request))).thenApply(this::decode);
}
 
Example #12
Source File: RaftClientMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId, MetadataRequest request) {
  return sendAndReceive(memberId, "metadata", request);
}
 
Example #13
Source File: RaftClientCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId, MetadataRequest request) {
  return sendAndReceive(context.metadataSubject, request, memberId);
}
 
Example #14
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerMetadataHandler(Function<MetadataRequest, CompletableFuture<MetadataResponse>> handler) {
  clusterCommunicator.subscribe(context.metadataSubject, serializer::decode, handler, serializer::encode);
}
 
Example #15
Source File: RaftClientMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId,
                                                    MetadataRequest request) {
  return sendAndReceive(memberId, "metadata", request);
}
 
Example #16
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerMetadataHandler(Function<MetadataRequest,
    CompletableFuture<MetadataResponse>> handler) {
  this.metadataHandler = handler;
}
 
Example #17
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId,
                                                    MetadataRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.metadata(encode(request))).thenApply(this::decode);
}
 
Example #18
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerMetadataHandler(Function<MetadataRequest,
    CompletableFuture<MetadataResponse>> handler) {
  registerHandler("metadata", handler);
}
 
Example #19
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId,
                                                    MetadataRequest request) {
  return sendAndReceive(memberId, "metadata", request);
}
 
Example #20
Source File: LocalRaftClientProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId,
                                                    MetadataRequest request) {
  return getServer(memberId).thenCompose(protocol ->
      protocol.metadata(encode(request))).thenApply(this::decode);
}
 
Example #21
Source File: RaftClientMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId,
                                                    MetadataRequest request) {
  return sendAndReceive(memberId, "metadata", request);
}
 
Example #22
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerMetadataHandler(Function<MetadataRequest,
    CompletableFuture<MetadataResponse>> handler) {
  this.metadataHandler = handler;
}
 
Example #23
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId,
                                                    MetadataRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.metadata(encode(request))).thenApply(this::decode);
}
 
Example #24
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerMetadataHandler(Function<MetadataRequest,
    CompletableFuture<MetadataResponse>> handler) {
  registerHandler("metadata", handler);
}
 
Example #25
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId,
                                                    MetadataRequest request) {
  return sendAndReceive(memberId, "metadata", request);
}
 
Example #26
Source File: LocalRaftClientProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<MetadataResponse> metadata(MemberId memberId,
                                                    MetadataRequest request) {
  return getServer(memberId).thenCompose(protocol ->
      protocol.metadata(encode(request))).thenApply(this::decode);
}
 
Example #27
Source File: RaftRole.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Handles a metadata request.
 *
 * @param request The request to handle.
 * @return A completable future to be completed with the request response.
 */
CompletableFuture<MetadataResponse> onMetadata(MetadataRequest request);