BUG-4626: Introduce NormalizedNodeData{Input,Output}
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>
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataInput.java [new file with mode: 0644]
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataOutput.java [new file with mode: 0644]
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java [new file with mode: 0644]
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java
java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReader.java

diff --git a/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataInput.java b/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/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeDataOutput.java b/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/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputOutput.java b/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 {
 }