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 com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.VisibleForTesting;
14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15 import java.io.Externalizable;
16 import java.io.IOException;
17 import java.io.ObjectInput;
18 import java.io.ObjectOutput;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
23 * Encapsulates the snapshot State for a Shard.
25 * @author Thomas Pantelis
27 public final class ShardSnapshotState implements Snapshot.State {
28 interface SerialForm extends Externalizable {
30 ShardSnapshotState snapshotState();
32 void resolveTo(@NonNull ShardSnapshotState newSnapshotState);
37 default void readExternal(final ObjectInput in) throws IOException {
38 resolveTo(ShardDataTreeSnapshot.deserialize(in));
42 default void writeExternal(final ObjectOutput out) throws IOException {
43 snapshotState().getSnapshot().serialize(out);
47 @Deprecated(since = "7.0.0", forRemoval = true)
48 private static final class Proxy implements SerialForm {
50 private static final long serialVersionUID = 1L;
52 private ShardSnapshotState snapshotState;
54 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
55 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
56 @SuppressWarnings("checkstyle:RedundantModifier")
62 public ShardSnapshotState snapshotState() {
67 public void resolveTo(final ShardSnapshotState newSnapshotState) {
68 snapshotState = requireNonNull(newSnapshotState);
72 public Object readResolve() {
73 return verifyNotNull(snapshotState);
78 private static final long serialVersionUID = 1L;
80 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
81 + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
82 + "aren't serialized. FindBugs does not recognize this.")
83 private final @NonNull ShardDataTreeSnapshot snapshot;
84 private final boolean migrated;
87 public ShardSnapshotState(final @NonNull ShardDataTreeSnapshot snapshot, final boolean migrated) {
88 this.snapshot = requireNonNull(snapshot);
89 this.migrated = migrated;
92 public ShardSnapshotState(final @NonNull ShardDataTreeSnapshot snapshot) {
93 this(snapshot, false);
96 public @NonNull ShardDataTreeSnapshot getSnapshot() {
101 public boolean needsMigration() {
106 private Object writeReplace() {