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
8 package org.opendaylight.controller.cluster.access.commands;
10 import com.google.common.base.Optional;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
15 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataOutput;
16 import org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeInputOutput;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 * Externalizable proxy for use with {@link ReadTransactionSuccess}. It implements the initial (Boron) serialization
23 * @author Robert Varga
25 final class ReadTransactionSuccessProxyV1 extends AbstractTransactionSuccessProxy<ReadTransactionSuccess> {
26 private static final long serialVersionUID = 1L;
27 private Optional<NormalizedNode<?, ?>> data;
29 // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
30 // be able to create instances via reflection.
31 @SuppressWarnings("checkstyle:RedundantModifier")
32 public ReadTransactionSuccessProxyV1() {
36 ReadTransactionSuccessProxyV1(final ReadTransactionSuccess request) {
38 this.data = request.getData();
42 public void writeExternal(final ObjectOutput out) throws IOException {
43 super.writeExternal(out);
45 if (data.isPresent()) {
46 out.writeBoolean(true);
47 try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out)) {
48 nnout.writeNormalizedNode(data.get());
51 out.writeBoolean(false);
56 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
57 super.readExternal(in);
59 if (in.readBoolean()) {
60 data = Optional.of(NormalizedNodeInputOutput.newDataInput(in).readNormalizedNode());
62 data = Optional.absent();
67 protected ReadTransactionSuccess createSuccess(final TransactionIdentifier target, final long sequence) {
68 return new ReadTransactionSuccess(target, sequence, data);