2 * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.raft.persisted;
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;
17 * This is an internal message that is stored in the akka's persistent journal. During recovery, this
18 * message is used to apply recovered journal entries to the state whose indexes range from the context's
19 * current lastApplied index to "toIndex" contained in the message. This message is sent internally from a
20 * behavior to the RaftActor to persist.
22 * @author Thomas Pantelis
24 public class ApplyJournalEntries implements Serializable, MigratedSerializable {
25 private static final class Proxy implements Externalizable {
26 private static final long serialVersionUID = 1L;
28 private ApplyJournalEntries applyEntries;
34 Proxy(final ApplyJournalEntries applyEntries) {
35 this.applyEntries = applyEntries;
39 public void writeExternal(final ObjectOutput out) throws IOException {
40 out.writeLong(applyEntries.toIndex);
44 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
45 applyEntries = new ApplyJournalEntries(in.readLong());
48 private Object readResolve() {
53 private static final long serialVersionUID = 1L;
55 private final long toIndex;
56 private final boolean migrated;
58 private ApplyJournalEntries(final long toIndex, final boolean migrated) {
59 this.toIndex = toIndex;
60 this.migrated = migrated;
63 public ApplyJournalEntries(final long toIndex) {
67 public long getToIndex() {
72 public boolean isMigrated() {
77 public Object writeReplace() {
78 return new Proxy(this);
82 public static ApplyJournalEntries createMigrated(final long fromIndex) {
83 return new ApplyJournalEntries(fromIndex, true);
87 public String toString() {
88 return "ApplyJournalEntries [toIndex=" + toIndex + "]";