Do not override jsr305 version
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / messages / RequestVote.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.raft.messages;
10
11 /**
12  * Invoked by candidates to gather votes (§5.2).
13  */
14 public class RequestVote extends AbstractRaftRPC {
15     private static final long serialVersionUID = -6967509186297108657L;
16
17     // candidate requesting vote
18     private String candidateId;
19
20     // index of candidate’s last log entry (§5.4)
21     private long lastLogIndex;
22
23     // term of candidate’s last log entry (§5.4)
24     private long lastLogTerm;
25
26     public RequestVote(long term, String candidateId, long lastLogIndex,
27         long lastLogTerm) {
28         super(term);
29         this.candidateId = candidateId;
30         this.lastLogIndex = lastLogIndex;
31         this.lastLogTerm = lastLogTerm;
32     }
33
34     // added for testing while serialize-messages=on
35     public RequestVote() {
36     }
37
38     @Override
39     public long getTerm() {
40         return term;
41     }
42
43     public String getCandidateId() {
44         return candidateId;
45     }
46
47     public long getLastLogIndex() {
48         return lastLogIndex;
49     }
50
51     public long getLastLogTerm() {
52         return lastLogTerm;
53     }
54
55     public void setCandidateId(String candidateId) {
56         this.candidateId = candidateId;
57     }
58
59     public void setLastLogIndex(long lastLogIndex) {
60         this.lastLogIndex = lastLogIndex;
61     }
62
63     public void setLastLogTerm(long lastLogTerm) {
64         this.lastLogTerm = lastLogTerm;
65     }
66
67     @Override public String toString() {
68         final StringBuilder sb =
69             new StringBuilder("RequestVote{");
70         sb.append("term='").append(getTerm()).append('\'');
71         sb.append("candidateId='").append(candidateId).append('\'');
72         sb.append(", lastLogIndex=").append(lastLogIndex);
73         sb.append(", lastLogTerm=").append(lastLogTerm);
74         sb.append('}');
75         return sb.toString();
76     }
77 }