Remove deprecated persisted raft payloads
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / persisted / UpdateElectionTerm.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.raft.persisted;
9
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;
15
16 /**
17  * Message class to persist election term information.
18  */
19 public class UpdateElectionTerm implements Serializable {
20     private static final class Proxy implements Externalizable {
21         private static final long serialVersionUID = 1L;
22
23         private UpdateElectionTerm updateElectionTerm;
24
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")
28         public Proxy() {
29             // For Externalizable
30         }
31
32         Proxy(final UpdateElectionTerm updateElectionTerm) {
33             this.updateElectionTerm = updateElectionTerm;
34         }
35
36         @Override
37         public void writeExternal(final ObjectOutput out) throws IOException {
38             out.writeLong(updateElectionTerm.currentTerm);
39             out.writeObject(updateElectionTerm.votedFor);
40         }
41
42         @Override
43         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
44             updateElectionTerm = new UpdateElectionTerm(in.readLong(), (String) in.readObject());
45         }
46
47         private Object readResolve() {
48             return updateElectionTerm;
49         }
50     }
51
52     private static final long serialVersionUID = 1L;
53
54     private final long currentTerm;
55     private final String votedFor;
56
57     public UpdateElectionTerm(final long currentTerm, final String votedFor) {
58         this.currentTerm = currentTerm;
59         this.votedFor = votedFor;
60     }
61
62     public long getCurrentTerm() {
63         return currentTerm;
64     }
65
66     public String getVotedFor() {
67         return votedFor;
68     }
69
70     private Object writeReplace() {
71         return new Proxy(this);
72     }
73
74     @Override
75     public String toString() {
76         return "UpdateElectionTerm [currentTerm=" + currentTerm + ", votedFor=" + votedFor + "]";
77     }
78 }
79