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 {
20 private static final long serialVersionUID = -6967509186297108657L;
22 // candidate requesting vote
23 private final String candidateId;
25 // index of candidate’s last log entry (§5.4)
26 private final long lastLogIndex;
28 // term of candidate’s last log entry (§5.4)
29 private final long lastLogTerm;
31 public RequestVote(final long term, final String candidateId, final long lastLogIndex, final long lastLogTerm) {
33 this.candidateId = candidateId;
34 this.lastLogIndex = lastLogIndex;
35 this.lastLogTerm = lastLogTerm;
38 public String getCandidateId() {
42 public long getLastLogIndex() {
46 public long getLastLogTerm() {
51 public String toString() {
52 return "RequestVote [term=" + getTerm()
53 + ", candidateId=" + candidateId
54 + ", lastLogIndex=" + lastLogIndex
55 + ", lastLogTerm=" + lastLogTerm
60 Object writeReplace() {
64 @Deprecated(since = "7.0.0", forRemoval = true)
65 private static class Proxy implements Externalizable {
67 private static final long serialVersionUID = 1L;
69 private RequestVote requestVote;
71 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
72 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
73 @SuppressWarnings("checkstyle:RedundantModifier")
78 public void writeExternal(final ObjectOutput out) {
79 throw new UnsupportedOperationException();
83 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
84 long term = in.readLong();
85 String candidateId = (String) in.readObject();
86 long lastLogIndex = in.readLong();
87 long lastLogTerm = in.readLong();
89 requestVote = new RequestVote(term, candidateId, lastLogIndex, lastLogTerm);
93 private Object readResolve() {