2 * Copyright (c) 2017 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.datastore.persisted;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.VisibleForTesting;
13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14 import java.io.Externalizable;
15 import java.io.IOException;
16 import java.io.ObjectInput;
17 import java.io.ObjectOutput;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
22 * Encapsulates the snapshot State for a Shard.
24 * @author Thomas Pantelis
26 public class ShardSnapshotState implements Snapshot.State {
27 private static final long serialVersionUID = 1L;
29 private static final class Proxy implements Externalizable {
30 private static final long serialVersionUID = 1L;
32 private ShardSnapshotState snapshotState;
34 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
35 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
36 @SuppressWarnings("checkstyle:RedundantModifier")
41 Proxy(final ShardSnapshotState snapshotState) {
42 this.snapshotState = snapshotState;
46 public void writeExternal(final ObjectOutput out) throws IOException {
47 snapshotState.snapshot.serialize(out);
51 public void readExternal(final ObjectInput in) throws IOException {
52 snapshotState = ShardDataTreeSnapshot.deserialize(in);
55 private Object readResolve() {
60 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
61 + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
62 + "aren't serialized. FindBugs does not recognize this.")
63 private final @NonNull ShardDataTreeSnapshot snapshot;
64 private final boolean migrated;
67 public ShardSnapshotState(final @NonNull ShardDataTreeSnapshot snapshot, final boolean migrated) {
68 this.snapshot = requireNonNull(snapshot);
69 this.migrated = migrated;
72 public ShardSnapshotState(final @NonNull ShardDataTreeSnapshot snapshot) {
73 this(snapshot, false);
76 public @NonNull ShardDataTreeSnapshot getSnapshot() {
81 public boolean needsMigration() {
85 private Object writeReplace() {
86 return new Proxy(this);