Remove NormalizedNodeOutputStreamWriter 85/84585/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 7 Sep 2019 09:22:39 +0000 (11:22 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 23 Sep 2019 03:37:04 +0000 (05:37 +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)

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/NeonSR2NormalizedNodeOutputStreamWriter.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 b096a445f387dca2d84a05159f370c6240dba27c..2224357d42d96b3c5c9e1bdcdfd0c618b3631233 100755 (executable)
@@ -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.
+ *
+ * <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 e38c34aa9600e6aeb2837945beb6fc43228bcf91..b3183a3d95ee93fbcf7194bca6cb19223923a666 100644 (file)
@@ -29,7 +29,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.Augmentat
  * <p>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<AugmentationIdentifier, Integer> aidCodeMap = new HashMap<>();
     private final Map<QNameModule, Integer> moduleCodeMap = new HashMap<>();
     private final Map<QName, Integer> 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
index 7a8c267ad1abe23167f72ca7adc62bba90de545d..87aec1dc1188536065d84c7587e056b67c08b8a5 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 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 (file)
index 84e7f33..0000000
+++ /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.
- *
- * <p>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);
-    }
-}
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);
     }
 
 }