BUG-4626: Introduce NormalizedNodeData{Input,Output} 72/30872/10
authorRobert Varga <robert.varga@pantheon.sk>
Sun, 6 Dec 2015 22:07:36 +0000 (23:07 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 10 Dec 2015 13:08:14 +0000 (13:08 +0000)
Introduce the interfaces that are actually consumed, so that the
external interface is accurately captured.

Change-Id: I8ba93c279cfb4de063afb9c1078e97080e735e44
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataInput.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataOutput.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReader.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/SerializationUtils.java

diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataInput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataInput.java
new file mode 100644 (file)
index 0000000..f2a1b9a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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 com.google.common.annotations.Beta;
+import java.io.DataInput;
+import java.io.IOException;
+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;;
+
+/**
+ * Interface for reading {@link NormalizedNode}s, {@link YangInstanceIdentifier}s and {@link PathArgument}s.
+ */
+@Beta
+public interface NormalizedNodeDataInput extends DataInput {
+    /**
+     * Read a normalized node from the reader.
+     *
+     * @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
+     */
+    NormalizedNode<?, ?> readNormalizedNode() throws IOException;
+
+    YangInstanceIdentifier readYangInstanceIdentifier() throws IOException;
+
+    PathArgument readPathArgument() throws IOException;
+}
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataOutput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataOutput.java
new file mode 100644 (file)
index 0000000..1ea933c
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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 com.google.common.annotations.Beta;
+import java.io.DataOutput;
+import java.io.IOException;
+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;;
+
+/**
+ * Interface for emitting {@link NormalizedNode}s, {@link YangInstanceIdentifier}s and {@link PathArgument}s.
+ */
+@Beta
+public interface NormalizedNodeDataOutput extends DataOutput {
+    void writeNormalizedNode(NormalizedNode<?, ?> normalizedNode) throws IOException;
+    void writePathArgument(PathArgument pathArgument) throws IOException;
+    void writeYangInstanceIdentifier(YangInstanceIdentifier identifier) throws IOException;
+}
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java
new file mode 100644 (file)
index 0000000..cb84ef8
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 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.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import javax.annotation.Nonnull;
+
+public final class NormalizedNodeInputOutput {
+    private NormalizedNodeInputOutput() {
+        throw new UnsupportedOperationException();
+    }
+
+    public static NormalizedNodeDataInput newDataInput(@Nonnull final DataInput input) throws IOException {
+        return new NormalizedNodeInputStreamReader(input);
+    }
+
+    public static NormalizedNodeDataOutput newDataOutput(@Nonnull final DataOutput output) throws IOException {
+        return new NormalizedNodeOutputStreamWriter(output);
+    }
+}
index 03bd56eae74370a8631fca1985acad59a5d4271d..9f6d39aa194c370eeeefced90a999e87f4523814 100644 (file)
@@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory;
  *
  */
 
-public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamReader {
+public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput, NormalizedNodeStreamReader {
 
     private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeInputStreamReader.class);
 
@@ -79,6 +79,10 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
         input = new DataInputStream(stream);
     }
 
+    /**
+     * @deprecated Use {@link NormalizedNodeInputOutput#newDataInput(DataInput)} instead.
+     */
+    @Deprecated
     public NormalizedNodeInputStreamReader(final DataInput input) {
         this.input = Preconditions.checkNotNull(input);
     }
@@ -327,6 +331,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
         return new String(bytes, StandardCharsets.UTF_8);
     }
 
+    @Override
     public YangInstanceIdentifier readYangInstanceIdentifier() throws IOException {
         readSignatureMarkerAndVersionIfNeeded();
         return readYangInstanceIdentifierInternal();
@@ -352,6 +357,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
         return children;
     }
 
+    @Override
     public PathArgument readPathArgument() throws IOException {
         // read Type
         int type = input.readByte();
@@ -405,4 +411,94 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead
         }
         return builder;
     }
