Remove NormalizedNodeOutputStreamWriter 70/84670/3
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 7 Sep 2019 09:22:39 +0000 (11:22 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 24 Sep 2019 05:18:09 +0000 (07:18 +0200)
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 <robert.varga@pantheon.tech>
(cherry picked from commit 68f179dcd8483dd7f681e134268a1eee29d09d55)
(cherry picked from commit 65f9a729fde4ad25cea4b81eede806a299e426b4)

opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumNormalizedNodeOutputStreamWriter.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java [deleted file]
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/SampleNormalizedNodeSerializable.java

index f4138488b522d24a2594e8f33de1c001b6878e11..6a1cb337313fb32f7a01b1c76558922e07f1f62b 100755 (executable)
@@ -36,6 +36,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.
+ *
+ * <p>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);
 
index ccc5e96249efb183a35f24004d05cfdeda3b6de9..cceb16c2e6cea9cfc2ed606e4dbeab613bd7ecbf 100644 (file)
@@ -26,23 +26,23 @@ import org.opendaylight.yangtools.yang.common.QNameModule;
  * <p>Based on the each node, the node type is also written to the stream, that helps in reconstructing the object,
  * while reading.
  */
-class LithiumNormalizedNodeOutputStreamWriter extends AbstractLithiumDataOutput {
+final class LithiumNormalizedNodeOutputStreamWriter extends AbstractLithiumDataOutput {
     LithiumNormalizedNodeOutputStreamWriter(final DataOutput output) {
         super(output);
     }
 
     @Override
-    protected final short streamVersion() {
+    protected short streamVersion() {
         return TokenTypes.LITHIUM_VERSION;
     }
 
     @Override
-    protected final void writeQName(final QName qname) throws IOException {
+    protected void writeQName(final QName qname) throws IOException {
         defaultWriteQName(qname);
     }
 
     @Override
-    final void writeModule(final QNameModule module) throws IOException {
+    void writeModule(final QNameModule module) throws IOException {
         defaultWriteModule(module);
     }
 }
index 7a8c267ad1abe23167f72ca7adc62bba90de545d..b609287d1592c7ef87ca12acdfdc58307aeadc20 100644 (file)
@@ -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 LithiumNormalizedNodeOutputStreamWriter(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 (file)
index a9515d2..0000000
+++ /dev/null
@@ -1,31 +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.
- *
- * <p>Based on the each node, the node type is also written to the stream, that helps in reconstructing the object,
- * while reading.
- */
-// FIXME: CONTROLLER-1888: switch this to Sodium once we have a corresponding datastore version
-class NormalizedNodeOutputStreamWriter extends LithiumNormalizedNodeOutputStreamWriter {
-    NormalizedNodeOutputStreamWriter(final DataOutput output) {
-        super(output);
-    }
-}
index 147cc663d956ca4d7f4bac89d187407b575cfb38..e1bf0447e657c88162a284f384efe6c684742245 100644 (file)
@@ -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();
index 6b24b05a735b912b15dcacec61d69a6898521f8c..0ce7331e0f46e4253a0aac8b43eb7e5b163d8086 100644 (file)
@@ -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);
     }
 
 }