2 * Copyright (c) 2014 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;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.Preconditions;
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import java.io.Serializable;
18 import javax.annotation.Nonnull;
19 import javax.annotation.Nullable;
20 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
21 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
29 public class ExecuteRpc implements Serializable {
30 private static final long serialVersionUID = 1128904894827335676L;
32 private final NormalizedNode<?, ?> inputNormalizedNode;
33 private final QName rpc;
35 private ExecuteRpc(@Nullable final NormalizedNode<?, ?> inputNormalizedNode, @Nonnull final QName rpc) {
36 this.rpc = Preconditions.checkNotNull(rpc, "rpc Qname should not be null");
37 this.inputNormalizedNode = inputNormalizedNode;
40 public static ExecuteRpc from(@Nonnull final DOMRpcIdentifier rpc, @Nullable final NormalizedNode<?, ?> input) {
41 return new ExecuteRpc(input, rpc.getType().getLastComponent());
45 public NormalizedNode<?, ?> getInputNormalizedNode() {
46 return inputNormalizedNode;
50 public QName getRpc() {
54 private Object writeReplace() {
55 return new Proxy(this);
59 public String toString() {
60 return MoreObjects.toStringHelper(this)
62 .add("normalizedNode", inputNormalizedNode)
66 private static class Proxy implements Externalizable {
67 private static final long serialVersionUID = 1L;
69 private ExecuteRpc executeRpc;
71 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
72 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
73 @SuppressWarnings("checkstyle:RedundantModifier")
77 Proxy(ExecuteRpc executeRpc) {
78 this.executeRpc = executeRpc;
82 public void writeExternal(ObjectOutput out) throws IOException {
83 out.writeObject(executeRpc.getRpc());
84 SerializationUtils.serializeNormalizedNode(executeRpc.getInputNormalizedNode(), out);
88 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
89 QName qname = (QName) in.readObject();
90 executeRpc = new ExecuteRpc(SerializationUtils.deserializeNormalizedNode(in), qname);
93 private Object readResolve() {