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.mdsal.dom.spi.store.DOMStoreWriteTransaction;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
24 * WriteModification stores all the parameters required to write data to the specified path.
26 public class WriteModification extends AbstractModification {
27 private static final long serialVersionUID = 1L;
29 private NormalizedNode<?, ?> data;
31 public WriteModification() {
32 this(DataStoreVersions.CURRENT_VERSION);
35 public WriteModification(final short version) {
39 WriteModification(final short version, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
44 public WriteModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
50 public void apply(final DOMStoreWriteTransaction transaction) {
51 transaction.write(getPath(), data);
55 public void apply(final DataTreeModification transaction) {
56 transaction.write(getPath(), data);
59 public NormalizedNode<?, ?> getData() {
64 public byte getType() {
69 public void readExternal(final ObjectInput in) throws IOException {
70 SerializationUtils.readNodeAndPath(in, this, (instance, path, node) -> {
71 instance.setPath(path);
77 public void writeExternal(final ObjectOutput out) throws IOException {
78 SerializationUtils.writeNodeAndPath(out, getPath(), data);
82 public static WriteModification fromStream(final ObjectInput in, final short version) {
83 WriteModification mod = new WriteModification(version);
86 } catch (IOException e) {
87 throw new IllegalArgumentException("Error deserializing WriteModification", e);
92 public static WriteModification fromStream(final NormalizedNodeDataInput in, final short version)
94 final NormalizedNode<?, ?> node = in.readNormalizedNode();
95 final YangInstanceIdentifier path = in.readYangInstanceIdentifier();
96 return new WriteModification(version, path, node);
100 public void writeTo(final NormalizedNodeDataOutput out) throws IOException {
101 // FIXME: this should be inverted, as the path helps receivers in establishment of context
102 out.writeNormalizedNode(data);
103 out.writeYangInstanceIdentifier(getPath());