Bug 2268: Use streaming for Modification payload
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / modification / MergeModification.java
index 2f9d77660aba4d76b671b91df000baae5c5780ba..571443eedd3a89f2ce9d474cbfbd883919a8d7ff 100644 (file)
@@ -8,13 +8,14 @@
 
 package org.opendaylight.controller.cluster.datastore.modification;
 
+import java.io.IOException;
+import java.io.ObjectInput;
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
  * MergeModification stores all the parameters required to merge data into the specified path
@@ -22,19 +23,33 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 public class MergeModification extends WriteModification {
     private static final long serialVersionUID = 1L;
 
-    public MergeModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
-        final SchemaContext schemaContext) {
-        super(path, data, schemaContext);
+    public MergeModification() {
+    }
+
+    public MergeModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+        super(path, data);
     }
 
     @Override
     public void apply(final DOMStoreWriteTransaction transaction) {
-        transaction.merge(path, data);
+        transaction.merge(getPath(), getData());
     }
 
-    public static MergeModification fromSerializable(final Object serializable, final SchemaContext schemaContext) {
+    @Override
+    public byte getType() {
+        return MERGE;
+    }
+
+    @Deprecated
+    public static MergeModification fromSerializable(final Object serializable) {
         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
-        Decoded decoded = new NormalizedNodeToNodeCodec(schemaContext).decode(o.getPath(), o.getData());
-        return new MergeModification(decoded.getDecodedPath(), decoded.getDecodedNode(), schemaContext);
+        Decoded decoded = new NormalizedNodeToNodeCodec(null).decode(o.getPath(), o.getData());
+        return new MergeModification(decoded.getDecodedPath(), decoded.getDecodedNode());
+    }
+
+    public static MergeModification fromStream(ObjectInput in) throws ClassNotFoundException, IOException {
+        MergeModification mod = new MergeModification();
+        mod.readExternal(in);
+        return mod;
     }
 }