BUG-8402: correctly propagate read-only bit
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / AbstractReadPathTransactionRequestProxyV1.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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 akka.actor.ActorRef;
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.YangInstanceIdentifier;
18
19 /**
20  * Abstract base class for serialization proxies associated with {@link AbstractReadTransactionRequest}s. It implements
21  * the initial (Boron) serialization format.
22  *
23  * @author Robert Varga
24  *
25  * @param <T> Message type
26  */
27 abstract class AbstractReadPathTransactionRequestProxyV1<T extends AbstractReadPathTransactionRequest<T>>
28         extends AbstractReadTransactionRequestProxyV1<T> {
29     private static final long serialVersionUID = 1L;
30     private YangInstanceIdentifier path;
31
32     protected AbstractReadPathTransactionRequestProxyV1() {
33         // For Externalizable
34     }
35
36     AbstractReadPathTransactionRequestProxyV1(final T request) {
37         super(request);
38         path = request.getPath();
39     }
40
41     @Override
42     public final void writeExternal(final ObjectOutput out) throws IOException {
43         super.writeExternal(out);
44         try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out)) {
45             nnout.writeYangInstanceIdentifier(path);
46         }
47     }
48
49     @Override
50     public final void readExternal(final ObjectInput in) throws ClassNotFoundException, IOException {
51         super.readExternal(in);
52         path = NormalizedNodeInputOutput.newDataInput(in).readYangInstanceIdentifier();
53     }
54
55     @Override
56     protected final T createReadRequest(final TransactionIdentifier target, final long sequence,
57             final ActorRef replyTo, final boolean snapshotOnly) {
58         return createReadPathRequest(target, sequence, replyTo, path, snapshotOnly);
59     }
60
61     abstract T createReadPathRequest(TransactionIdentifier target, long sequence, ActorRef replyTo,
62             YangInstanceIdentifier requestPath, boolean snapshotOnly);
63 }