X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2Fmessages%2FRpcResponse.java;h=02d0f1f185116ce30ce0d46754ff26aefe4dd86f;hb=refs%2Fchanges%2F11%2F80211%2F6;hp=387cb90112dad6ffbab6fb7cce7bf7c1d92442f1;hpb=b131db5779e46e9555aa3358c5b6aa13109ef8f5;p=controller.git diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/RpcResponse.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/RpcResponse.java index 387cb90112..02d0f1f185 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/RpcResponse.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/RpcResponse.java @@ -7,17 +7,62 @@ */ package org.opendaylight.controller.remote.rpc.messages; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.io.Serializable; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; public class RpcResponse implements Serializable { - private static final long serialVersionUID = 1L; - private final String resultCompositeNode; + private static final long serialVersionUID = -4211279498688989245L; - public RpcResponse(final String resultCompositeNode) { - this.resultCompositeNode = resultCompositeNode; - } + @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class " + + "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class " + + "aren't serialized. FindBugs does not recognize this.") + private final NormalizedNode resultNormalizedNode; - public String getResultCompositeNode() { - return resultCompositeNode; - } + public RpcResponse(final @Nullable NormalizedNode inputNormalizedNode) { + resultNormalizedNode = inputNormalizedNode; + } + + public @Nullable NormalizedNode getResultNormalizedNode() { + return resultNormalizedNode; + } + + private Object writeReplace() { + return new Proxy(this); + } + + private static class Proxy implements Externalizable { + private static final long serialVersionUID = 1L; + + private RpcResponse rpcResponse; + + // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't + // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection. + @SuppressWarnings("checkstyle:RedundantModifier") + public Proxy() { + } + + Proxy(RpcResponse rpcResponse) { + this.rpcResponse = rpcResponse; + } + + @Override + public void writeExternal(ObjectOutput out) { + SerializationUtils.serializeNormalizedNode(rpcResponse.getResultNormalizedNode(), out); + } + + @Override + public void readExternal(ObjectInput in) { + rpcResponse = new RpcResponse(SerializationUtils.deserializeNormalizedNode(in)); + } + + private Object readResolve() { + return rpcResponse; + } + } }