*/
package org.opendaylight.controller.cluster.datastore.persisted;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.ImmutableList;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.List;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
/**
*
* @author Thomas Pantelis
*/
-public class DatastoreSnapshot implements Serializable {
+public final class DatastoreSnapshot implements Serializable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
- private static final class Proxy implements Externalizable {
- private static final long serialVersionUID = 1L;
-
- private DatastoreSnapshot datastoreSnapshot;
-
- // 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 DatastoreSnapshot datastoreSnapshot) {
- this.datastoreSnapshot = datastoreSnapshot;
- }
-
- @Override
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(datastoreSnapshot.type);
- out.writeObject(datastoreSnapshot.shardManagerSnapshot);
-
- out.writeInt(datastoreSnapshot.shardSnapshots.size());
- for (ShardSnapshot shardSnapshot: datastoreSnapshot.shardSnapshots) {
- out.writeObject(shardSnapshot);
- }
- }
-
- @Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- String type = (String)in.readObject();
- ShardManagerSnapshot shardManagerSnapshot = (ShardManagerSnapshot) in.readObject();
-
- int size = in.readInt();
- List<ShardSnapshot> shardSnapshots = new ArrayList<>(size);
- for (int i = 0; i < size; i++) {
- shardSnapshots.add((ShardSnapshot) in.readObject());
- }
-
- datastoreSnapshot = new DatastoreSnapshot(type, shardManagerSnapshot, shardSnapshots);
- }
-
- private Object readResolve() {
- return datastoreSnapshot;
- }
- }
-
- private final String type;
+ private final @NonNull String type;
private final ShardManagerSnapshot shardManagerSnapshot;
- private final List<ShardSnapshot> shardSnapshots;
+ private final @NonNull ImmutableList<ShardSnapshot> shardSnapshots;
- public DatastoreSnapshot(@Nonnull String type, @Nullable ShardManagerSnapshot shardManagerSnapshot,
- @Nonnull List<ShardSnapshot> shardSnapshots) {
- this.type = Preconditions.checkNotNull(type);
+ public DatastoreSnapshot(final @NonNull String type, final @Nullable ShardManagerSnapshot shardManagerSnapshot,
+ final @NonNull List<ShardSnapshot> shardSnapshots) {
+ this.type = requireNonNull(type);
this.shardManagerSnapshot = shardManagerSnapshot;
- this.shardSnapshots = ImmutableList.copyOf(Preconditions.checkNotNull(shardSnapshots));
+ this.shardSnapshots = ImmutableList.copyOf(shardSnapshots);
}
- @Nonnull
- public String getType() {
+ public @NonNull String getType() {
return type;
}
- @Nullable
- public ShardManagerSnapshot getShardManagerSnapshot() {
+ public @Nullable ShardManagerSnapshot getShardManagerSnapshot() {
return shardManagerSnapshot;
}
- @Nonnull
- public List<ShardSnapshot> getShardSnapshots() {
+ public @NonNull List<ShardSnapshot> getShardSnapshots() {
return shardSnapshots;
}
+ @java.io.Serial
private Object writeReplace() {
- return new Proxy(this);
+ return new DS(this);
}
- public static class ShardSnapshot implements Serializable {
+ public static final class ShardSnapshot implements Serializable {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
- private static final class Proxy implements Externalizable {
- private static final long serialVersionUID = 1L;
-
- private ShardSnapshot shardSnapshot;
-
- // 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 ShardSnapshot shardSnapshot) {
- this.shardSnapshot = shardSnapshot;
- }
-
- @Override
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(shardSnapshot.name);
- out.writeObject(shardSnapshot.snapshot);
- }
-
- @Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- shardSnapshot = new ShardSnapshot((String)in.readObject(), (Snapshot) in.readObject());
- }
-
- private Object readResolve() {
- return shardSnapshot;
- }
- }
-
- private final String name;
- private final Snapshot snapshot;
+ private final @NonNull String name;
+ private final @NonNull Snapshot snapshot;
- public ShardSnapshot(@Nonnull String name, @Nonnull Snapshot snapshot) {
- this.name = Preconditions.checkNotNull(name);
- this.snapshot = Preconditions.checkNotNull(snapshot);
+ public ShardSnapshot(final @NonNull String name, final @NonNull Snapshot snapshot) {
+ this.name = requireNonNull(name);
+ this.snapshot = requireNonNull(snapshot);
}
- @Nonnull
- public String getName() {
+ public @NonNull String getName() {
return name;
}
- @Nonnull
- public Snapshot getSnapshot() {
+ public @NonNull Snapshot getSnapshot() {
return snapshot;
}
+ @java.io.Serial
private Object writeReplace() {
- return new Proxy(this);
+ return new DSS(this);
}
}
}