+
+    @Override
+    public void readFully(byte[] b) throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        input.readFully(b);
+    }
+
+    @Override
+    public void readFully(byte[] b, int off, int len) throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        input.readFully(b, off, len);
+    }
+
+    @Override
+    public int skipBytes(int n) throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.skipBytes(n);
+    }
+
+    @Override
+    public boolean readBoolean() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readBoolean();
+    }
+
+    @Override
+    public byte readByte() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readByte();
+    }
+
+    @Override
+    public int readUnsignedByte() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readUnsignedByte();
+    }
+
+    @Override
+    public short readShort() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readShort();
+    }
+
+    @Override
+    public int readUnsignedShort() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readUnsignedShort();
+    }
+
+    @Override
+    public char readChar() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readChar();
+    }
+
+    @Override
+    public int readInt() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readInt();
+    }
+
+    @Override
+    public long readLong() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readLong();
+    }
+
+    @Override
+    public float readFloat() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readFloat();
+    }
+
+    @Override
+    public double readDouble() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readDouble();
+    }
+
+    @Override
+    public String readLine() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readLine();
+    }
+
+    @Override
+    public String readUTF() throws IOException {
+        readSignatureMarkerAndVersionIfNeeded();
+        return input.readUTF();
+    }
 }
index a266a2f2202904c190ca873fa7764709a767ecac..473677396310513d73472bbc8ac8f410793e90a2 100644 (file)
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
  *
  */
 
-public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWriter {
+public class NormalizedNodeOutputStreamWriter implements NormalizedNodeDataOutput, NormalizedNodeStreamWriter {
 
     private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeOutputStreamWriter.class);
 
@@ -61,7 +61,11 @@ public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWri
         this((DataOutput) new DataOutputStream(Preconditions.checkNotNull(stream)));
     }
 
-    public NormalizedNodeOutputStreamWriter(DataOutput output) {
+    /**
+     * @deprecated Use {@link NormalizedNodeInputOutput#newDataOutput(DataOutput)} instead.
+     */
+    @Deprecated
+    public NormalizedNodeOutputStreamWriter(final DataOutput output) {
         this.output = Preconditions.checkNotNull(output);
     }
 
@@ -73,6 +77,7 @@ public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWri
         return normalizedNodeWriter;
     }
 
+    @Override
     public void writeNormalizedNode(NormalizedNode<?, ?> node) throws IOException {
         writeSignatureMarkerAndVersionIfNeeded();
         normalizedNodeWriter().write(node);
@@ -268,6 +273,7 @@ public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWri
         }
     }
 
+    @Override
     public void writeYangInstanceIdentifier(YangInstanceIdentifier identifier) throws IOException {
         writeSignatureMarkerAndVersionIfNeeded();
         writeYangInstanceIdentifierInternal(identifier);
@@ -282,6 +288,7 @@ public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWri
         }
     }
 
+    @Override
     public void writePathArgument(YangInstanceIdentifier.PathArgument pathArgument) throws IOException {
 
         byte type = PathArgumentTypes.getSerializablePathArgumentType(pathArgument);
@@ -289,7 +296,7 @@ public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWri
         output.writeByte(type);
 
         switch(type) {
-            case PathArgumentTypes.NODE_IDENTIFIER :
+            case PathArgumentTypes.NODE_IDENTIFIER:
 
                 YangInstanceIdentifier.NodeIdentifier nodeIdentifier =
                     (YangInstanceIdentifier.NodeIdentifier) pathArgument;
@@ -403,4 +410,88 @@ public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWri
                 break;
         }
     }
+
+    @Override
+    public void write(int b) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.write(b);
+    }
+
+    @Override
+    public void write(byte[] b) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.write(b);
+    }
+
+    @Override
+    public void write(byte[] b, int off, int len) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.write(b, off, len);
+    }
+
+    @Override
+    public void writeBoolean(boolean v) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeBoolean(v);
+    }
+
+    @Override
+    public void writeByte(int v) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeByte(v);
+    }
+
+    @Override
+    public void writeShort(int v) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeShort(v);
+    }
+
+    @Override
+    public void writeChar(int v) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeChar(v);
+    }
+
+    @Override
+    public void writeInt(int v) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeInt(v);
+    }
+
+    @Override
+    public void writeLong(long v) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeLong(v);
+    }
+
+    @Override
+    public void writeFloat(float v) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeFloat(v);
+    }
+
+    @Override
+    public void writeDouble(double v) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeDouble(v);
+    }
+
+    @Override
+    public void writeBytes(String s) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeBytes(s);
+    }
+
+    @Override
+    public void writeChars(String s) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeChars(s);
+    }
+
+    @Override
+    public void writeUTF(String s) throws IOException {
+        writeSignatureMarkerAndVersionIfNeeded();
+        output.writeUTF(s);
+    }
 }
index ae4fed4b72e128c3750873afaa5626e59b660dbb..b055055b4046527b20d0b52283160e4897d4f2de 100644 (file)
@@ -8,13 +8,10 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
 
