Separate out AbstractNormalizedNodeDataInput 96/84596/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 17 Sep 2019 21:35:14 +0000 (23:35 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 23 Sep 2019 03:38:44 +0000 (05:38 +0200)
As we are going to introduce a streaming format for Magnesium, which
uses very different token set, it is convenient to have a common
base class which does not have conotations about what the tokens are.

We provide a baseline counterpart to AbstractNormalizedNodeDataOutput
and base AbstractLithiumDataInput on it. The asymmetry of
writeYangInstanceIdentifier() is fixed by moving it to
AbstractLithiumDataOutput.

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

opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataInput.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java

index 05864cdda24859235c14d1d13be93bfaa9836294..16bc11237ea1a6cb664ab3e2e886c4edf37bf111 100644 (file)
@@ -26,7 +26,6 @@ import java.util.Set;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.dom.DOMSource;
-import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
 import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate;
 import org.opendaylight.yangtools.yang.common.Empty;
@@ -38,7 +37,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
@@ -50,23 +48,16 @@ import org.xml.sax.SAXException;
  * nodes. This process goes in recursive manner, where each NodeTypes object signifies the start of the object, except
  * END_NODE. If a node can have children, then that node's end is calculated based on appearance of END_NODE.
  */
-abstract class AbstractLithiumDataInput extends ForwardingDataInput implements NormalizedNodeDataInput {
+abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput {
 
     private static final Logger LOG = LoggerFactory.getLogger(AbstractLithiumDataInput.class);
 
-    private final @NonNull DataInput input;
-
     private final List<String> codedStringMap = new ArrayList<>();
 
     private QName lastLeafSetQName;
 
     AbstractLithiumDataInput(final DataInput input) {
-        this.input = requireNonNull(input);
-    }
-
-    @Override
-    final DataInput delegate() {
-        return input;
+        super(input);
     }
 
     @Override
@@ -409,18 +400,6 @@ abstract class AbstractLithiumDataInput extends ForwardingDataInput implements N
         return new String(bytes, StandardCharsets.UTF_8);
     }
 
-    @Override
-    public final SchemaPath readSchemaPath() throws IOException {
-        final boolean absolute = input.readBoolean();
-        final int size = input.readInt();
-
-        final Builder<QName> qnames = ImmutableList.builderWithExpectedSize(size);
-        for (int i = 0; i < size; ++i) {
-            qnames.add(readQName());
-        }
-        return SchemaPath.create(qnames.build(), absolute);
-    }
-
     @Override
     public final YangInstanceIdentifier readYangInstanceIdentifier() throws IOException {
         return readYangInstanceIdentifierInternal();
index 2320775d5f50d3949def25bfebca9945de5edab7..3a3015bb1af210896df9fc965664b3bad0b3c1bf 100644 (file)
@@ -22,6 +22,7 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
@@ -243,6 +244,16 @@ abstract class AbstractLithiumDataOutput extends AbstractNormalizedNodeDataOutpu
         }
     }
 
+    @Override
+    final void writeYangInstanceIdentifierInternal(final YangInstanceIdentifier identifier) throws IOException {
+        List<PathArgument> pathArguments = identifier.getPathArguments();
+        output.writeInt(pathArguments.size());
+
+        for (PathArgument pathArgument : pathArguments) {
+            writePathArgumentInternal(pathArgument);
+        }
+    }
+
     final void defaultWriteAugmentationIdentifier(final @NonNull AugmentationIdentifier aid) throws IOException {
         final Set<QName> qnames = aid.getPossibleChildNames();
         // Write each child's qname separately, if list is empty send count as 0
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataInput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataInput.java
new file mode 100644 (file)
index 0000000..f6ab760
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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 static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import java.io.DataInput;
+import java.io.IOException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+abstract class AbstractNormalizedNodeDataInput extends ForwardingDataInput implements NormalizedNodeDataInput {
+    // Visible for subclasses
+    final @NonNull DataInput input;
+
+    AbstractNormalizedNodeDataInput(final DataInput input) {
+        this.input = requireNonNull(input);
+    }
+
+    @Override
+    final DataInput delegate() {
+        return input;
+    }
+
+    @Override
+    public final SchemaPath readSchemaPath() throws IOException {
+        final boolean absolute = input.readBoolean();
+        final int size = input.readInt();
+
+        final Builder<QName> qnames = ImmutableList.builderWithExpectedSize(size);
+        for (int i = 0; i < size; ++i) {
+            qnames.add(readQName());
+        }
+        return SchemaPath.create(qnames.build(), absolute);
+    }
+
+}
index 4c170d7fbacb23695fc2678e922130f85fdaf9fd..7907fcfc9f493c23d08737e4649f40d3d7140ed8 100755 (executable)
@@ -186,18 +186,11 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         }
     }
 
-    final void writeYangInstanceIdentifierInternal(final YangInstanceIdentifier identifier) throws IOException {
-        List<PathArgument> pathArguments = identifier.getPathArguments();
-        output.writeInt(pathArguments.size());
-
-        for (PathArgument pathArgument : pathArguments) {
-            writePathArgumentInternal(pathArgument);
-        }
-    }
-
     abstract short streamVersion();
 
     abstract void writeQNameInternal(@NonNull QName qname) throws IOException;
 
     abstract void writePathArgumentInternal(PathArgument pathArgument) throws IOException;
+
+    abstract void writeYangInstanceIdentifierInternal(YangInstanceIdentifier identifier) throws IOException;
 }