Remove unneeded SuppressWarnings
[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, MigratedSerializable {
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     private final boolean migrated;
57
58     private UpdateElectionTerm(final long currentTerm, final String votedFor, final boolean migrated) {
59         this.currentTerm = currentTerm;
60         this.votedFor = votedFor;
61         this.migrated = migrated;
62     }
63
64     public UpdateElectionTerm(final long currentTerm, final String votedFor) {
65         this(currentTerm, votedFor, false);
66     }
67
68     public long getCurrentTerm() {
69         return currentTerm;
70     }
71
72     public String getVotedFor() {
73         return votedFor;
74     }
75
76     @Override
77     public boolean isMigrated() {
78         return migrated;
79     }
80
81     @Override
82     public Object writeReplace() {
83         return new Proxy(this);
84     }
85
86     @Deprecated
87     public static UpdateElectionTerm createMigrated(final long currentTerm, final String votedFor) {
88         return new UpdateElectionTerm(currentTerm, votedFor, true);
89     }
90
91     @Override
92     public String toString() {
93         return "UpdateElectionTerm [currentTerm=" + currentTerm + ", votedFor=" + votedFor + "]";
94     }
95 }
96