Define DataStoreVersions.MAGNESIUM_VERSION
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / ReadDataReply.java
index b0c163d87f346ccaefc300ce38f88573ab033b17..91d38ccd079ab7aad5ec069eb2208bcbe0c560b6 100644 (file)
@@ -8,27 +8,21 @@
 
 package org.opendaylight.controller.cluster.datastore.messages;
 
-import com.google.protobuf.ByteString;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
-import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 public class ReadDataReply extends VersionedExternalizableMessage {
     private static final long serialVersionUID = 1L;
 
-    public static final Class<ReadDataReply> SERIALIZABLE_CLASS = ReadDataReply.class;
-
     private NormalizedNode<?, ?> normalizedNode;
 
     public ReadDataReply() {
     }
 
-    public ReadDataReply(NormalizedNode<?, ?> normalizedNode, short version) {
+    public ReadDataReply(final NormalizedNode<?, ?> normalizedNode, final short version) {
         super(version);
         this.normalizedNode = normalizedNode;
     }
@@ -38,62 +32,22 @@ public class ReadDataReply extends VersionedExternalizableMessage {
     }
 
     @Override
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+    public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
         super.readExternal(in);
-        normalizedNode = SerializationUtils.deserializeNormalizedNode(in);
+        normalizedNode = SerializationUtils.readNormalizedNode(in).orElse(null);
     }
 
     @Override
-    public void writeExternal(ObjectOutput out) throws IOException {
+    public void writeExternal(final ObjectOutput out) throws IOException {
         super.writeExternal(out);
-        SerializationUtils.serializeNormalizedNode(normalizedNode, out);
-    }
-
-    @Override
-    public Object toSerializable() {
-        if(getVersion() >= DataStoreVersions.LITHIUM_VERSION) {
-            return this;
-        } else {
-            return toSerializableReadDataReply(normalizedNode);
-        }
-    }
-
-    private static ShardTransactionMessages.ReadDataReply toSerializableReadDataReply(
-            NormalizedNode<?, ?> normalizedNode) {
-        if(normalizedNode != null) {
-            return ShardTransactionMessages.ReadDataReply.newBuilder()
-                    .setNormalizedNode(new NormalizedNodeToNodeCodec(null)
-                    .encode(normalizedNode).getNormalizedNode()).build();
-        } else {
-            return ShardTransactionMessages.ReadDataReply.newBuilder().build();
-
-        }
-    }
-
-    public static ReadDataReply fromSerializable(Object serializable) {
-        if(serializable instanceof ReadDataReply) {
-            return (ReadDataReply) serializable;
-        } else {
-            ShardTransactionMessages.ReadDataReply o =
-                    (ShardTransactionMessages.ReadDataReply) serializable;
-            return new ReadDataReply(new NormalizedNodeToNodeCodec(null).decode(o.getNormalizedNode()),
-                    DataStoreVersions.HELIUM_2_VERSION);
-        }
+        SerializationUtils.writeNormalizedNode(out, getStreamVersion(), normalizedNode);
     }
 
-    public static ByteString fromSerializableAsByteString(Object serializable) {
-        if(serializable instanceof ReadDataReply) {
-            ReadDataReply r = (ReadDataReply)serializable;
-            return toSerializableReadDataReply(r.getNormalizedNode()).toByteString();
-        } else {
-            ShardTransactionMessages.ReadDataReply o =
-                    (ShardTransactionMessages.ReadDataReply) serializable;
-            return o.getNormalizedNode().toByteString();
-        }
+    public static ReadDataReply fromSerializable(final Object serializable) {
+        return (ReadDataReply) serializable;
     }
 
-    public static boolean isSerializedType(Object message) {
-        return SERIALIZABLE_CLASS.isAssignableFrom(message.getClass()) ||
-               message instanceof ShardTransactionMessages.ReadDataReply;
+    public static boolean isSerializedType(final Object message) {
+        return message instanceof ReadDataReply;
     }
 }