public void onVoteRequest(VoteRequest request) {

    handleLargerTerm(request.getTerm());

    VoteResponse.Builder builder = VoteResponse.newBuilder()
            .setTerm(this.currentTerm).setCandidateId(this.candidateId);

    if (request.getTerm() >= this.currentTerm &&
            !isLogLatestThan(request.getLastLogTerm(), request.getLastLogIndex()) &&
            this.voteFor == -1 || this.voteFor == request.getCandidateId()) {
      builder.setVoteDecision(VoteDecision.GRANTED);
      this.voteFor = request.getCandidateId();
    } else {
      builder.setVoteDecision(VoteDecision.DENIED);
    }

    this.communicator.sendTo(request.getCandidateId(), Messages.VoteResponse, builder.build().toByteArray());
  }