Merge "Fixed for bug : 1171 - issue while creating subnet"
[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
16     // candidate requesting vote
17     private String candidateId;
18
19     // index of candidate’s last log entry (§5.4)
20     private long lastLogIndex;
21
22     // term of candidate’s last log entry (§5.4)
23     private long lastLogTerm;
24
25     public RequestVote(long term, String candidateId, long lastLogIndex,
26         long lastLogTerm) {
27         super(term);
28         this.candidateId = candidateId;
29         this.lastLogIndex = lastLogIndex;
30         this.lastLogTerm = lastLogTerm;
31     }
32
33     // added for testing while serialize-messages=on
34     public RequestVote() {
35     }
36
37     public long getTerm() {
38         return term;
39     }
40
41     public String getCandidateId() {
42         return candidateId;
43     }
44
45     public long getLastLogIndex() {
46         return lastLogIndex;
47     }
48
49     public long getLastLogTerm() {
50         return lastLogTerm;
51     }
52
53     public void setCandidateId(String candidateId) {
54         this.candidateId = candidateId;
55     }
56
57     public void setLastLogIndex(long lastLogIndex) {
58         this.lastLogIndex = lastLogIndex;
59     }
60
61     public void setLastLogTerm(long lastLogTerm) {
62         this.lastLogTerm = lastLogTerm;
63     }
64
65     @Override public String toString() {
66         final StringBuilder sb =
67             new StringBuilder("RequestVote{");
68         sb.append("term='").append(getTerm()).append('\'');
69         sb.append("candidateId='").append(candidateId).append('\'');
70         sb.append(", lastLogIndex=").append(lastLogIndex);
71         sb.append(", lastLogTerm=").append(lastLogTerm);
72         sb.append('}');
73         return sb.toString();
74     }
75 }