X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2Fmessages%2FExecuteRpc.java;h=cfa0c8964f93d978043d30e3078619bf1fb94783;hp=5d780be641e2cce6d2b48a2628cd675f9a24c8ee;hb=927bce5688e4b9d33d3e5e9b769d8a0dba5ccdd4;hpb=3927509ec3ecfa32a51b725d2b7155d425f5b877 diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/ExecuteRpc.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/ExecuteRpc.java index 5d780be641..cfa0c8964f 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/ExecuteRpc.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/ExecuteRpc.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -7,30 +7,72 @@ */ package org.opendaylight.controller.remote.rpc.messages; +import static java.util.Objects.requireNonNull; -import com.google.common.base.Preconditions; -import java.io.Serializable; -import org.opendaylight.yangtools.yang.common.QName; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput; +import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput; +import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; -public class ExecuteRpc implements Serializable { +public final class ExecuteRpc extends AbstractExecute<@Nullable NormalizedNode> { private static final long serialVersionUID = 1128904894827335676L; - private final String inputCompositeNode; - private final QName rpc; - - public ExecuteRpc(final String inputCompositeNode, final QName rpc) { - Preconditions.checkNotNull(inputCompositeNode, "Composite Node input string should be present"); - Preconditions.checkNotNull(rpc, "rpc Qname should not be null"); + private ExecuteRpc(final @NonNull SchemaPath type, final @Nullable NormalizedNode input) { + super(type, input); + } - this.inputCompositeNode = inputCompositeNode; - this.rpc = rpc; + public static @NonNull ExecuteRpc from(final @NonNull DOMRpcIdentifier rpc, + final @Nullable NormalizedNode input) { + return new ExecuteRpc(rpc.getType(), input); } - public String getInputCompositeNode() { - return inputCompositeNode; + @Override + Object writeReplace() { + return new Proxy(this); } - public QName getRpc() { - return rpc; + private static final class Proxy implements Externalizable { + private static final long serialVersionUID = 1L; + + private ExecuteRpc executeRpc; + + // 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(final ExecuteRpc executeRpc) { + this.executeRpc = requireNonNull(executeRpc); + } + + @Override + public void writeExternal(final ObjectOutput out) throws IOException { + try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out)) { + stream.writeQName(executeRpc.getType().getLastComponent()); + stream.writeOptionalNormalizedNode(executeRpc.getInput()); + } + } + + @Override + public void readExternal(final ObjectInput in) throws IOException { + final NormalizedNodeDataInput stream = NormalizedNodeInputOutput.newDataInput(in); + final SchemaPath type = SchemaPath.ROOT.createChild(stream.readQName()); + final NormalizedNode input = stream.readOptionalNormalizedNode().orElse(null); + executeRpc = new ExecuteRpc(type, input); + } + + private Object readResolve() { + return executeRpc; + } } }