Remove pre-Lithium serialization support in sal-distributed-datastore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / SerializationUtils.java
index 97e3383490d5bb058d3999c454464c435d16ee0c..9ed9e9a88fae5e870c9f21b50076d08c47d61020 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.cluster.datastore.utils;
 
 import com.google.common.base.Preconditions;
-import com.google.protobuf.InvalidProtocolBufferException;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataInput;
@@ -16,13 +15,10 @@ import java.io.DataInputStream;
 import java.io.DataOutput;
 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.NormalizedNodeInputOutput;
 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputStreamReader;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
@@ -41,7 +37,7 @@ public final class SerializationUtils {
 
     private static NormalizedNodeDataOutput streamWriter(DataOutput out) throws IOException {
         NormalizedNodeDataOutput streamWriter = REUSABLE_WRITER_TL.get();
-        if(streamWriter == null) {
+        if (streamWriter == null) {
             streamWriter = NormalizedNodeInputOutput.newDataOutput(out);
         }
 
@@ -50,7 +46,7 @@ public final class SerializationUtils {
 
     private static NormalizedNodeDataInput streamReader(DataInput in) throws IOException {
         NormalizedNodeDataInput streamReader = REUSABLE_READER_TL.get();
-        if(streamReader == null) {
+        if (streamReader == null) {
             streamReader = new NormalizedNodeInputStreamReader(in);
         }
 
@@ -82,17 +78,14 @@ public final class SerializationUtils {
         }
     }
 
-    public static void serializeNormalizedNode(NormalizedNode<?, ?> node, DataOutput out) {
-        try {
-            out.writeBoolean(node != null);
-            if(node != null) {
-                NormalizedNodeDataOutput streamWriter = streamWriter(out);
-                streamWriter.writeNormalizedNode(node);
-            }
-        } catch (IOException e) {
-            throw new IllegalArgumentException(String.format("Error serializing NormalizedNode %s",
-                    node), e);
+    private static NormalizedNode<?, ?> tryDeserializeNormalizedNode(DataInput in) throws IOException {
+        boolean present = in.readBoolean();
+        if (present) {
+            NormalizedNodeDataInput streamReader = streamReader(in);
+            return streamReader.readNormalizedNode();
         }
+
+        return null;
     }
 
     public static NormalizedNode<?, ?> deserializeNormalizedNode(DataInput in) {
@@ -103,29 +96,24 @@ public final class SerializationUtils {
         }
     }
 
-    private static NormalizedNode<?, ?> tryDeserializeNormalizedNode(DataInput in) throws IOException {
-        boolean present = in.readBoolean();
-        if(present) {
-            NormalizedNodeDataInput streamReader = streamReader(in);
-            return streamReader.readNormalizedNode();
+    public static NormalizedNode<?, ?> deserializeNormalizedNode(byte [] bytes) {
+        try {
+            return tryDeserializeNormalizedNode(new DataInputStream(new ByteArrayInputStream(bytes)));
+        } catch (IOException e) {
+            throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
         }
-
-        return null;
     }
 
-    public static NormalizedNode<?, ?> deserializeNormalizedNode(byte [] bytes) {
+    public static void serializeNormalizedNode(NormalizedNode<?, ?> node, DataOutput out) {
         try {
-            return tryDeserializeNormalizedNode(new DataInputStream(new ByteArrayInputStream(bytes)));
-        } catch(InvalidNormalizedNodeStreamException e) {
-            // Probably from legacy protobuf serialization - try that.
-            try {
-                NormalizedNodeMessages.Node serializedNode = NormalizedNodeMessages.Node.parseFrom(bytes);
-                return new NormalizedNodeToNodeCodec(null).decode(serializedNode);
-            } catch (InvalidProtocolBufferException e2) {
-                throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
+            out.writeBoolean(node != null);
+            if (node != null) {
+                NormalizedNodeDataOutput streamWriter = streamWriter(out);
+                streamWriter.writeNormalizedNode(node);
             }
         } catch (IOException e) {
-            throw new IllegalArgumentException("Error deserializing NormalizedNode", e);
+            throw new IllegalArgumentException(String.format("Error serializing NormalizedNode %s",
+                    node), e);
         }
     }