5650360c5ff89d24a09d1021066611fea44116f9
[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         public Proxy() {
28             // For Externalizable
29         }
30
31         Proxy(final DeleteEntries deleteEntries) {
32             this.deleteEntries = deleteEntries;
33         }
34
35         @Override
36         public void writeExternal(final ObjectOutput out) throws IOException {
37             out.writeLong(deleteEntries.fromIndex);
38          }
39
40         @Override
41         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
42             deleteEntries = new DeleteEntries(in.readLong());
43         }
44
45         private Object readResolve() {
46             return deleteEntries;
47         }
48     }
49
50     private static final long serialVersionUID = 1L;
51
52     private final long fromIndex;
53     private final boolean migrated;
54
55     private DeleteEntries(final long fromIndex, final boolean migrated) {
56         this.fromIndex = fromIndex;
57         this.migrated = migrated;
58     }
59
60     public DeleteEntries(final long fromIndex) {
61         this(fromIndex, false);
62     }
63
64     public long getFromIndex() {
65         return fromIndex;
66     }
67
68     @Override
69     public boolean isMigrated() {
70         return migrated;
71     }
72
73     @Override
74     public Object writeReplace() {
75         return new Proxy(this);
76     }
77
78     @Deprecated
79     public static DeleteEntries createMigrated(final long fromIndex) {
80         return new DeleteEntries(fromIndex, true);
81     }
82
83     @Override
84     public String toString() {
85         return "DeleteEntries [fromIndex=" + fromIndex + "]";
86     }
87 }