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;
15 public final class RequestVoteReply extends AbstractRaftRPC {
16 private static final long serialVersionUID = 8427899326488775660L;
18 // true means candidate received vote
19 private final boolean voteGranted;
21 public RequestVoteReply(final long term, final boolean voteGranted) {
23 this.voteGranted = voteGranted;
26 public boolean isVoteGranted() {
31 public String toString() {
32 return "RequestVoteReply [term=" + getTerm() + ", voteGranted=" + voteGranted + "]";
36 Object writeReplace() {
37 return new Proxy(this);
40 private static class Proxy implements Externalizable {
41 private static final long serialVersionUID = 1L;
43 private RequestVoteReply requestVoteReply;
45 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
46 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
47 @SuppressWarnings("checkstyle:RedundantModifier")
51 Proxy(final RequestVoteReply requestVoteReply) {
52 this.requestVoteReply = requestVoteReply;
56 public void writeExternal(final ObjectOutput out) throws IOException {
57 out.writeLong(requestVoteReply.getTerm());
58 out.writeBoolean(requestVoteReply.voteGranted);
62 public void readExternal(final ObjectInput in) throws IOException {
63 long term = in.readLong();
64 boolean voteGranted = in.readBoolean();
66 requestVoteReply = new RequestVoteReply(term, voteGranted);
69 private Object readResolve() {
70 return requestVoteReply;