Fix warnings and clean up javadocs in sal-akka-raft
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / persisted / DeleteEntries.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  * Internal message that is stored in the akka's persistent journal to delete journal entries.
18  *
19  * @author Thomas Pantelis
20  */
21 public class DeleteEntries implements Serializable, MigratedSerializable {
22     private static final class Proxy implements Externalizable {
23         private static final long serialVersionUID = 1L;
24
25         private DeleteEntries deleteEntries;
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 DeleteEntries deleteEntries) {
35             this.deleteEntries = deleteEntries;
36         }
37
38         @Override
39         public void writeExternal(final ObjectOutput out) throws IOException {
40             out.writeLong(deleteEntries.fromIndex);
41         }
42
43         @Override
44         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
45             deleteEntries = new DeleteEntries(in.readLong());
46         }
47
48         private Object readResolve() {
49             return deleteEntries;
50         }
51     }
52
53     private static final long serialVersionUID = 1L;
54
55     private final long fromIndex;
56     private final boolean migrated;
57
58     private DeleteEntries(final long fromIndex, final boolean migrated) {
59         this.fromIndex = fromIndex;
60         this.migrated = migrated;
61     }
62
63     public DeleteEntries(final long fromIndex) {
64         this(fromIndex, false);
65     }
66
67     public long getFromIndex() {
68         return fromIndex;
69     }
70
71     @Override
72     public boolean isMigrated() {
73         return migrated;
74     }
75
76     @Override
77     public Object writeReplace() {
78         return new Proxy(this);
79     }
80
81     @Deprecated
82     public static DeleteEntries createMigrated(final long fromIndex) {
83         return new DeleteEntries(fromIndex, true);
84     }
85
86     @Override
87     public String toString() {
88         return "DeleteEntries [fromIndex=" + fromIndex + "]";
89     }
90 }