-import java.io.IOException;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
 /**
  * Interface for a class that can read serialized NormalizedNode instances from a stream.
+ *
+ * @deprecated Use {@link NormalizedNodeDataInput} instead.
  */
-public interface NormalizedNodeStreamReader {
-
-    NormalizedNode<?, ?> readNormalizedNode() throws IOException;
+public interface NormalizedNodeStreamReader extends NormalizedNodeDataInput {
 }
index bc3d7b02f8dda76d57f91a57ad7d30b3e98bc671..4bd098a00296bf0c368912c397755d33bb2e88e9 100644 (file)
@@ -12,8 +12,6 @@ import com.google.common.io.ByteArrayDataInput;
 import com.google.common.io.ByteArrayDataOutput;
 import com.google.common.io.ByteStreams;
 import com.google.protobuf.GeneratedMessage.GeneratedExtension;
-import java.io.DataInput;
-import java.io.DataOutput;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
@@ -22,6 +20,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputStreamReader;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeOutputStreamWriter;
 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
@@ -56,39 +56,39 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
         this.serialized = Preconditions.checkNotNull(serialized);
     }
 
-    private static void writeChildren(final NormalizedNodeOutputStreamWriter writer, final DataOutput out,
+    private static void writeChildren(final NormalizedNodeDataOutput out,
             final Collection<DataTreeCandidateNode> children) throws IOException {
         out.writeInt(children.size());
         for (DataTreeCandidateNode child : children) {
-            writeNode(writer, out, child);
+            writeNode(out, child);
         }
     }
 
-    private static void writeNode(final NormalizedNodeOutputStreamWriter writer, final DataOutput out,
-            final DataTreeCandidateNode node) throws IOException {
+    private static void writeNode(final NormalizedNodeDataOutput out, final DataTreeCandidateNode node)
+            throws IOException {
         switch (node.getModificationType()) {
         case APPEARED:
             out.writeByte(APPEARED);
-            writer.writePathArgument(node.getIdentifier());
-            writeChildren(writer, out, node.getChildNodes());
+            out.writePathArgument(node.getIdentifier());
+            writeChildren(out, node.getChildNodes());
             break;
         case DELETE:
             out.writeByte(DELETE);
-            writer.writePathArgument(node.getIdentifier());
+            out.writePathArgument(node.getIdentifier());
             break;
         case DISAPPEARED:
             out.writeByte(DISAPPEARED);
-            writer.writePathArgument(node.getIdentifier());
-            writeChildren(writer, out, node.getChildNodes());
+            out.writePathArgument(node.getIdentifier());
+            writeChildren(out, node.getChildNodes());
             break;
         case SUBTREE_MODIFIED:
             out.writeByte(SUBTREE_MODIFIED);
-            writer.writePathArgument(node.getIdentifier());
-            writeChildren(writer, out, node.getChildNodes());
+            out.writePathArgument(node.getIdentifier());
+            writeChildren(out, node.getChildNodes());
             break;
         case WRITE:
             out.writeByte(WRITE);
-            writer.writeNormalizedNode(node.getDataAfter().get());
+            out.writeNormalizedNode(node.getDataAfter().get());
             break;
         case UNMODIFIED:
             out.writeByte(UNMODIFIED);
@@ -98,7 +98,7 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
         }
     }
 
-    static DataTreeCandidatePayload create(DataTreeCandidate candidate) {
+    static DataTreeCandidatePayload create(final DataTreeCandidate candidate) {
         final ByteArrayDataOutput out = ByteStreams.newDataOutput();
         try (final NormalizedNodeOutputStreamWriter writer = new NormalizedNodeOutputStreamWriter(out)) {
             writer.writeYangInstanceIdentifier(candidate.getRootPath());
@@ -106,32 +106,31 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
             final DataTreeCandidateNode node = candidate.getRootNode();
             switch (node.getModificationType()) {
             case APPEARED:
-                out.writeByte(APPEARED);
-                writeChildren(writer, out, node.getChildNodes());
+                writer.writeByte(APPEARED);
+                writeChildren(writer, node.getChildNodes());
                 break;
             case DELETE:
-                out.writeByte(DELETE);
+                writer.writeByte(DELETE);
                 break;
             case DISAPPEARED:
-                out.writeByte(DISAPPEARED);
-                writeChildren(writer, out, node.getChildNodes());
+                writer.writeByte(DISAPPEARED);
+                writeChildren(writer, node.getChildNodes());
                 break;
             case SUBTREE_MODIFIED:
-                out.writeByte(SUBTREE_MODIFIED);
-                writeChildren(writer, out, node.getChildNodes());
+                writer.writeByte(SUBTREE_MODIFIED);
+                writeChildren(writer, node.getChildNodes());
                 break;
             case UNMODIFIED:
-                out.writeByte(UNMODIFIED);
+                writer.writeByte(UNMODIFIED);
                 break;
             case WRITE:
-                out.writeByte(WRITE);
+                writer.writeByte(WRITE);
                 writer.writeNormalizedNode(node.getDataAfter().get());
                 break;
             default:
                 throw new IllegalArgumentException("Unhandled node type " + node.getModificationType());
             }
 
-            writer.close();
         } catch (IOException e) {
             throw new IllegalArgumentException(String.format("Failed to serialize candidate %s", candidate), e);
         }
@@ -139,13 +138,12 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
         return new DataTreeCandidatePayload(out.toByteArray());
     }
 
-    private static Collection<DataTreeCandidateNode> readChildren(final NormalizedNodeInputStreamReader reader,
-        final DataInput in) throws IOException {
+    private static Collection<DataTreeCandidateNode> readChildren(final NormalizedNodeDataInput in) throws IOException {
         final int size = in.readInt();
         if (size != 0) {
             final Collection<DataTreeCandidateNode> ret = new ArrayList<>(size);
             for (int i = 0; i < size; ++i) {
-                final DataTreeCandidateNode child = readNode(reader, in);
+                final DataTreeCandidateNode child = readNode(in);
                 if (child != null) {
                     ret.add(child);
                 }
@@ -157,10 +155,10 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
     }
 
     private static DataTreeCandidateNode readModifiedNode(final ModificationType type,
-            final NormalizedNodeInputStreamReader reader, final DataInput in) throws IOException {
+            final NormalizedNodeDataInput in) throws IOException {
 
-        final PathArgument identifier = reader.readPathArgument();
-        final Collection<DataTreeCandidateNode> children = readChildren(reader, in);
+        final PathArgument identifier = in.readPathArgument();
+        final Collection<DataTreeCandidateNode> children = readChildren(in);
         if (children.isEmpty()) {
             LOG.debug("Modified node {} does not have any children, not instantiating it", identifier);
             return null;
@@ -169,31 +167,30 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
         }
     }
 
-    private static DataTreeCandidateNode readNode(final NormalizedNodeInputStreamReader reader,
-            final DataInput in) throws IOException {
+    private static DataTreeCandidateNode readNode(final NormalizedNodeDataInput in) throws IOException {
         final byte type = in.readByte();
         switch (type) {
         case APPEARED:
-            return readModifiedNode(ModificationType.APPEARED, reader, in);
+            return readModifiedNode(ModificationType.APPEARED, in);
         case DELETE:
-            return DeletedDataTreeCandidateNode.create(reader.readPathArgument());
+            return DeletedDataTreeCandidateNode.create(in.readPathArgument());
         case DISAPPEARED:
-            return readModifiedNode(ModificationType.DISAPPEARED, reader, in);
+            return readModifiedNode(ModificationType.DISAPPEARED, in);
         case SUBTREE_MODIFIED:
-            return readModifiedNode(ModificationType.SUBTREE_MODIFIED, reader, in);
+            return readModifiedNode(ModificationType.SUBTREE_MODIFIED, in);
         case UNMODIFIED:
             return null;
         case WRITE:
-            return DataTreeCandidateNodes.fromNormalizedNode(reader.readNormalizedNode());
+            return DataTreeCandidateNodes.fromNormalizedNode(in.readNormalizedNode());
         default:
             throw new IllegalArgumentException("Unhandled node type " + type);
         }
     }
 
     private static DataTreeCandidate parseCandidate(final ByteArrayDataInput in) throws IOException {
-        final NormalizedNodeInputStreamReader reader = new NormalizedNodeInputStreamReader(in);
+        final NormalizedNodeDataInput reader = new NormalizedNodeInputStreamReader(in);
         final YangInstanceIdentifier rootPath = reader.readYangInstanceIdentifier();
-        final byte type = in.readByte();
+        final byte type = reader.readByte();
 
         final DataTreeCandidateNode rootNode;
         switch (type) {
@@ -201,7 +198,7 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
             rootNode = DeletedDataTreeCandidateNode.create();
             break;
         case SUBTREE_MODIFIED:
-            rootNode = ModifiedDataTreeCandidateNode.create(readChildren(reader, in));
+            rootNode = ModifiedDataTreeCandidateNode.create(readChildren(reader));
             break;
         case WRITE:
             rootNode = DataTreeCandidateNodes.fromNormalizedNode(reader.readNormalizedNode());
index e96375b3e467c9ee2ef36214d47a8d0c84ff7caa..79772fed5e23c9bad4cce7d71febc0ea5f367739 100644 (file)
@@ -18,6 +18,8 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.InvalidNormalizedNodeStreamException;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputStreamReader;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeOutputStreamWriter;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
@@ -37,7 +39,7 @@ public final class SerializationUtils {
         void apply(T instance, YangInstanceIdentifier path, NormalizedNode<?, ?> node);
     }
 
-    private static NormalizedNodeOutputStreamWriter streamWriter(DataOutput out) throws IOException {
+    private static NormalizedNodeDataOutput streamWriter(DataOutput out) throws IOException {
         NormalizedNodeOutputStreamWriter streamWriter = REUSABLE_WRITER_TL.get();
         if(streamWriter == null) {
             streamWriter = new NormalizedNodeOutputStreamWriter(out);
@@ -46,7 +48,7 @@ public final class SerializationUtils {
         return streamWriter;
     }
 
-    private static NormalizedNodeInputStreamReader streamReader(DataInput in) throws IOException {
+    private static NormalizedNodeDataInput streamReader(DataInput in) throws IOException {
         NormalizedNodeInputStreamReader streamWriter = REUSABLE_READER_TL.get();
         if(streamWriter == null) {
             streamWriter = new NormalizedNodeInputStreamReader(in);
@@ -60,7 +62,7 @@ public final class SerializationUtils {
         Preconditions.checkNotNull(path);
         Preconditions.checkNotNull(node);
         try {
-            NormalizedNodeOutputStreamWriter streamWriter = streamWriter(out);
+            NormalizedNodeDataOutput streamWriter = streamWriter(out);
             streamWriter.writeNormalizedNode(node);
             streamWriter.writeYangInstanceIdentifier(path);
         } catch (IOException e) {
@@ -71,7 +73,7 @@ public final class SerializationUtils {
 
     public static <T> void deserializePathAndNode(DataInput in, T instance, Applier<T> applier) {
         try {
-            NormalizedNodeInputStreamReader streamReader = streamReader(in);
+            NormalizedNodeDataInput streamReader = streamReader(in);
             NormalizedNode<?, ?> node = streamReader.readNormalizedNode();
             YangInstanceIdentifier path = streamReader.readYangInstanceIdentifier();
             applier.apply(instance, path, node);
@@ -84,7 +86,7 @@ public final class SerializationUtils {
         try {
             out.writeBoolean(node != null);
             if(node != null) {
-                NormalizedNodeOutputStreamWriter streamWriter = streamWriter(out);
+                NormalizedNodeDataOutput streamWriter = streamWriter(out);
                 streamWriter.writeNormalizedNode(node);
             }
         } catch (IOException e) {
@@ -104,7 +106,7 @@ public final class SerializationUtils {
     private static NormalizedNode<?, ?> tryDeserializeNormalizedNode(DataInput in) throws IOException {
         boolean present = in.readBoolean();
         if(present) {
-            NormalizedNodeInputStreamReader streamReader = streamReader(in);
+            NormalizedNodeDataInput streamReader = streamReader(in);
             return streamReader.readNormalizedNode();
         }
 
@@ -139,7 +141,7 @@ public final class SerializationUtils {
     public static void serializePath(YangInstanceIdentifier path, DataOutput out) {
         Preconditions.checkNotNull(path);
         try {
-            NormalizedNodeOutputStreamWriter streamWriter = streamWriter(out);
+            NormalizedNodeDataOutput streamWriter = streamWriter(out);
             streamWriter.writeYangInstanceIdentifier(path);
         } catch (IOException e) {
             throw new IllegalArgumentException(String.format("Error serializing path %s", path), e);
@@ -148,7 +150,7 @@ public final class SerializationUtils {
 
     public static YangInstanceIdentifier deserializePath(DataInput in) {
         try {
-            NormalizedNodeInputStreamReader streamReader = streamReader(in);
+            NormalizedNodeDataInput streamReader = streamReader(in);
             return streamReader.readYangInstanceIdentifier();
         } catch (IOException e) {
             throw new IllegalArgumentException("Error deserializing path", e);