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, MigratedSerializable {
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;
56 private final boolean migrated;
58 private UpdateElectionTerm(final long currentTerm, final String votedFor, final boolean migrated) {
59 this.currentTerm = currentTerm;
60 this.votedFor = votedFor;
61 this.migrated = migrated;
64 public UpdateElectionTerm(final long currentTerm, final String votedFor) {
65 this(currentTerm, votedFor, false);
68 public long getCurrentTerm() {
72 public String getVotedFor() {
77 public boolean isMigrated() {
82 public Object writeReplace() {
83 return new Proxy(this);
87 public static UpdateElectionTerm createMigrated(final long currentTerm, final String votedFor) {
88 return new UpdateElectionTerm(currentTerm, votedFor, true);
92 public String toString() {
93 return "UpdateElectionTerm [currentTerm=" + currentTerm + ", votedFor=" + votedFor + "]";