2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.remote.rpc.messages;
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.io.Externalizable;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import java.io.Serializable;
15 import javax.annotation.Nullable;
16 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 public class RpcResponse implements Serializable {
20 private static final long serialVersionUID = -4211279498688989245L;
22 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class "
23 + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
24 + "aren't serialized. FindBugs does not recognize this.")
25 private final NormalizedNode<?, ?> resultNormalizedNode;
27 public RpcResponse(@Nullable final NormalizedNode<?, ?> inputNormalizedNode) {
28 resultNormalizedNode = inputNormalizedNode;
32 public NormalizedNode<?, ?> getResultNormalizedNode() {
33 return resultNormalizedNode;
36 private Object writeReplace() {
37 return new Proxy(this);
40 private static class Proxy implements Externalizable {
41 private static final long serialVersionUID = 1L;
43 private RpcResponse rpcResponse;
45 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
46 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
47 @SuppressWarnings("checkstyle:RedundantModifier")
51 Proxy(RpcResponse rpcResponse) {
52 this.rpcResponse = rpcResponse;
56 public void writeExternal(ObjectOutput out) {
57 SerializationUtils.serializeNormalizedNode(rpcResponse.getResultNormalizedNode(), out);
61 public void readExternal(ObjectInput in) {
62 rpcResponse = new RpcResponse(SerializationUtils.deserializeNormalizedNode(in));
65 private Object readResolve() {