예제 #1
0
  /** Transitions to a new state. */
  protected void transition(RaftServer.State state) {
    if (state == type()) return;

    switch (state) {
      case INACTIVE:
        context.transition(InactiveState.class);
        break;
      case PASSIVE:
        context.transition(PassiveState.class);
        break;
      case FOLLOWER:
        context.transition(FollowerState.class);
        break;
      case CANDIDATE:
        context.transition(CandidateState.class);
        break;
      case LEADER:
        context.transition(LeaderState.class);
        break;
      default:
        throw new IllegalStateException();
    }
  }
예제 #2
0
 @Override
 public CompletableFuture<AbstractState> open() {
   context.checkThread();
   open = true;
   return CompletableFuture.completedFuture(null);
 }
예제 #3
0
 /** Logs a request. */
 protected final <R extends Request> R logRequest(R request) {
   LOGGER.debug("{} - Received {}", context.getMember().id(), request);
   return request;
 }
예제 #4
0
 /** Logs a response. */
 protected final <R extends Response> R logResponse(R response) {
   LOGGER.debug("{} - Sent {}", context.getMember().id(), response);
   return response;
 }
예제 #5
0
 @Override
 public CompletableFuture<Void> close() {
   context.checkThread();
   open = false;
   return CompletableFuture.completedFuture(null);
 }