2 * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. 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 java.util.Objects.requireNonNull;
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
21 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput;
22 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
25 public final class ExecuteRpc extends AbstractExecute<@Nullable NormalizedNode<?, ?>> {
26 private static final long serialVersionUID = 1128904894827335676L;
28 private ExecuteRpc(final @NonNull SchemaPath type, final @Nullable NormalizedNode<?, ?> input) {
32 public static @NonNull ExecuteRpc from(final @NonNull DOMRpcIdentifier rpc,
33 final @Nullable NormalizedNode<?, ?> input) {
34 return new ExecuteRpc(rpc.getType(), input);
38 Object writeReplace() {
39 return new Proxy(this);
42 private static final class Proxy implements Externalizable {
43 private static final long serialVersionUID = 1L;
45 private ExecuteRpc executeRpc;
47 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
48 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
49 @SuppressWarnings("checkstyle:RedundantModifier")
54 Proxy(final ExecuteRpc executeRpc) {
55 this.executeRpc = requireNonNull(executeRpc);
59 public void writeExternal(final ObjectOutput out) throws IOException {
60 try (NormalizedNodeDataOutput stream = NormalizedNodeStreamVersion.current().newDataOutput(out)) {
61 stream.writeQName(executeRpc.getType().getLastComponent());
62 stream.writeOptionalNormalizedNode(executeRpc.getInput());
67 public void readExternal(final ObjectInput in) throws IOException {
68 final NormalizedNodeDataInput stream = NormalizedNodeDataInput.newDataInput(in);
69 final SchemaPath type = SchemaPath.ROOT.createChild(stream.readQName());
70 final NormalizedNode<?, ?> input = stream.readOptionalNormalizedNode().orElse(null);
71 executeRpc = new ExecuteRpc(type, input);
74 private Object readResolve() {