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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.io.Serializable;
17 import java.util.Collection;
18 import java.util.LinkedList;
19 import org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage;
20 import org.opendaylight.yangtools.yang.common.RpcError;
22 public class InvokeRpcMessageReply implements Serializable {
23 private static final long serialVersionUID = 1L;
25 @SuppressFBWarnings("SE_BAD_FIELD")
26 private final Collection<RpcError> rpcErrors;
27 private final NormalizedNodeMessage normalizedNodeMessage;
29 public InvokeRpcMessageReply(final NormalizedNodeMessage normalizedNodeMessage,
30 final Collection<RpcError> rpcErrors) {
31 this.normalizedNodeMessage = normalizedNodeMessage;
32 this.rpcErrors = rpcErrors;
35 public NormalizedNodeMessage getNormalizedNodeMessage() {
36 return normalizedNodeMessage;
39 public Collection<RpcError> getRpcErrors() {
43 private Object writeReplace() {
44 return new Proxy(this);
47 private static class Proxy implements Externalizable {
48 private static final long serialVersionUID = 2L;
50 private InvokeRpcMessageReply invokeRpcMessageReply;
52 @SuppressWarnings("checkstyle:RedundantModifier")
54 //due to Externalizable
57 Proxy(final InvokeRpcMessageReply invokeRpcMessageReply) {
58 this.invokeRpcMessageReply = invokeRpcMessageReply;
62 public void writeExternal(ObjectOutput out) throws IOException {
63 out.writeInt(invokeRpcMessageReply.getRpcErrors().size());
64 for (final RpcError rpcError : invokeRpcMessageReply.getRpcErrors()) {
65 out.writeObject(rpcError);
67 out.writeObject(invokeRpcMessageReply.getNormalizedNodeMessage());
71 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
72 final int size = in.readInt();
73 final Collection<RpcError> rpcErrors = new LinkedList<>();
74 for (int i = 0; i < size; i++) {
75 rpcErrors.add((RpcError) in.readObject());
77 final NormalizedNodeMessage normalizedNodeMessage = (NormalizedNodeMessage) in.readObject();
78 invokeRpcMessageReply = new InvokeRpcMessageReply(normalizedNodeMessage, rpcErrors);
81 private Object readResolve() {
82 return invokeRpcMessageReply;