Lower visibility to package
[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 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.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 @Nullable NormalizedNodeMessage normalizedNodeMessage) {
28         this.schemaPathMessage = schemaPathMessage;
29         this.normalizedNodeMessage = normalizedNodeMessage;
30     }
31
32     SchemaPathMessage getSchemaPathMessage() {
33         return schemaPathMessage;
34     }
35
36     public SchemaPath getSchemaPath() {
37         return schemaPathMessage.getSchemaPath();
38     }
39
40
41     public @Nullable NormalizedNodeMessage getNormalizedNodeMessage() {
42         return normalizedNodeMessage;
43     }
44
45     private Object writeReplace() {
46         return new Proxy(this);
47     }
48
49     @Override
50     public String toString() {
51         return "InvokeRpcMessage [schemaPathMessage=" + schemaPathMessage + ", normalizedNodeMessage="
52                 + normalizedNodeMessage + "]";
53     }
54
55     private static class Proxy implements Externalizable {
56         private static final long serialVersionUID = 2L;
57
58         private InvokeRpcMessage invokeRpcMessage;
59
60         @SuppressWarnings("checkstyle:RedundantModifier")
61         public Proxy() {
62             //due to Externalizable
63         }
64
65         Proxy(final InvokeRpcMessage invokeRpcMessage) {
66             this.invokeRpcMessage = invokeRpcMessage;
67         }
68
69         @Override
70         public void writeExternal(final ObjectOutput out) throws IOException {
71             out.writeObject(invokeRpcMessage.getSchemaPathMessage());
72             out.writeObject(invokeRpcMessage.getNormalizedNodeMessage());
73         }
74
75         @Override
76         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
77             invokeRpcMessage = new InvokeRpcMessage((SchemaPathMessage) in.readObject(),
78                     (NormalizedNodeMessage) in.readObject());
79         }
80
81         private Object readResolve() {
82             return invokeRpcMessage;
83         }
84     }
85 }