BUG-5280: Remove PeristentMessages
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / modification / DeleteModification.java
index 063ec3e1fcc34ca96192bd4e0c90e40c604c43a6..08274ef7051d714aa736d505c965d97ae10f3a44 100644 (file)
@@ -8,19 +8,62 @@
 
 package org.opendaylight.controller.cluster.datastore.modification;
 
+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.utils.SerializationUtils;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 
 /**
  * DeleteModification store all the parameters required to delete a path from the data tree
  */
 public class DeleteModification extends AbstractModification {
-  public DeleteModification(InstanceIdentifier path) {
-    super(path);
-  }
-
-  @Override
-  public void apply(DOMStoreWriteTransaction transaction) {
-    transaction.delete(path);
-  }
+    private static final long serialVersionUID = 1L;
+
+    public DeleteModification() {
+        this(DataStoreVersions.CURRENT_VERSION);
+    }
+
+    public DeleteModification(short version) {
+        super(version);
+    }
+
+    public DeleteModification(YangInstanceIdentifier path) {
+        super(path);
+    }
+
+    @Override
+    public void apply(DOMStoreWriteTransaction transaction) {
+        transaction.delete(getPath());
+    }
+
+    @Override
+    public void apply(DataTreeModification transaction) {
+        transaction.delete(getPath());
+    }
+
+    @Override
+    public byte getType() {
+        return DELETE;
+    }
+
+    @Override
+    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        setPath(SerializationUtils.deserializePath(in));
+    }
+
+    @Override
+    public void writeExternal(ObjectOutput out) throws IOException {
+        SerializationUtils.serializePath(getPath(), out);
+    }
+
+    public static DeleteModification fromStream(ObjectInput in, short version)
+            throws ClassNotFoundException, IOException {
+        DeleteModification mod = new DeleteModification(version);
+        mod.readExternal(in);
+        return mod;
+    }
 }