ad334f4c156ad0dc43aaf4eb69cf0e3184e4a039
[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 class ApplyJournalEntries implements Serializable, ControlMessage {
26     @Deprecated(since = "7.0.0", forRemoval = true)
27     private static final class Proxy implements Externalizable {
28         @java.io.Serial
29         private static final long serialVersionUID = 1L;
30
31         private ApplyJournalEntries applyEntries;
32
33         // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
34         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
35         @SuppressWarnings("checkstyle:RedundantModifier")
36         public Proxy() {
37             // For Externalizable
38         }
39
40         Proxy(final ApplyJournalEntries applyEntries) {
41             this.applyEntries = applyEntries;
42         }
43
44         @Override
45         public void writeExternal(final ObjectOutput out) throws IOException {
46             out.writeLong(applyEntries.toIndex);
47         }
48
49         @Override
50         public void readExternal(final ObjectInput in) throws IOException {
51             applyEntries = new ApplyJournalEntries(in.readLong());
52         }
53
54         @java.io.Serial
55         private Object readResolve() {
56             return applyEntries;
57         }
58     }
59
60     @java.io.Serial
61     private static final long serialVersionUID = 1L;
62
63     private final long toIndex;
64
65     public ApplyJournalEntries(final long toIndex) {
66         this.toIndex = toIndex;
67     }
68
69     public long getToIndex() {
70         return toIndex;
71     }
72
73     private Object writeReplace() {
74         return new AJE(this);
75     }
76
77     @Override
78     public String toString() {
79         return "ApplyJournalEntries [toIndex=" + toIndex + "]";
80     }
81 }