2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.raft.messages;
12 * Invoked by candidates to gather votes (§5.2).
14 public class RequestVote extends AbstractRaftRPC {
15 private static final long serialVersionUID = 1L;
17 // candidate requesting vote
18 private String candidateId;
20 // index of candidate’s last log entry (§5.4)
21 private long lastLogIndex;
23 // term of candidate’s last log entry (§5.4)
24 private long lastLogTerm;
26 public RequestVote(long term, String candidateId, long lastLogIndex,
29 this.candidateId = candidateId;
30 this.lastLogIndex = lastLogIndex;
31 this.lastLogTerm = lastLogTerm;
34 // added for testing while serialize-messages=on
35 public RequestVote() {
38 public long getTerm() {
42 public String getCandidateId() {
46 public long getLastLogIndex() {
50 public long getLastLogTerm() {
54 public void setCandidateId(String candidateId) {
55 this.candidateId = candidateId;
58 public void setLastLogIndex(long lastLogIndex) {
59 this.lastLogIndex = lastLogIndex;
62 public void setLastLogTerm(long lastLogTerm) {
63 this.lastLogTerm = lastLogTerm;
66 @Override public String toString() {
67 final StringBuilder sb =
68 new StringBuilder("RequestVote{");
69 sb.append("term='").append(getTerm()).append('\'');
70 sb.append("candidateId='").append(candidateId).append('\'');
71 sb.append(", lastLogIndex=").append(lastLogIndex);
72 sb.append(", lastLogTerm=").append(lastLogTerm);