From ad7135c49d0ec5f7180b46fe3657349c5d81bc63 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 17 Sep 2019 23:35:14 +0200 Subject: [PATCH] Separate out AbstractNormalizedNodeDataInput 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 --- .../stream/AbstractLithiumDataInput.java | 25 +---------- .../stream/AbstractLithiumDataOutput.java | 11 +++++ .../AbstractNormalizedNodeDataInput.java | 45 +++++++++++++++++++ .../AbstractNormalizedNodeDataOutput.java | 11 +---- 4 files changed, 60 insertions(+), 32 deletions(-) create mode 100644 opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataInput.java diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java index 05864cdda2..16bc11237e 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java @@ -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 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 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(); diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java index 2320775d5f..3a3015bb1a 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java @@ -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 pathArguments = identifier.getPathArguments(); + output.writeInt(pathArguments.size()); + + for (PathArgument pathArgument : pathArguments) { + writePathArgumentInternal(pathArgument); + } + } + final void defaultWriteAugmentationIdentifier(final @NonNull AugmentationIdentifier aid) throws IOException { final Set 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 index 0000000000..f6ab760777 --- /dev/null +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataInput.java @@ -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 qnames = ImmutableList.builderWithExpectedSize(size); + for (int i = 0; i < size; ++i) { + qnames.add(readQName()); + } + return SchemaPath.create(qnames.build(), absolute); + } + +} diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java index 4c170d7fba..7907fcfc9f 100755 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java @@ -186,18 +186,11 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut } } - final void writeYangInstanceIdentifierInternal(final YangInstanceIdentifier identifier) throws IOException { - List 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; } -- 2.36.6