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.node.NormalizedNodeToNodeCodec;
import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Encoded;
+import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
+import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils.Applier;
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;
/**
* WriteModification stores all the parameters required to write data to the specified path
*/
public class WriteModification extends AbstractModification {
+ private static final long serialVersionUID = 1L;
- protected final NormalizedNode data;
- private final SchemaContext schemaContext;
+ private NormalizedNode<?, ?> data;
- public WriteModification(YangInstanceIdentifier path, NormalizedNode data, SchemaContext schemaContext) {
+ public WriteModification() {
+ }
+
+ public WriteModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
super(path);
this.data = data;
- this.schemaContext = schemaContext;
}
@Override
- public void apply(DOMStoreWriteTransaction transaction) {
- transaction.write(path, data);
+ public void apply(final DOMStoreWriteTransaction transaction) {
+ transaction.write(getPath(), data);
}
- public NormalizedNode getData() {
+ public NormalizedNode<?, ?> getData() {
return data;
}
@Override
- public Object toSerializable() {
- Encoded encoded = new NormalizedNodeToNodeCodec(schemaContext).encode(path, data);
+ public byte getType() {
+ return WRITE;
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ in.readShort(); // version
+
+ SerializationUtils.deserializePathAndNode(in, this, APPLIER);
+ }
- return PersistentMessages.Modification.newBuilder()
- .setType(this.getClass().toString())
- .setPath(encoded.getEncodedPath())
- .setData(encoded.getEncodedNode().getNormalizedNode())
- .build();
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeShort(DataStoreVersions.CURRENT_VERSION);
+ SerializationUtils.serializePathAndNode(getPath(), data, out);
+ }
+
+ @Override
+ @Deprecated
+ public Object toSerializable() {
+ Encoded encoded = new NormalizedNodeToNodeCodec(null).encode(getPath(), getData());
+ return PersistentMessages.Modification.newBuilder().setType(this.getClass().toString())
+ .setPath(encoded.getEncodedPath()).setData(encoded.getEncodedNode()
+ .getNormalizedNode()).build();
}
- public static WriteModification fromSerializable(Object serializable, SchemaContext schemaContext) {
+ @Deprecated
+ public static WriteModification fromSerializable(final Object serializable) {
PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
- Decoded decoded = new NormalizedNodeToNodeCodec(schemaContext).decode(o.getPath(), o.getData());
- return new WriteModification(decoded.getDecodedPath(), decoded.getDecodedNode(), schemaContext);
+ Decoded decoded = new NormalizedNodeToNodeCodec(null).decode(o.getPath(), o.getData());
+ return new WriteModification(decoded.getDecodedPath(), decoded.getDecodedNode());
+ }
+
+ public static WriteModification fromStream(ObjectInput in) throws ClassNotFoundException, IOException {
+ WriteModification mod = new WriteModification();
+ mod.readExternal(in);
+ return mod;
}
+
+ private static final Applier<WriteModification> APPLIER = new Applier<WriteModification>() {
+ @Override
+ public void apply(WriteModification instance, YangInstanceIdentifier path,
+ NormalizedNode<?, ?> node) {
+ instance.setPath(path);
+ instance.data = node;
+ }
+ };
}