2 * Copyright (c) 2016 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
9 package org.opendaylight.netconf.topology.singleton.messages.rpc;
11 import java.io.Externalizable;
12 import java.io.IOException;
13 import java.io.ObjectInput;
14 import java.io.ObjectOutput;
15 import java.io.Serializable;
16 import java.util.Collection;
17 import java.util.LinkedList;
18 import org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage;
19 import org.opendaylight.yangtools.yang.common.RpcError;
21 public class InvokeRpcMessageReply implements Serializable {
22 private static final long serialVersionUID = 1L;
24 private final Collection<RpcError> rpcErrors;
25 private final NormalizedNodeMessage normalizedNodeMessage;
27 public InvokeRpcMessageReply(final NormalizedNodeMessage normalizedNodeMessage,
28 final Collection<RpcError> rpcErrors) {
29 this.normalizedNodeMessage = normalizedNodeMessage;
30 this.rpcErrors = rpcErrors;
33 public NormalizedNodeMessage getNormalizedNodeMessage() {
34 return normalizedNodeMessage;
37 public Collection<RpcError> getRpcErrors() {
41 private Object writeReplace() {
42 return new Proxy(this);
45 private static class Proxy implements Externalizable {
46 private static final long serialVersionUID = 2L;
48 private InvokeRpcMessageReply invokeRpcMessageReply;
51 //due to Externalizable
54 Proxy(final InvokeRpcMessageReply invokeRpcMessageReply) {
55 this.invokeRpcMessageReply = invokeRpcMessageReply;
59 public void writeExternal(ObjectOutput out) throws IOException {
60 out.writeInt(invokeRpcMessageReply.getRpcErrors().size());
61 for (final RpcError rpcError : invokeRpcMessageReply.getRpcErrors()) {
62 out.writeObject(rpcError);
64 out.writeObject(invokeRpcMessageReply.getNormalizedNodeMessage());
68 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
69 final int size = in.readInt();
70 final Collection<RpcError> rpcErrors = new LinkedList<>();
71 for (int i = 0; i < size; i++) {
72 rpcErrors.add((RpcError) in.readObject());
74 final NormalizedNodeMessage normalizedNodeMessage = (NormalizedNodeMessage) in.readObject();
75 invokeRpcMessageReply = new InvokeRpcMessageReply(normalizedNodeMessage, rpcErrors);
78 private Object readResolve() {
79 return invokeRpcMessageReply;