X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fpersisted%2FShardSnapshotState.java;h=a8c7393b52f6804872e50a9db803aa279bf404d2;hp=5275582f079ba188eb71bf7fcc1c15bd6c082af1;hb=HEAD;hpb=aafb8cb044e992dd784d1f4f66508599cc4cd588 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardSnapshotState.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardSnapshotState.java index 5275582f07..c06c5cf318 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardSnapshotState.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/ShardSnapshotState.java @@ -7,13 +7,11 @@ */ package org.opendaylight.controller.cluster.datastore.persisted; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; + +import com.google.common.annotations.VisibleForTesting; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import javax.annotation.Nonnull; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.raft.persisted.Snapshot; /** @@ -21,55 +19,37 @@ import org.opendaylight.controller.cluster.raft.persisted.Snapshot; * * @author Thomas Pantelis */ -public class ShardSnapshotState implements Snapshot.State { +public final class ShardSnapshotState implements Snapshot.State { + @java.io.Serial private static final long serialVersionUID = 1L; - private static final class Proxy implements Externalizable { - private static final long serialVersionUID = 1L; - - private ShardSnapshotState snapshotState; - - // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't - // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection. - @SuppressWarnings("checkstyle:RedundantModifier") - public Proxy() { - // For Externalizable - } - - Proxy(final ShardSnapshotState snapshotState) { - this.snapshotState = snapshotState; - } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - snapshotState.snapshot.serialize(out); - } - - @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - snapshotState = new ShardSnapshotState(ShardDataTreeSnapshot.deserialize(in)); - } - - private Object readResolve() { - return snapshotState; - } - } - @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class " + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class " + "aren't serialized. FindBugs does not recognize this.") - private final ShardDataTreeSnapshot snapshot; + private final @NonNull ShardDataTreeSnapshot snapshot; + private final boolean migrated; + + @VisibleForTesting + public ShardSnapshotState(final @NonNull ShardDataTreeSnapshot snapshot, final boolean migrated) { + this.snapshot = requireNonNull(snapshot); + this.migrated = migrated; + } - public ShardSnapshotState(@Nonnull final ShardDataTreeSnapshot snapshot) { - this.snapshot = Preconditions.checkNotNull(snapshot); + public ShardSnapshotState(final @NonNull ShardDataTreeSnapshot snapshot) { + this(snapshot, false); } - @Nonnull - public ShardDataTreeSnapshot getSnapshot() { + public @NonNull ShardDataTreeSnapshot getSnapshot() { return snapshot; } + @Override + public boolean needsMigration() { + return migrated; + } + + @java.io.Serial private Object writeReplace() { - return new Proxy(this); + return new SS(this); } }