From 68f179dcd8483dd7f681e134268a1eee29d09d55 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 7 Sep 2019 11:22:39 +0200 Subject: [PATCH 1/1] Remove NormalizedNodeOutputStreamWriter This class is tied to NeonSR2 serialization format through subclassing, where it really is a package-private detail. This leads to two concrete classes being in existence for a particular format, which simply does not make sense. Eliminating this subclass allows us to make Neon SR2 final, thus arriving and monomorphic or bimorphic invocation of all methods based on whether we have seen Lithium (well, Oxygen) format at runtime. Change-Id: I9e0463ec4879900e82cf757006dccfdbeb0d7297 Signed-off-by: Robert Varga --- .../AbstractNormalizedNodeDataOutput.java | 14 +++++++++ ...onSR2NormalizedNodeOutputStreamWriter.java | 4 +-- .../stream/NormalizedNodeInputOutput.java | 2 +- .../NormalizedNodeOutputStreamWriter.java | 30 ------------------- .../NormalizedNodeStreamReaderWriterTest.java | 2 +- .../SampleNormalizedNodeSerializable.java | 15 +++------- 6 files changed, 22 insertions(+), 45 deletions(-) delete mode 100644 opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java index b096a445f3..2224357d42 100755 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java @@ -39,6 +39,20 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * NormalizedNodeOutputStreamWriter will be used by distributed datastore to send normalized node in + * a stream. + * A stream writer wrapper around this class will write node objects to stream in recursive manner. + * for example - If you have a ContainerNode which has a two LeafNode as children, then + * you will first call + * {@link #startContainerNode(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier, int)}, + * then will call + * {@link #leafNode(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier, Object)} twice + * and then, {@link #endNode()} to end container node. + * + *

Based on the each node, the node type is also written to the stream, that helps in reconstructing the object, + * while reading. + */ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOutput, NormalizedNodeStreamWriter { private static final Logger LOG = LoggerFactory.getLogger(AbstractNormalizedNodeDataOutput.class); diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NeonSR2NormalizedNodeOutputStreamWriter.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NeonSR2NormalizedNodeOutputStreamWriter.java index e38c34aa96..b3183a3d95 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NeonSR2NormalizedNodeOutputStreamWriter.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NeonSR2NormalizedNodeOutputStreamWriter.java @@ -29,7 +29,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.Augmentat *

Based on the each node, the node type is also written to the stream, that helps in reconstructing the object, * while reading. */ -class NeonSR2NormalizedNodeOutputStreamWriter extends AbstractLithiumDataOutput { +final class NeonSR2NormalizedNodeOutputStreamWriter extends AbstractLithiumDataOutput { private final Map aidCodeMap = new HashMap<>(); private final Map moduleCodeMap = new HashMap<>(); private final Map qnameCodeMap = new HashMap<>(); @@ -44,7 +44,7 @@ class NeonSR2NormalizedNodeOutputStreamWriter extends AbstractLithiumDataOutput } @Override - public final void writeQName(final QName qname) throws IOException { + public void writeQName(final QName qname) throws IOException { final Integer value = qnameCodeMap.get(qname); if (value == null) { // Fresh QName, remember it and emit as three strings 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 7a8c267ad1..87aec1dc11 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 @@ -50,7 +50,7 @@ public final class NormalizedNodeInputOutput { * @return a new {@link NormalizedNodeDataOutput} instance */ public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output) { - return new NormalizedNodeOutputStreamWriter(output); + return new NeonSR2NormalizedNodeOutputStreamWriter(output); } /** diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java deleted file mode 100644 index 84e7f33587..0000000000 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.cluster.datastore.node.utils.stream; - -import java.io.DataOutput; - -/** - * NormalizedNodeOutputStreamWriter will be used by distributed datastore to send normalized node in - * a stream. - * A stream writer wrapper around this class will write node objects to stream in recursive manner. - * for example - If you have a ContainerNode which has a two LeafNode as children, then - * you will first call - * {@link #startContainerNode(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier, int)}, - * then will call - * {@link #leafNode(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier, Object)} twice - * and then, {@link #endNode()} to end container node. - * - *

Based on the each node, the node type is also written to the stream, that helps in reconstructing the object, - * while reading. - */ -class NormalizedNodeOutputStreamWriter extends NeonSR2NormalizedNodeOutputStreamWriter { - NormalizedNodeOutputStreamWriter(final DataOutput output) { - super(output); - } -} diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java index 147cc663d9..e1bf0447e6 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java @@ -122,7 +122,7 @@ public class NormalizedNodeStreamReaderWriterTest { public void testNormalizedNodeAndYangInstanceIdentifierStreaming() throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - NormalizedNodeOutputStreamWriter writer = new NormalizedNodeOutputStreamWriter( + NormalizedNodeDataOutput writer = NormalizedNodeInputOutput.newDataOutput( ByteStreams.newDataOutput(byteArrayOutputStream)); NormalizedNode testContainer = TestModel.createBaseTestContainerBuilder().build(); 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 6b24b05a73..0ce7331e0f 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 @@ -13,15 +13,13 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; public class SampleNormalizedNodeSerializable implements Serializable { private static final long serialVersionUID = 1L; private NormalizedNode input; - public SampleNormalizedNodeSerializable(NormalizedNode input) { + public SampleNormalizedNodeSerializable(final NormalizedNode input) { this.input = input; } @@ -29,17 +27,12 @@ public class SampleNormalizedNodeSerializable implements Serializable { return input; } - private void readObject(final ObjectInputStream stream) - throws IOException { - NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(stream); - this.input = reader.readNormalizedNode(); + private void readObject(final ObjectInputStream stream) throws IOException { + this.input = NormalizedNodeInputOutput.newDataInput(stream).readNormalizedNode(); } private void writeObject(final ObjectOutputStream stream) throws IOException { - NormalizedNodeStreamWriter writer = new NormalizedNodeOutputStreamWriter(stream); - NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(writer); - - normalizedNodeWriter.write(this.input); + NormalizedNodeInputOutput.newDataOutput(stream).writeNormalizedNode(input); } } -- 2.36.6