Remove ensureHeaderWritten() from writeNode() 91/84591/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Sep 2019 20:05:19 +0000 (22:05 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 23 Sep 2019 03:38:09 +0000 (05:38 +0200)
This updates documentation of AbstractNormalizedNodeDataOutput
to make it clear that the NormalizedNodeStreamWriter aspect of
it is an implementation detail and that the stream has been
header-initialized by the time any of those methods are called.

The clarification renders calling ensureHeaderWritten() from
writeNode() superfluous, as at that point it is guaranteed to
be a no-op.

Change-Id: I85a5c1304849fe5bc737fa51bd4b40ff2dd8c08c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 1165ba34382d4c99394e64d71ffee783d6a8fe82)

opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java

index fb677a33df7ec4a34174f34f317d74837cd98a18..bb6e97a00e2b36f4460004e0ff2074b352ee0310 100755 (executable)
@@ -40,18 +40,13 @@ 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.
+ * Abstract base class for implementing {@link NormalizedNodeDataOutput} contract. This class uses
+ * {@link NormalizedNodeStreamWriter} as an internal interface for performing the actual NormalizedNode writeout,
+ * i.e. it will defer to a {@link NormalizedNodeWriter} instance.
  *
- * <p>Based on the each node, the node type is also written to the stream, that helps in reconstructing the object,
- * while reading.
+ * <p>
+ * As such, this is an implementation detail not exposed from this package, hence implementations can rely on the
+ * stream being initialized with a header and version.
  */
 abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOutput, NormalizedNodeStreamWriter {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractNormalizedNodeDataOutput.class);
@@ -67,6 +62,10 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         this.output = requireNonNull(output);
     }
 
+    final DataOutput output() {
+        return output;
+    }
+
     private void ensureHeaderWritten() throws IOException {
         if (!headerWritten) {
             output.writeByte(TokenTypes.SIGNATURE_MARKER);
@@ -344,8 +343,6 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         requireNonNull(arg, "Node identifier should not be null");
         checkState(!inSimple, "Attempted to start a child in a simple node");
 
-        ensureHeaderWritten();
-
         // First write the type of node
         output.writeByte(nodeType);
         // Write Start Tag