2 * Copyright (c) 2016 Brocade Communications 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.persisted;
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import java.io.Serializable;
17 * Message class to persist election term information.
19 public class UpdateElectionTerm implements Serializable {
20 private static final class Proxy implements Externalizable {
21 private static final long serialVersionUID = 1L;
23 private UpdateElectionTerm updateElectionTerm;
25 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
26 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
27 @SuppressWarnings("checkstyle:RedundantModifier")
32 Proxy(final UpdateElectionTerm updateElectionTerm) {
33 this.updateElectionTerm = updateElectionTerm;
37 public void writeExternal(final ObjectOutput out) throws IOException {
38 out.writeLong(updateElectionTerm.currentTerm);
39 out.writeObject(updateElectionTerm.votedFor);
43 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
44 updateElectionTerm = new UpdateElectionTerm(in.readLong(), (String) in.readObject());
47 private Object readResolve() {
48 return updateElectionTerm;
52 private static final long serialVersionUID = 1L;
54 private final long currentTerm;
55 private final String votedFor;
57 public UpdateElectionTerm(final long currentTerm, final String votedFor) {
58 this.currentTerm = currentTerm;
59 this.votedFor = votedFor;
62 public long getCurrentTerm() {
66 public String getVotedFor() {
70 private Object writeReplace() {
71 return new Proxy(this);
75 public String toString() {
76 return "UpdateElectionTerm [currentTerm=" + currentTerm + ", votedFor=" + votedFor + "]";