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