Bug 6911 - RPC support in singleton
[netconf.git] / netconf / 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
9 package org.opendaylight.netconf.topology.singleton.messages.rpc;
10
11 import java.io.Externalizable;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import java.io.Serializable;
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.SchemaPath;
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 NormalizedNodeMessage normalizedNodeMessage) {
28         this.schemaPathMessage = schemaPathMessage;
29         this.normalizedNodeMessage = normalizedNodeMessage;
30     }
31     private SchemaPathMessage getSchemaPathMessage() {
32         return schemaPathMessage;
33     }
34
35     public SchemaPath getSchemaPath() {
36         return schemaPathMessage.getSchemaPath();
37     }
38
39     public NormalizedNodeMessage getNormalizedNodeMessage() {
40         return normalizedNodeMessage;
41     }
42
43     private Object writeReplace() {
44         return new Proxy(this);
45     }
46
47     private static class Proxy implements Externalizable {
48         private static final long serialVersionUID = 2L;
49
50         private InvokeRpcMessage invokeRpcMessage;
51
52         public Proxy() {
53             //due to Externalizable
54         }
55
56         Proxy(final InvokeRpcMessage invokeRpcMessage) {
57             this.invokeRpcMessage = invokeRpcMessage;
58         }
59
60         @Override
61         public void writeExternal(final ObjectOutput out) throws IOException {
62             out.writeObject(invokeRpcMessage.getSchemaPathMessage());
63             out.writeObject(invokeRpcMessage.getNormalizedNodeMessage());
64         }
65
66         @Override
67         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
68             invokeRpcMessage = new InvokeRpcMessage((SchemaPathMessage) in.readObject(),
69                     (NormalizedNodeMessage) in.readObject());
70         }
71
72         private Object readResolve() {
73             return invokeRpcMessage;
74         }
75     }
76 }