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