From 763995ce31cdaed38be580781df1f5c20edf5225 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Tue, 30 May 2017 09:16:28 -0400 Subject: [PATCH] Remove deprecated NormalizedNodeInputStreamReader ctor The intent is for NormalizedNodeInputStreamReader to be package-scoped and to create instances via NormalizedNodeInputOutput#newDataInput. Thus the deprecated public constructor was removed and the remaining users were converted to use NormalizedNodeInputOutput#newDataInput. However newDataInput has the side-effect of validating the input stream first which failed for a couple users who need to lazily do the validation so I added a newDataInputWithoutValidation method. Change-Id: Ieb97ab77d05d7a4401dd0526cd4df3a5eafc9eda Signed-off-by: Tom Pantelis --- .../stream/NormalizedNodeInputOutput.java | 27 ++++++++++++++++++- .../NormalizedNodeInputStreamReader.java | 10 ------- .../node/utils/stream/SerializationUtils.java | 2 +- .../SampleNormalizedNodeSerializable.java | 2 +- .../datastore/messages/DataChanged.java | 3 +-- .../MutableCompositeModification.java | 3 +-- .../DataTreeCandidateInputOutput.java | 3 +-- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java index 5b93b274e0..486891dfd5 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java @@ -19,6 +19,14 @@ public final class NormalizedNodeInputOutput { throw new UnsupportedOperationException(); } + /** + * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method first reads + * and validates that the input contains a valid NormalizedNode stream. + * + * @param input the DataInput to read from + * @return a new {@link NormalizedNodeDataInput} instance + * @throws IOException if an error occurs reading from the input + */ public static NormalizedNodeDataInput newDataInput(@Nonnull final DataInput input) throws IOException { final byte marker = input.readByte(); if (marker != TokenTypes.SIGNATURE_MARKER) { @@ -34,7 +42,24 @@ public final class NormalizedNodeInputOutput { } } - public static NormalizedNodeDataOutput newDataOutput(@Nonnull final DataOutput output) throws IOException { + /** + * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method does not + * perform any initial validation of the input stream. + * + * @param input the DataInput to read from + * @return a new {@link NormalizedNodeDataInput} instance + */ + public static NormalizedNodeDataInput newDataInputWithoutValidation(@Nonnull final DataInput input) { + return new NormalizedNodeInputStreamReader(input, false); + } + + /** + * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output. + * + * @param output the DataOutput to write to + * @return a new {@link NormalizedNodeDataOutput} instance + */ + public static NormalizedNodeDataOutput newDataOutput(@Nonnull final DataOutput output) { return new NormalizedNodeOutputStreamWriter(output); } } diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java index 4cc63d06b1..989884cebd 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java @@ -74,16 +74,6 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput private boolean readSignatureMarker = true; - /** - * Constructs an instance. - * - * @deprecated Use {@link NormalizedNodeInputOutput#newDataInput(DataInput)} instead. - */ - @Deprecated - public NormalizedNodeInputStreamReader(final DataInput input) { - this(input, false); - } - NormalizedNodeInputStreamReader(final DataInput input, final boolean versionChecked) { this.input = Preconditions.checkNotNull(input); readSignatureMarker = !versionChecked; diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SerializationUtils.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SerializationUtils.java index fc0497280c..e4fd9363a6 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SerializationUtils.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SerializationUtils.java @@ -31,7 +31,7 @@ public final class SerializationUtils { void apply(T instance, YangInstanceIdentifier path, NormalizedNode node); } - private static NormalizedNodeDataOutput streamWriter(DataOutput out) throws IOException { + private static NormalizedNodeDataOutput streamWriter(DataOutput out) { NormalizedNodeDataOutput streamWriter = REUSABLE_WRITER_TL.get(); if (streamWriter == null) { streamWriter = NormalizedNodeInputOutput.newDataOutput(out); diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SampleNormalizedNodeSerializable.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SampleNormalizedNodeSerializable.java index 365dab7d7b..ea89e2096a 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SampleNormalizedNodeSerializable.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SampleNormalizedNodeSerializable.java @@ -32,7 +32,7 @@ public class SampleNormalizedNodeSerializable implements Serializable { private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException, URISyntaxException { - NormalizedNodeDataInput reader = new NormalizedNodeInputStreamReader(stream); + NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(stream); this.input = reader.readNormalizedNode(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChanged.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChanged.java index c48adf2d80..3cc6d041d8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChanged.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChanged.java @@ -18,7 +18,6 @@ import org.opendaylight.controller.cluster.datastore.DataStoreVersions; import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput; import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput; import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput; -import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputStreamReader; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; import org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent; @@ -46,7 +45,7 @@ public class DataChanged implements Externalizable { public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { in.readShort(); // Read the version - NormalizedNodeDataInput streamReader = new NormalizedNodeInputStreamReader(in); + NormalizedNodeDataInput streamReader = NormalizedNodeInputOutput.newDataInputWithoutValidation(in); // Note: the scope passed to builder is not actually used. Builder builder = DOMImmutableDataChangeEvent.builder(DataChangeScope.SUBTREE); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/MutableCompositeModification.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/MutableCompositeModification.java index f2a8c00d19..5a2c8054be 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/MutableCompositeModification.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/MutableCompositeModification.java @@ -18,7 +18,6 @@ import java.util.List; import org.opendaylight.controller.cluster.datastore.DataStoreVersions; import org.opendaylight.controller.cluster.datastore.messages.VersionedExternalizableMessage; import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput; -import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputStreamReader; import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils; import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; @@ -91,7 +90,7 @@ public class MutableCompositeModification extends VersionedExternalizableMessage int size = in.readInt(); if (size > 1) { - SerializationUtils.REUSABLE_READER_TL.set(new NormalizedNodeInputStreamReader(in)); + SerializationUtils.REUSABLE_READER_TL.set(NormalizedNodeInputOutput.newDataInputWithoutValidation(in)); } try { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DataTreeCandidateInputOutput.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DataTreeCandidateInputOutput.java index c2a873331d..fb9b07a5d0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DataTreeCandidateInputOutput.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/DataTreeCandidateInputOutput.java @@ -17,7 +17,6 @@ import java.util.Collections; import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput; import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput; import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput; -import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputStreamReader; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; @@ -98,7 +97,7 @@ public final class DataTreeCandidateInputOutput { } public static DataTreeCandidate readDataTreeCandidate(final DataInput in) throws IOException { - final NormalizedNodeDataInput reader = new NormalizedNodeInputStreamReader(in); + final NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(in); final YangInstanceIdentifier rootPath = reader.readYangInstanceIdentifier(); final byte type = reader.readByte(); -- 2.36.6