Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / messages / ExecuteRpc.java
index c9fb52b6065daf841659e161868cd92b8a579726..cfa0c8964f93d978043d30e3078619bf1fb94783 100644 (file)
@@ -9,61 +9,37 @@ package org.opendaylight.controller.remote.rpc.messages;
 
 import static java.util.Objects.requireNonNull;
 
 
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.MoreObjects;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.io.Serializable;
 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.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.common.QName;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 
-public final class ExecuteRpc implements Serializable {
+public final class ExecuteRpc extends AbstractExecute<@Nullable NormalizedNode<?, ?>> {
     private static final long serialVersionUID = 1128904894827335676L;
 
     private static final long serialVersionUID = 1128904894827335676L;
 
-    @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<?, ?> inputNormalizedNode;
-    private final QName rpc;
-
-    private ExecuteRpc(final @Nullable NormalizedNode<?, ?> inputNormalizedNode, final @NonNull QName rpc) {
-        this.rpc = requireNonNull(rpc, "rpc Qname should not be null");
-        this.inputNormalizedNode = inputNormalizedNode;
-    }
-
-    public static ExecuteRpc from(final @NonNull DOMRpcIdentifier rpc, final @Nullable NormalizedNode<?, ?> input) {
-        return new ExecuteRpc(input, rpc.getType().getLastComponent());
-    }
-
-    public @Nullable NormalizedNode<?, ?> getInputNormalizedNode() {
-        return inputNormalizedNode;
+    private ExecuteRpc(final @NonNull SchemaPath type, final @Nullable NormalizedNode<?, ?> input) {
+        super(type, input);
     }
 
     }
 
-    public @NonNull QName getRpc() {
-        return rpc;
-    }
-
-    private Object writeReplace() {
-        return new Proxy(this);
+    public static @NonNull ExecuteRpc from(final @NonNull DOMRpcIdentifier rpc,
+            final @Nullable NormalizedNode<?, ?> input) {
+        return new ExecuteRpc(rpc.getType(), input);
     }
 
     @Override
     }
 
     @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(this)
-                .add("rpc", rpc)
-                .add("normalizedNode", inputNormalizedNode)
-                .toString();
+    Object writeReplace() {
+        return new Proxy(this);
     }
 
     }
 
-    private static class Proxy implements Externalizable {
+    private static final class Proxy implements Externalizable {
         private static final long serialVersionUID = 1L;
 
         private ExecuteRpc executeRpc;
         private static final long serialVersionUID = 1L;
 
         private ExecuteRpc executeRpc;
@@ -72,25 +48,27 @@ public final class ExecuteRpc implements Serializable {
         // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
         @SuppressWarnings("checkstyle:RedundantModifier")
         public Proxy() {
         // 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) {
         }
 
         Proxy(final ExecuteRpc executeRpc) {
-            this.executeRpc = executeRpc;
+            this.executeRpc = requireNonNull(executeRpc);
         }
 
         @Override
         public void writeExternal(final ObjectOutput out) throws IOException {
             try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out)) {
         }
 
         @Override
         public void writeExternal(final ObjectOutput out) throws IOException {
             try (NormalizedNodeDataOutput stream = NormalizedNodeInputOutput.newDataOutput(out)) {
-                stream.writeQName(executeRpc.getRpc());
-                stream.writeOptionalNormalizedNode(executeRpc.getInputNormalizedNode());
+                stream.writeQName(executeRpc.getType().getLastComponent());
+                stream.writeOptionalNormalizedNode(executeRpc.getInput());
             }
         }
 
         @Override
             }
         }
 
         @Override
-        public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+        public void readExternal(final ObjectInput in) throws IOException {
             final NormalizedNodeDataInput stream = NormalizedNodeInputOutput.newDataInput(in);
             final NormalizedNodeDataInput stream = NormalizedNodeInputOutput.newDataInput(in);
-            final QName qname = stream.readQName();
-            executeRpc = new ExecuteRpc(stream.readOptionalNormalizedNode().orElse(null), qname);
+            final SchemaPath type = SchemaPath.ROOT.createChild(stream.readQName());
+            final NormalizedNode<?, ?> input = stream.readOptionalNormalizedNode().orElse(null);
+            executeRpc = new ExecuteRpc(type, input);
         }
 
         private Object readResolve() {
         }
 
         private Object readResolve() {