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;
29 Proxy(final UpdateElectionTerm updateElectionTerm) {
30 this.updateElectionTerm = updateElectionTerm;
34 public void writeExternal(final ObjectOutput out) throws IOException {
35 out.writeLong(updateElectionTerm.currentTerm);
36 out.writeObject(updateElectionTerm.votedFor);
40 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
41 updateElectionTerm = new UpdateElectionTerm(in.readLong(), (String) in.readObject());
44 private Object readResolve() {
45 return updateElectionTerm;
49 private static final long serialVersionUID = 1L;
51 private final long currentTerm;
52 private final String votedFor;
53 private final boolean migrated;
55 private UpdateElectionTerm(final long currentTerm, final String votedFor, final boolean migrated) {
56 this.currentTerm = currentTerm;
57 this.votedFor = votedFor;
58 this.migrated = migrated;
61 public UpdateElectionTerm(final long currentTerm, final String votedFor) {
62 this(currentTerm, votedFor, false);
65 public long getCurrentTerm() {
69 public String getVotedFor() {
74 public boolean isMigrated() {
79 public Object writeReplace() {
80 return new Proxy(this);
84 public static UpdateElectionTerm createMigrated(final long currentTerm, final String votedFor) {
85 return new UpdateElectionTerm(currentTerm, votedFor, true);
89 public String toString() {
90 return "UpdateElectionTerm [currentTerm=" + currentTerm + ", votedFor=" + votedFor + "]";