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.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
23 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
24 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput;
25 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
26 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
28 public final class ExecuteAction extends AbstractExecute<@NonNull ContainerNode> {
29 private static final long serialVersionUID = 1128904894827335676L;
31 private final @NonNull DOMDataTreeIdentifier path;
33 private ExecuteAction(final @NonNull SchemaPath type, final @NonNull DOMDataTreeIdentifier path,
34 final @NonNull ContainerNode input) {
35 super(type, requireNonNull(input));
36 this.path = requireNonNull(path);
39 public static @NonNull ExecuteAction from(final @NonNull SchemaPath type, @NonNull final DOMDataTreeIdentifier path,
40 final @NonNull ContainerNode input) {
41 return new ExecuteAction(type, path, input);
44 public @NonNull DOMDataTreeIdentifier getPath() {
49 ToStringHelper addToStringAttributes(final ToStringHelper helper) {
50 return super.addToStringAttributes(helper.add("path", path));
54 Object writeReplace() {
55 return new Proxy(this);
58 private static final class Proxy implements Externalizable {
59 private static final long serialVersionUID = 1L;
61 private ExecuteAction executeAction;
63 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
64 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
65 @SuppressWarnings("checkstyle:RedundantModifier")
70 Proxy(final ExecuteAction executeAction) {
71 this.executeAction = requireNonNull(executeAction);
75 public void writeExternal(final ObjectOutput out) throws IOException {
76 try (NormalizedNodeDataOutput stream = NormalizedNodeStreamVersion.current().newDataOutput(out)) {
77 stream.writeSchemaPath(executeAction.getType());
78 executeAction.getPath().getDatastoreType().writeTo(out);
79 stream.writeYangInstanceIdentifier(executeAction.getPath().getRootIdentifier());
80 stream.writeOptionalNormalizedNode(executeAction.getInput());
85 public void readExternal(final ObjectInput in) throws IOException {
86 final NormalizedNodeDataInput stream = NormalizedNodeDataInput.newDataInput(in);
87 final SchemaPath name = stream.readSchemaPath();
88 final LogicalDatastoreType type = LogicalDatastoreType.readFrom(in);
89 final YangInstanceIdentifier path = stream.readYangInstanceIdentifier();
90 final ContainerNode input = (ContainerNode) stream.readOptionalNormalizedNode().orElse(null);
92 executeAction = new ExecuteAction(name, new DOMDataTreeIdentifier(type, path), input);
95 private Object readResolve() {
96 return verifyNotNull(executeAction);