1324e7e2f8c23be5f7a7425c3eab0e8e0efae250
[netconf.git] / apps / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / messages / rpc / InvokeRpcMessage.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 package org.opendaylight.netconf.topology.singleton.messages.rpc;
9
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import java.io.Serializable;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage;
17 import org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage;
18 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
19
20 public class InvokeRpcMessage implements Serializable {
21     private static final long serialVersionUID = 1L;
22
23     private final SchemaPathMessage schemaPathMessage;
24     private final NormalizedNodeMessage normalizedNodeMessage;
25
26     public InvokeRpcMessage(final SchemaPathMessage schemaPathMessage,
27                             final @Nullable NormalizedNodeMessage normalizedNodeMessage) {
28         this.schemaPathMessage = schemaPathMessage;
29         this.normalizedNodeMessage = normalizedNodeMessage;
30     }
31
32     SchemaPathMessage getSchemaPathMessage() {
33         return schemaPathMessage;
34     }
35
36     public Absolute getSchemaPath() {
37         return schemaPathMessage.getSchemaPath();
38     }
39
40     public @Nullable NormalizedNodeMessage getNormalizedNodeMessage() {
41         return normalizedNodeMessage;
42     }
43
44     private Object writeReplace() {
45         return new Proxy(this);
46     }
47
48     @Override
49     public String toString() {
50         return "InvokeRpcMessage [schemaPathMessage=" + schemaPathMessage + ", normalizedNodeMessage="
51                 + normalizedNodeMessage + "]";
52     }
53
54     private static class Proxy implements Externalizable {
55         private static final long serialVersionUID = 2L;
56
57         private InvokeRpcMessage invokeRpcMessage;
58
59         @SuppressWarnings("checkstyle:RedundantModifier")
60         public Proxy() {
61             //due to Externalizable
62         }
63
64         Proxy(final InvokeRpcMessage invokeRpcMessage) {
65             this.invokeRpcMessage = invokeRpcMessage;
66         }
67
68         @Override
69         public void writeExternal(final ObjectOutput out) throws IOException {
70             out.writeObject(invokeRpcMessage.getSchemaPathMessage());
71             out.writeObject(invokeRpcMessage.getNormalizedNodeMessage());
72         }
73
74         @Override
75         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
76             invokeRpcMessage = new InvokeRpcMessage((SchemaPathMessage) in.readObject(),
77                     (NormalizedNodeMessage) in.readObject());
78         }
79
80         private Object readResolve() {
81             return invokeRpcMessage;
82         }
83     }
84 }