Switch CompositeModification to bypass thread-local streams
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / modification / DeleteModification.java
index f7d8b87ff6b74a4f33917d57173621edf7305820..ce4108dc7f7b83feea604bbc8b788fd7e44b2899 100644 (file)
@@ -8,33 +8,71 @@
 
 package org.opendaylight.controller.cluster.datastore.modification;
 
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
-import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
-import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+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.utils.stream.NormalizedNodeDataInput;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
+import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
+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
+ * 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);
-  }
+    private static final long serialVersionUID = 1L;
 
-  @Override
-  public void apply(DOMStoreWriteTransaction transaction) {
-    transaction.delete(path);
-  }
+    public DeleteModification() {
+        this(DataStoreVersions.CURRENT_VERSION);
+    }
+
+    public DeleteModification(final short version) {
+        super(version);
+    }
+
+    public DeleteModification(final YangInstanceIdentifier path) {
+        super(path);
+    }
+
+    DeleteModification(final short version, final YangInstanceIdentifier path) {
+        super(version, path);
+    }
+
+    @Override
+    public void apply(final DOMStoreWriteTransaction transaction) {
+        transaction.delete(getPath());
+    }
+
+    @Override
+    public void apply(final DataTreeModification transaction) {
+        transaction.delete(getPath());
+    }
+
+    @Override
+    public byte getType() {
+        return DELETE;
+    }
+
+    @Override
+    public void readExternal(final ObjectInput in) {
+        setPath(SerializationUtils.deserializePath(in));
+    }
+
+    @Override
+    public void writeExternal(final ObjectOutput out) {
+        SerializationUtils.serializePath(getPath(), out);
+    }
 
-    @Override public Object toSerializable() {
-        return PersistentMessages.Modification.newBuilder()
-            .setType(this.getClass().toString())
-            .setPath(this.path.toString())
-            .build();
+    @Override
+    public void writeTo(final NormalizedNodeDataOutput out) throws IOException {
+        out.writeYangInstanceIdentifier(getPath());
     }
 
-    public static DeleteModification fromSerializable(Object serializable){
-        PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
-        return new DeleteModification(InstanceIdentifierUtils.from(o.getPath()));
+    public static DeleteModification fromStream(final NormalizedNodeDataInput in, final short version)
+            throws IOException {
+        return new DeleteModification(version, in.readYangInstanceIdentifier());
     }
 }