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
8 package org.opendaylight.controller.cluster.raft.messages;
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
16 * Invoked by candidates to gather votes (§5.2).
18 public final class RequestVote extends AbstractRaftRPC {
19 private static final long serialVersionUID = -6967509186297108657L;
21 // candidate requesting vote
22 private final String candidateId;
24 // index of candidate’s last log entry (§5.4)
25 private final long lastLogIndex;
27 // term of candidate’s last log entry (§5.4)
28 private final long lastLogTerm;
30 public RequestVote(final long term, final String candidateId, final long lastLogIndex, final long lastLogTerm) {
32 this.candidateId = candidateId;
33 this.lastLogIndex = lastLogIndex;
34 this.lastLogTerm = lastLogTerm;
37 public String getCandidateId() {
41 public long getLastLogIndex() {
45 public long getLastLogTerm() {
50 public String toString() {
51 return "RequestVote [term=" + getTerm()
52 + ", candidateId=" + candidateId
53 + ", lastLogIndex=" + lastLogIndex
54 + ", lastLogTerm=" + lastLogTerm
59 Object writeReplace() {
63 @Deprecated(since = "7.0.0", forRemoval = true)
64 private static class Proxy implements Externalizable {
66 private static final long serialVersionUID = 1L;
68 private RequestVote requestVote;
70 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
71 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
72 @SuppressWarnings("checkstyle:RedundantModifier")
77 public void writeExternal(final ObjectOutput out) {
78 throw new UnsupportedOperationException();
82 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
83 long term = in.readLong();
84 String candidateId = (String) in.readObject();
85 long lastLogIndex = in.readLong();
86 long lastLogTerm = in.readLong();
88 requestVote = new RequestVote(term, candidateId, lastLogIndex, lastLogTerm);
92 private Object readResolve() {