Add support for reusable streaming
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Jun 2019 10:26:37 +0000 (12:26 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 8 Jul 2019 08:48:19 +0000 (08:48 +0000)
With the actual implementations working on top of
NormalizedNodeStreamWriter, we gained the ability to flexibly
receive stream events.

This patch takes advantage of that flexibility by allowing
a ReusableImmutableNormalizedNodeStreamWriter to be the receiver
of the events -- thus allowing parts of the state involved in
building a NormalizedNode tree to be reused -- lowering GC
pressure.

A number of call sites, which can safely reuse such state are
converted to use the newly-introduced facility.

Change-Id: Iaf1b3ab2b2996e7004c036fc93a80a8ca8792314
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ForwardingNormalizedNodeDataInput.java
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataInput.java

index 1c160698a4b7dd7dff642ef7d31f4f34e1779dd1..a1a0d69426f31bcbf4aee4e4fc3ca244b93f65ff 100644 (file)
@@ -14,6 +14,7 @@ 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.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.ReusableImmutableNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 abstract class ForwardingNormalizedNodeDataInput extends ForwardingDataInput implements NormalizedNodeDataInput {
@@ -31,6 +32,12 @@ abstract class ForwardingNormalizedNodeDataInput extends ForwardingDataInput imp
         return delegate().readNormalizedNode();
     }
 
+    @Override
+    public final NormalizedNode<?, ?> readNormalizedNode(final ReusableImmutableNormalizedNodeStreamWriter writer)
+            throws IOException {
+        return delegate().readNormalizedNode(writer);
+    }
+
     @Override
     public final YangInstanceIdentifier readYangInstanceIdentifier() throws IOException {
         return delegate().readYangInstanceIdentifier();
index 9dda8bf6e47f5c1664b1060d7cc085196f6a64fa..57d41d58354a916e401ae1e2424b1db167386ddb 100644 (file)
@@ -19,6 +19,7 @@ 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.impl.schema.ImmutableNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
+import org.opendaylight.yangtools.yang.data.impl.schema.ReusableImmutableNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 /**
@@ -52,6 +53,24 @@ public interface NormalizedNodeDataInput extends DataInput {
         return result.getResult();
     }
 
+    /**
+     * Read a normalized node from the reader, using specified writer to construct the result.
+     *
+     * @param writer Reusable writer to
+     * @return Next node from the stream, or null if end of stream has been reached.
+     * @throws IOException if an error occurs
+     * @throws IllegalStateException if the dictionary has been detached
+     */
+    default NormalizedNode<?, ?> readNormalizedNode(final ReusableImmutableNormalizedNodeStreamWriter writer)
+            throws IOException {
+        try {
+            streamNormalizedNode(writer);
+            return writer.getResult();
+        } finally {
+            writer.reset();
+        }
+    }
+
     YangInstanceIdentifier readYangInstanceIdentifier() throws IOException;
 
     @NonNull QName readQName() throws IOException;