2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore.modification;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput;
16 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
17 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
18 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils.Applier;
19 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
25 * WriteModification stores all the parameters required to write data to the specified path.
27 public class WriteModification extends AbstractModification {
28 private static final long serialVersionUID = 1L;
30 private NormalizedNode<?, ?> data;
32 public WriteModification() {
33 this(DataStoreVersions.CURRENT_VERSION);
36 public WriteModification(final short version) {
40 WriteModification(final short version, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
45 public WriteModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
51 public void apply(final DOMStoreWriteTransaction transaction) {
52 transaction.write(getPath(), data);
56 public void apply(final DataTreeModification transaction) {
57 transaction.write(getPath(), data);
60 public NormalizedNode<?, ?> getData() {
65 public byte getType() {
70 public void readExternal(final ObjectInput in) {
71 SerializationUtils.deserializePathAndNode(in, this, APPLIER);
75 public void writeExternal(final ObjectOutput out) throws IOException {
76 SerializationUtils.writeNodeAndPath(out, getPath(), data);
79 public static WriteModification fromStream(final NormalizedNodeDataInput in, final short version)
81 final NormalizedNode<?, ?> node = in.readNormalizedNode();
82 final YangInstanceIdentifier path = in.readYangInstanceIdentifier();
83 return new WriteModification(version, path, node);
87 public void writeTo(final NormalizedNodeDataOutput out) throws IOException {
88 // FIXME: this should be inverted, as the path helps receivers in establishment of context
89 out.writeNormalizedNode(data);
90 out.writeYangInstanceIdentifier(getPath());
93 private static final Applier<WriteModification> APPLIER = (instance, path, node) -> {
94 instance.setPath(path);