419aec0e321a678a04469f26cb38442bca2fe9c9
[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     @Deprecated(since = "7.0.0", forRemoval = true)
21     private static final class Proxy implements Externalizable {
22         @java.io.Serial
23         private static final long serialVersionUID = 1L;
24
25         private UpdateElectionTerm updateElectionTerm;
26
27         // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
28         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
29         @SuppressWarnings("checkstyle:RedundantModifier")
30         public Proxy() {
31             // For Externalizable
32         }
33
34         Proxy(final UpdateElectionTerm updateElectionTerm) {
35             this.updateElectionTerm = updateElectionTerm;
36         }
37
38         @Override
39         public void writeExternal(final ObjectOutput out) throws IOException {
40             out.writeLong(updateElectionTerm.currentTerm);
41             out.writeObject(updateElectionTerm.votedFor);
42         }
43
44         @Override
45         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
46             updateElectionTerm = new UpdateElectionTerm(in.readLong(), (String) in.readObject());
47         }
48
49         @java.io.Serial
50         private Object readResolve() {
51             return updateElectionTerm;
52         }
53     }
54
55     @java.io.Serial
56     private static final long serialVersionUID = 1L;
57
58     private final long currentTerm;
59     private final String votedFor;
60
61     public UpdateElectionTerm(final long currentTerm, final String votedFor) {
62         this.currentTerm = currentTerm;
63         this.votedFor = votedFor;
64     }
65
66     public long getCurrentTerm() {
67         return currentTerm;
68     }
69
70     public String getVotedFor() {
71         return votedFor;
72     }
73
74     @java.io.Serial
75     private Object writeReplace() {
76         return new UT(this);
77     }
78
79     @Override
80     public String toString() {
81         return "UpdateElectionTerm [currentTerm=" + currentTerm + ", votedFor=" + votedFor + "]";
82     }
83 }
84