fc6d48906a73b63f34eaf053792b2c3a0cb1c3c0
[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 final String candidateId;
19
20     // index of candidate’s last log entry (§5.4)
21     private final long lastLogIndex;
22
23     // term of candidate’s last log entry (§5.4)
24     private final long lastLogTerm;
25
26     public RequestVote(long term, String candidateId, long lastLogIndex, long lastLogTerm) {
27         super(term);
28         this.candidateId = candidateId;
29         this.lastLogIndex = lastLogIndex;
30         this.lastLogTerm = lastLogTerm;
31     }
32
33     public String getCandidateId() {
34         return candidateId;
35     }
36
37     public long getLastLogIndex() {
38         return lastLogIndex;
39     }
40
41     public long getLastLogTerm() {
42         return lastLogTerm;
43     }
44
45     @Override
46     public String toString() {
47         StringBuilder builder = new StringBuilder();
48         builder.append("RequestVote [term=").append(getTerm()).append(", candidateId=").append(candidateId)
49                 .append(", lastLogIndex=").append(lastLogIndex).append(", lastLogTerm=").append(lastLogTerm)
50                 .append("]");
51         return builder.toString();
52     }
53 }