/** 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(); } }
@Override public CompletableFuture<AbstractState> open() { context.checkThread(); open = true; return CompletableFuture.completedFuture(null); }
/** Logs a request. */ protected final <R extends Request> R logRequest(R request) { LOGGER.debug("{} - Received {}", context.getMember().id(), request); return request; }
/** Logs a response. */ protected final <R extends Response> R logResponse(R response) { LOGGER.debug("{} - Sent {}", context.getMember().id(), response); return response; }
@Override public CompletableFuture<Void> close() { context.checkThread(); open = false; return CompletableFuture.completedFuture(null); }