a9c8ab9fc2781827414c88e844a0d07cc7b9af9c
[netconf.git] / apps / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / messages / NormalizedNodeMessage.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.topology.singleton.messages;
10
11 import java.io.Externalizable;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18
19 /**
20  * Message which holds node data, prepared to sending between remote hosts with serialization.
21  */
22 public class NormalizedNodeMessage implements Externalizable {
23     private static final long serialVersionUID = 1L;
24
25     private YangInstanceIdentifier identifier;
26     private NormalizedNode node;
27
28     public NormalizedNodeMessage() {
29         // empty constructor needed for Externalizable
30     }
31
32     public NormalizedNodeMessage(final YangInstanceIdentifier identifier, final NormalizedNode node) {
33         this.identifier = identifier;
34         this.node = node;
35     }
36
37     public YangInstanceIdentifier getIdentifier() {
38         return identifier;
39     }
40
41     public NormalizedNode getNode() {
42         return node;
43     }
44
45     @Override
46     public void writeExternal(final ObjectOutput out) throws IOException {
47         SerializationUtils.writeNodeAndPath(out, getIdentifier(), node);
48     }
49
50     @Override
51     public void readExternal(final ObjectInput in) throws IOException {
52         SerializationUtils.readNodeAndPath(in, this, APPLIER);
53     }
54
55     @Override
56     public String toString() {
57         return "NormalizedNodeMessage [identifier=" + identifier + ", node=" + node + "]";
58     }
59
60     private static final SerializationUtils.Applier<NormalizedNodeMessage> APPLIER = (instance, path, node) -> {
61         instance.identifier = path;
62         instance.node = node;
63     };
64 }