docs: protected VoteResponse handleVote(VoteRequest request) {
      // If the request term is not as great as the current context term then don't
      // vote for the candidate. We want to vote for candidates that are at least
      // as up to date as us.
      if (request.term() < raft.getTerm()) {
        log.debug("Rejected {}: candidate's term is less than the current term", request);
        return VoteResponse.builder()
            .withStatus(RaftResponse.Status.OK)
            .withTerm(raft.getTerm())
            .withVoted(false)
            .build();
      }
      // If a leader was already determined for this term then reject the request.
      else if (raft.getLeader() != null) {
        log.debug("Rejected {}: leader already exists", request);
        return VoteResponse.builder()
            .withStatus(RaftResponse.Status.OK)
            .withTerm(raft.getTerm())
            .withVoted(false)
            .build();
      }
      // If the requesting candidate is not a known member of the cluster (to this
      // node) then don't vote for it. Only vote for candidates that we know about.
      else if (!raft.getCluster().getRemoteMemberStates().stream().map(m -> m.getMember().memberId()).collect(Collectors.toSet()).contains(request.candidate())) {
        log.debug("Rejected {}: candidate is not known to the local member", request);
        return VoteResponse.builder()
            .withStatus(RaftResponse.Status.OK)
            .withTerm(raft.getTerm())
            .withVoted(false)
            .build();
      }
      // If no vote has been cast, check the log and cast a vote if necessary.
      else if (raft.getLastVotedFor() == null) {
        if (isLogUpToDate(request.lastLogIndex(), request.lastLogTerm(), request)) {
          raft.setLastVotedFor(request.candidate());
          return VoteResponse.builder()
              .withStatus(RaftResponse.Status.OK)
              .withTerm(raft.getTerm())
              .withVoted(true)
              .build();
        } else {
          return VoteResponse.builder()
              .withStatus(RaftResponse.Status.OK)
              .withTerm(raft.getTerm())
              .withVoted(false)
              .build();
        }
      }
      // If we already voted for the requesting server, respond successfully.
      else if (raft.getLastVotedFor() == request.candidate()) {
        log.debug("Accepted {}: already voted for {}", request, raft.getCluster().getMember(raft.getLastVotedFor()).memberId());
        return VoteResponse.builder()
            .withStatus(RaftResponse.Status.OK)
            .withTerm(raft.getTerm())
            .withVoted(true)
            .build();
      }
      // In this case, we've already voted for someone else.
      else {
        log.debug("Rejected {}: already voted for {}", request, raft.getCluster().getMember(raft.getLastVotedFor()).memberId());
        return VoteResponse.builder()
            .withStatus(RaftResponse.Status.OK)
            .withTerm(raft.getTerm())
            .withVoted(false)
            .build();
      }
    }