62690ea6253e99ff923f75d97b20550be20aa886
[netconf.git] / netconf / 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.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17
18 /**
19  * Message which holds node data, prepared to sending between remote hosts with serialization.
20  */
21 public class NormalizedNodeMessage implements Externalizable {
22     private static final long serialVersionUID = 1L;
23
24     private YangInstanceIdentifier identifier = null;
25     private NormalizedNode<?, ?> node = null;
26
27     public NormalizedNodeMessage() {
28         // empty constructor needed for Externalizable
29     }
30
31     public NormalizedNodeMessage(final YangInstanceIdentifier identifier, final NormalizedNode<?, ?> node) {
32         this.identifier = identifier;
33         this.node = node;
34     }
35
36     public YangInstanceIdentifier getIdentifier() {
37         return identifier;
38     }
39
40     public NormalizedNode<?, ?> getNode() {
41         return node;
42     }
43
44     @Override
45     public void writeExternal(final ObjectOutput out) {
46         SerializationUtils.serializePathAndNode(getIdentifier(), node, out);
47     }
48
49     @Override
50     public void readExternal(final ObjectInput in) {
51         SerializationUtils.deserializePathAndNode(in, this, APPLIER);
52     }
53
54     @Override
55     public String toString() {
56         return "NormalizedNodeMessage [identifier=" + identifier + ", node=" + node + "]";
57     }
58
59     private static final SerializationUtils.Applier<NormalizedNodeMessage> APPLIER = (instance, path, node) -> {
60         instance.identifier = path;
61         instance.node = node;
62     };
63 }