*/
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.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.io.OutputStream;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
/**
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
- snapshotState.snapshot.serialize(toOutputStream(out));
- }
-
- private OutputStream toOutputStream(final ObjectOutput out) {
- if (out instanceof OutputStream) {
- return (OutputStream) out;
- }
-
- return new OutputStream() {
- @Override
- public void write(int value) throws IOException {
- out.write(value);
- }
- };
+ snapshotState.snapshot.serialize(out);
}
@Override
- public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
- snapshotState = new ShardSnapshotState(ShardDataTreeSnapshot.deserialize(toInputStream(in)));
- }
-
- private InputStream toInputStream(final ObjectInput in) {
- if (in instanceof InputStream) {
- return (InputStream) in;
- }
-
- return new InputStream() {
- @Override
- public int read() throws IOException {
- return in.read();
- }
- };
+ public void readExternal(final ObjectInput in) throws IOException {
+ snapshotState = ShardDataTreeSnapshot.deserialize(in);
}
private Object readResolve() {
@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;
- public ShardSnapshotState(@Nonnull ShardDataTreeSnapshot snapshot) {
- this.snapshot = Preconditions.checkNotNull(snapshot);
+ @VisibleForTesting
+ public ShardSnapshotState(final @NonNull ShardDataTreeSnapshot snapshot, final boolean migrated) {
+ this.snapshot = requireNonNull(snapshot);
+ this.migrated = migrated;
}
- @Nonnull
- public ShardDataTreeSnapshot getSnapshot() {
+ public ShardSnapshotState(final @NonNull ShardDataTreeSnapshot snapshot) {
+ this(snapshot, false);
+ }
+
+ public @NonNull ShardDataTreeSnapshot getSnapshot() {
return snapshot;
}
- @SuppressWarnings("static-method")
+ @Override
+ public boolean needsMigration() {
+ return migrated;
+ }
+
private Object writeReplace() {
return new Proxy(this);
}