2 * Copyright (c) 2019 Nordix Foundation. 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 static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import java.io.Externalizable;
15 import java.io.IOException;
16 import java.io.ObjectInput;
17 import java.io.ObjectOutput;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
20 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
21 import org.opendaylight.yangtools.yang.common.YangConstants;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
24 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
25 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput;
26 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
27 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
28 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
30 public final class ExecuteAction extends AbstractExecute {
31 private static final long serialVersionUID = 1128904894827335676L;
33 private final @NonNull DOMDataTreeIdentifier path;
35 private ExecuteAction(final @NonNull SchemaPath type, final @NonNull DOMDataTreeIdentifier path,
36 final @NonNull ContainerNode input) {
37 super(type, requireNonNull(input));
38 this.path = requireNonNull(path);
41 public static @NonNull ExecuteAction from(final @NonNull SchemaPath type, @NonNull final DOMDataTreeIdentifier path,
42 final @NonNull ContainerNode input) {
43 return new ExecuteAction(type, path, input);
46 public @NonNull DOMDataTreeIdentifier getPath() {
51 ToStringHelper addToStringAttributes(final ToStringHelper helper) {
52 return super.addToStringAttributes(helper.add("path", path));
56 Object writeReplace() {
57 return new Proxy(this);
60 private static final class Proxy implements Externalizable {
61 private static final long serialVersionUID = 1L;
63 private ExecuteAction executeAction;
65 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
66 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
67 @SuppressWarnings("checkstyle:RedundantModifier")
72 Proxy(final ExecuteAction executeAction) {
73 this.executeAction = requireNonNull(executeAction);
77 public void writeExternal(final ObjectOutput out) throws IOException {
78 try (NormalizedNodeDataOutput stream = NormalizedNodeStreamVersion.current().newDataOutput(out)) {
79 stream.writeSchemaPath(executeAction.getType());
80 executeAction.getPath().getDatastoreType().writeTo(out);
81 stream.writeYangInstanceIdentifier(executeAction.getPath().getRootIdentifier());
82 stream.writeOptionalNormalizedNode(executeAction.getInput());
87 public void readExternal(final ObjectInput in) throws IOException {
88 final NormalizedNodeDataInput stream = NormalizedNodeDataInput.newDataInput(in);
89 final SchemaPath name = stream.readSchemaPath();
90 final LogicalDatastoreType type = LogicalDatastoreType.readFrom(in);
91 final YangInstanceIdentifier path = stream.readYangInstanceIdentifier();
92 ContainerNode input = (ContainerNode) stream.readOptionalNormalizedNode().orElse(null);
94 input = ImmutableNodes.containerNode(
95 YangConstants.operationInputQName(name.getLastComponent().getModule()));
98 executeAction = new ExecuteAction(name, new DOMDataTreeIdentifier(type, path), input);
101 private Object readResolve() {
102 return verifyNotNull(executeAction);