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);
* <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<>();
}
@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
* @return a new {@link NormalizedNodeDataOutput} instance
*/
public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output) {
- return new NormalizedNodeOutputStreamWriter(output);
+ return new NeonSR2NormalizedNodeOutputStreamWriter(output);
}
/**
+++ /dev/null
-/*
- * 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);
- }
-}
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();
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;
}
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);
}
}