public void receive(Messages msg, byte[] data) throws Exception {

    switch (msg) {
      case VoteRequest:
        LOG.debug("Candidate: " + this.getCandidateId() + " received VoteRequest: " + VoteRequest.parseFrom(data));
        this.onVoteRequest(VoteRequest.parseFrom(data));
        break;
      case VoteResponse:
        LOG.debug("Candidate: " + this.getCandidateId() + " received VoteResponse: " + VoteResponse.parseFrom(data));
        this.onVoteResponse(VoteResponse.parseFrom(data));
        break;
      case AppendEntriesRequest:
        this.onAppendEntriesRequest(AppendEntriesRequest.parseFrom(data));
        break;
      case AppendEntriesResponse:
        this.onAppendEntriesResponse(AppendEntriesResponse.parseFrom(data));
      default:
        throw new UnknownRaftMessageException("Unknown message: " + msg);
    }
  }