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%2FMetadataShardDataTreeSnapshot.java;h=fa8877fd9fef9b7d3d6f10d475c59793cd92fffd;hp=8cde0d953287691b440d10476ecbe6e801710383;hb=6a32d897d2dcb4fa54977b3b2defe76dc0a5d5e2;hpb=6276a65120a674b545ea787a5e1d9311bcdbf2af diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/MetadataShardDataTreeSnapshot.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/MetadataShardDataTreeSnapshot.java index 8cde0d9532..fa8877fd9f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/MetadataShardDataTreeSnapshot.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/MetadataShardDataTreeSnapshot.java @@ -8,17 +8,19 @@ package org.opendaylight.controller.cluster.datastore.persisted; import com.google.common.annotations.Beta; +import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.base.Verify; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.Serializable; import java.util.Map; -import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +31,8 @@ import org.slf4j.LoggerFactory; * @author Robert Varga */ @Beta -public final class MetadataShardDataTreeSnapshot extends AbstractVersionedShardDataTreeSnapshot implements Serializable { +public final class MetadataShardDataTreeSnapshot extends AbstractVersionedShardDataTreeSnapshot + implements Serializable { private static final class Proxy implements Externalizable { private static final long serialVersionUID = 1L; private static final Logger LOG = LoggerFactory.getLogger(MetadataShardDataTreeSnapshot.class); @@ -37,6 +40,9 @@ public final class MetadataShardDataTreeSnapshot extends AbstractVersionedShardD private Map>, ShardDataTreeSnapshotMetadata> metadata; private NormalizedNode rootNode; + // 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 } @@ -53,7 +59,7 @@ public final class MetadataShardDataTreeSnapshot extends AbstractVersionedShardD out.writeObject(m); } - SerializationUtils.serializeNormalizedNode(rootNode, out); + SerializationUtils.writeNormalizedNode(out, rootNode); } @Override @@ -62,8 +68,8 @@ public final class MetadataShardDataTreeSnapshot extends AbstractVersionedShardD Preconditions.checkArgument(metaSize >= 0, "Invalid negative metadata map length %s", metaSize); // Default pre-allocate is 4, which should be fine - final Builder>, ShardDataTreeSnapshotMetadata> metaBuilder = - ImmutableMap.builder(); + final Builder>, ShardDataTreeSnapshotMetadata> + metaBuilder = ImmutableMap.builder(); for (int i = 0; i < metaSize; ++i) { final ShardDataTreeSnapshotMetadata m = (ShardDataTreeSnapshotMetadata) in.readObject(); if (m != null) { @@ -84,7 +90,12 @@ public final class MetadataShardDataTreeSnapshot extends AbstractVersionedShardD private static final long serialVersionUID = 1L; + @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 Map>, ShardDataTreeSnapshotMetadata> metadata; + + @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "See above justification.") private final NormalizedNode rootNode; public MetadataShardDataTreeSnapshot(final NormalizedNode rootNode) { @@ -115,4 +126,8 @@ public final class MetadataShardDataTreeSnapshot extends AbstractVersionedShardD return new Proxy(this); } + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("metadata", metadata).toString(); + } }