5c00cf16507344febb6fcce8d87d897863f1145d
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / ReadDataReply.java
1 /*
2  * Copyright (c) 2014 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.controller.cluster.datastore.messages;
10
11 import java.io.IOException;
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.schema.NormalizedNode;
16
17 public class ReadDataReply extends VersionedExternalizableMessage {
18     private static final long serialVersionUID = 1L;
19
20     private NormalizedNode<?, ?> normalizedNode;
21
22     public ReadDataReply() {
23     }
24
25     public ReadDataReply(final NormalizedNode<?, ?> normalizedNode, final short version) {
26         super(version);
27         this.normalizedNode = normalizedNode;
28     }
29
30     public NormalizedNode<?, ?> getNormalizedNode() {
31         return normalizedNode;
32     }
33
34     @Override
35     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
36         super.readExternal(in);
37         normalizedNode = SerializationUtils.readNormalizedNode(in).orElse(null);
38     }
39
40     @Override
41     public void writeExternal(final ObjectOutput out) throws IOException {
42         super.writeExternal(out);
43         SerializationUtils.writeNormalizedNode(out, normalizedNode);
44     }
45
46     public static ReadDataReply fromSerializable(final Object serializable) {
47         return (ReadDataReply) serializable;
48     }
49
50     public static boolean isSerializedType(final Object message) {
51         return message instanceof ReadDataReply;
52     }
53 }