Bump cds-access-api ABIVersion
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / ReadTransactionSuccessProxyV1.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.access.commands;
9
10 import java.io.IOException;
11 import java.io.ObjectInput;
12 import java.io.ObjectOutput;
13 import java.util.Optional;
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.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamVersion;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19
20 /**
21  * Externalizable proxy for use with {@link ReadTransactionSuccess}. It implements the initial (Boron) serialization
22  * format.
23  *
24  * @author Robert Varga
25  */
26 final class ReadTransactionSuccessProxyV1 extends AbstractTransactionSuccessProxy<ReadTransactionSuccess> {
27     private static final long serialVersionUID = 1L;
28
29     private Optional<NormalizedNode<?, ?>> data;
30     private transient NormalizedNodeStreamVersion streamVersion;
31
32     // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
33     // be able to create instances via reflection.
34     @SuppressWarnings("checkstyle:RedundantModifier")
35     public ReadTransactionSuccessProxyV1() {
36         // For Externalizable
37     }
38
39     ReadTransactionSuccessProxyV1(final ReadTransactionSuccess request) {
40         super(request);
41         this.data = request.getData();
42         this.streamVersion = request.getVersion().getStreamVersion();
43     }
44
45     @Override
46     public void writeExternal(final ObjectOutput out) throws IOException {
47         super.writeExternal(out);
48
49         if (data.isPresent()) {
50             out.writeBoolean(true);
51             try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out, streamVersion)) {
52                 nnout.writeNormalizedNode(data.get());
53             }
54         } else {
55             out.writeBoolean(false);
56         }
57     }
58
59     @Override
60     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
61         super.readExternal(in);
62
63         if (in.readBoolean()) {
64             data = Optional.of(NormalizedNodeInputOutput.newDataInput(in).readNormalizedNode());
65         } else {
66             data = Optional.empty();
67         }
68     }
69
70     @Override
71     protected ReadTransactionSuccess createSuccess(final TransactionIdentifier target, final long sequence) {
72         return new ReadTransactionSuccess(target, sequence, data);
73     }
74 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.