Bug 6714 - Use singleton service in clustered netconf topology
[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.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
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.NormalizedNodeInputOutput;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
21 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
22
23 /**
24  * Message which holds node data, prepared to sending between remote hosts with serialization.
25  */
26 public class NormalizedNodeMessage implements Externalizable {
27     private static final long serialVersionUID = 1L;
28
29     private YangInstanceIdentifier identifier = null;
30     private NormalizedNode<?, ?> node = null;
31
32     public NormalizedNodeMessage() {
33         // empty constructor needed for Externalizable
34     }
35
36     public NormalizedNodeMessage(final YangInstanceIdentifier identifier, final NormalizedNode<?, ?> node) {
37         this.identifier = identifier;
38         this.node = node;
39     }
40
41     public YangInstanceIdentifier getIdentifier() {
42         return identifier;
43     }
44
45     public NormalizedNode<?, ?> getNode() {
46         return node;
47     }
48
49     @Override
50     public void writeExternal(final ObjectOutput out) throws IOException {
51         final NormalizedNodeDataOutput dataOutput = NormalizedNodeInputOutput.newDataOutput(out);
52         final NormalizedNodeWriter normalizedNodeWriter =
53                 NormalizedNodeWriter.forStreamWriter((NormalizedNodeStreamWriter) dataOutput);
54
55         dataOutput.writeYangInstanceIdentifier(identifier);
56
57         normalizedNodeWriter.write(node);
58     }
59
60     @Override
61     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
62         final NormalizedNodeDataInput dataInput = NormalizedNodeInputOutput.newDataInput(in);
63
64         identifier = dataInput.readYangInstanceIdentifier();
65         node = dataInput.readNormalizedNode();
66     }
67 }