BUG-8402: correctly propagate read-only bit
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / AbstractReadTransactionRequestProxyV1.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 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
16 /**
17  * Abstract base class for serialization proxies associated with {@link AbstractReadTransactionRequest}s. It implements
18  * the initial (Boron) serialization format.
19  *
20  * @author Robert Varga
21  *
22  * @param <T> Message type
23  */
24 abstract class AbstractReadTransactionRequestProxyV1<T extends AbstractReadTransactionRequest<T>>
25         extends AbstractTransactionRequestProxy<T> {
26     private static final long serialVersionUID = 1L;
27     private boolean snapshotOnly;
28
29     protected AbstractReadTransactionRequestProxyV1() {
30         // For Externalizable
31     }
32
33     AbstractReadTransactionRequestProxyV1(final T request) {
34         super(request);
35         snapshotOnly = request.isSnapshotOnly();
36     }
37
38     @Override
39     public void writeExternal(final ObjectOutput out) throws IOException {
40         super.writeExternal(out);
41         out.writeBoolean(snapshotOnly);
42     }
43
44     @Override
45     public void readExternal(final ObjectInput in) throws ClassNotFoundException, IOException {
46         super.readExternal(in);
47         snapshotOnly = in.readBoolean();
48     }
49
50     @Override
51     protected final T createRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo) {
52         return createReadRequest(target, sequence, replyTo, snapshotOnly);
53     }
54
55     abstract T createReadRequest(TransactionIdentifier target, long sequence, ActorRef replyTo, boolean snapshotOnly);
56 }