f141f09b3ccb42aa2f1adedb7c2299abba0e82da
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / messages / RpcResponse.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 package org.opendaylight.controller.remote.rpc.messages;
9
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17
18 public class RpcResponse extends AbstractResponse<NormalizedNode<?, ?>> {
19     private static final long serialVersionUID = -4211279498688989245L;
20
21     public RpcResponse(final @Nullable NormalizedNode<?, ?> output) {
22         super(output);
23     }
24
25     @Override
26     Object writeReplace() {
27         return new Proxy(this);
28     }
29
30     private static class Proxy implements Externalizable {
31         private static final long serialVersionUID = 1L;
32
33         private RpcResponse rpcResponse;
34
35         // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
36         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
37         @SuppressWarnings("checkstyle:RedundantModifier")
38         public Proxy() {
39         }
40
41         Proxy(final RpcResponse rpcResponse) {
42             this.rpcResponse = rpcResponse;
43         }
44
45         @Override
46         public void writeExternal(final ObjectOutput out) throws IOException {
47             SerializationUtils.writeNormalizedNode(out, rpcResponse.getOutput());
48         }
49
50         @Override
51         public void readExternal(final ObjectInput in) throws IOException {
52             rpcResponse = new RpcResponse(SerializationUtils.readNormalizedNode(in).orElse(null));
53         }
54
55         private Object readResolve() {
56             return rpcResponse;
57         }
58     }
59 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.