Trigger snapshots on legacy persisted entries
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / persisted / ApplyJournalEntries.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 akka.dispatch.ControlMessage;
11 import java.io.Externalizable;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import java.io.Serializable;
16
17 /**
18  * This is an internal message that is stored in the akka's persistent journal. During recovery, this
19  * message is used to apply recovered journal entries to the state whose indexes range from the context's
20  * current lastApplied index to "toIndex" contained in the message. This message is sent internally from a
21  * behavior to the RaftActor to persist.
22  *
23  * @author Thomas Pantelis
24  */
25 public sealed class ApplyJournalEntries implements Serializable, ControlMessage {
26     @Deprecated(since = "7.0.0", forRemoval = true)
27     private static final class Legacy extends ApplyJournalEntries implements LegacySerializable {
28         @java.io.Serial
29         private static final long serialVersionUID = 1L;
30
31         Legacy(final long toIndex) {
32             super(toIndex);
33         }
34     }
35
36     @Deprecated(since = "7.0.0", forRemoval = true)
37     private static final class Proxy implements Externalizable {
38         @java.io.Serial
39         private static final long serialVersionUID = 1L;
40
41         private ApplyJournalEntries applyEntries = null;
42
43         // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
44         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
45         @SuppressWarnings("checkstyle:RedundantModifier")
46         public Proxy() {
47             // For Externalizable
48         }
49
50         @Override
51         public void writeExternal(final ObjectOutput out) throws IOException {
52             out.writeLong(applyEntries.toIndex);
53         }
54
55         @Override
56         public void readExternal(final ObjectInput in) throws IOException {
57             applyEntries = new Legacy(in.readLong());
58         }
59
60         @java.io.Serial
61         private Object readResolve() {
62             return applyEntries;
63         }
64     }
65
66     @java.io.Serial
67     private static final long serialVersionUID = 1L;
68
69     private final long toIndex;
70
71     public ApplyJournalEntries(final long toIndex) {
72         this.toIndex = toIndex;
73     }
74
75     public final long getToIndex() {
76         return toIndex;
77     }
78
79     @java.io.Serial
80     public final Object writeReplace() {
81         return new AJE(this);
82     }
83
84     @Override
85     public final String toString() {
86         return "ApplyJournalEntries [toIndex=" + toIndex + "]";
87     }
88 }