2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.cluster.access.commands;
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.util.Optional;
17 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput;
22 * Externalizable proxy for use with {@link ReadTransactionSuccess}. It implements the Chlorine SR2 serialization
25 final class RTS implements TransactionSuccess.SerialForm<ReadTransactionSuccess> {
27 private static final long serialVersionUID = 1L;
29 private ReadTransactionSuccess message;
31 @SuppressWarnings("checkstyle:RedundantModifier")
36 RTS(final ReadTransactionSuccess message) {
37 this.message = requireNonNull(message);
41 public ReadTransactionSuccess message() {
42 return verifyNotNull(message);
46 public void setMessage(final ReadTransactionSuccess message) {
47 this.message = requireNonNull(message);
51 public ReadTransactionSuccess readExternal(final ObjectInput in, final TransactionIdentifier target,
52 final long sequence) throws IOException {
53 final Optional<NormalizedNode> data;
54 if (in.readBoolean()) {
55 data = Optional.of(NormalizedNodeDataInput.newDataInput(in).readNormalizedNode());
57 data = Optional.empty();
59 return new ReadTransactionSuccess(target, sequence, data);
63 public void writeExternal(final ObjectOutput out, final ReadTransactionSuccess msg) throws IOException {
64 TransactionSuccess.SerialForm.super.writeExternal(out, msg);
66 final var data = msg.getData();
67 if (data.isPresent()) {
68 out.writeBoolean(true);
69 try (var nnout = msg.getVersion().getStreamVersion().newDataOutput(out)) {
70 nnout.writeNormalizedNode(data.orElseThrow());
73 out.writeBoolean(false);
78 public Object readResolve() {