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

The following examples show how to use io.atomix.protocols.raft.protocol.TransferRequest. 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: InactiveRole.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<TransferResponse> onTransfer(TransferRequest request) {
  logRequest(request);
  return Futures.completedFuture(logResponse(TransferResponse.builder()
      .withStatus(Status.ERROR)
      .withError(RaftError.Type.UNAVAILABLE)
      .build()));
}
 
Example #2
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<TransferResponse> transfer(MemberId memberId, TransferRequest request) {
  return sendAndReceive(context.transferSubject, request, memberId);
}
 
Example #3
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTransferHandler(Function<TransferRequest, CompletableFuture<TransferResponse>> handler) {
  this.transferHandler = handler;
}
 
Example #4
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<TransferResponse> transfer(MemberId memberId, TransferRequest request) {
  return getServer(memberId).thenCompose(listener -> listener.install(encode(request))).thenApply(this::decode);
}
 
Example #5
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTransferHandler(Function<TransferRequest, CompletableFuture<TransferResponse>> handler) {
  registerHandler("transfer", handler);
}
 
Example #6
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<TransferResponse> transfer(MemberId memberId, TransferRequest request) {
  return sendAndReceive(memberId, "transfer", request);
}
 
Example #7
Source File: LeaderRole.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<TransferResponse> onTransfer(final TransferRequest request) {
  logRequest(request);

  RaftMemberContext member = raft.getCluster().getMemberState(request.member());
  if (member == null) {
    return CompletableFuture.completedFuture(logResponse(TransferResponse.builder()
        .withStatus(RaftResponse.Status.ERROR)
        .withError(RaftError.Type.ILLEGAL_MEMBER_STATE)
        .build()));
  }

  transferring = true;

  CompletableFuture<TransferResponse> future = new CompletableFuture<>();
  appender.appendEntries(raft.getLogWriter().getLastIndex()).whenComplete((result, error) -> {
    if (isRunning()) {
      if (error == null) {
        log.debug("Transferring leadership to {}", request.member());
        raft.transition(RaftServer.Role.FOLLOWER);
        future.complete(logResponse(TransferResponse.builder()
            .withStatus(RaftResponse.Status.OK)
            .build()));
      } else if (error instanceof CompletionException && error.getCause() instanceof RaftException) {
        future.complete(logResponse(TransferResponse.builder()
            .withStatus(RaftResponse.Status.ERROR)
            .withError(((RaftException) error.getCause()).getType(), error.getMessage())
            .build()));
      } else if (error instanceof RaftException) {
        future.complete(logResponse(TransferResponse.builder()
            .withStatus(RaftResponse.Status.ERROR)
            .withError(((RaftException) error).getType(), error.getMessage())
            .build()));
      } else {
        future.complete(logResponse(TransferResponse.builder()
            .withStatus(RaftResponse.Status.ERROR)
            .withError(RaftError.Type.PROTOCOL_ERROR, error.getMessage())
            .build()));
      }
    } else {
      future.complete(logResponse(TransferResponse.builder()
          .withStatus(RaftResponse.Status.ERROR)
          .withError(RaftError.Type.ILLEGAL_MEMBER_STATE)
          .build()));
    }
  });
  return future;
}
 
Example #8
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTransferHandler(Function<TransferRequest, CompletableFuture<TransferResponse>> handler) {
  clusterCommunicator.subscribe(context.transferSubject, serializer::decode, handler, serializer::encode);
}
 
Example #9
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<TransferResponse> transfer(MemberId memberId,
                                                    TransferRequest request) {
  return sendAndReceive(memberId, "transfer", request);
}
 
Example #10
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTransferHandler(Function<TransferRequest,
    CompletableFuture<TransferResponse>> handler) {
  this.transferHandler = handler;
}
 
Example #11
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<TransferResponse> transfer(MemberId memberId, TransferRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.install(encode(request))).thenApply(this::decode);
}
 
Example #12
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTransferHandler(Function<TransferRequest,
    CompletableFuture<TransferResponse>> handler) {
  registerHandler("transfer", handler);
}
 
Example #13
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<TransferResponse> transfer(MemberId memberId,
                                                    TransferRequest request) {
  return sendAndReceive(memberId, "transfer", request);
}
 
Example #14
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTransferHandler(Function<TransferRequest,
    CompletableFuture<TransferResponse>> handler) {
  this.transferHandler = handler;
}
 
Example #15
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<TransferResponse> transfer(MemberId memberId, TransferRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.install(encode(request))).thenApply(this::decode);
}
 
Example #16
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTransferHandler(Function<TransferRequest,
    CompletableFuture<TransferResponse>> handler) {
  registerHandler("transfer", handler);
}
 
Example #17
Source File: RaftRole.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Handles a transfer request.
 *
 * @param request The request to handle.
 * @return A completable future to be completed with the request response.
 */
CompletableFuture<TransferResponse> onTransfer(TransferRequest request);