BUG-5280: add basic concept of ClientSnapshot
[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 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 AbstractReadTransactionRequestProxyV1<T extends AbstractReadTransactionRequest<T>>
28         extends AbstractTransactionRequestProxy<T> {
29     private static final long serialVersionUID = 1L;
30     private YangInstanceIdentifier path;
31     private boolean snapshotOnly;
32
33     protected AbstractReadTransactionRequestProxyV1() {
34         // For Externalizable
35     }
36
37     AbstractReadTransactionRequestProxyV1(final T request) {
38         super(request);
39         path = request.getPath();
40         snapshotOnly = request.isSnapshotOnly();
41     }
42
43     @Override
44     public final void writeExternal(final ObjectOutput out) throws IOException {
45         super.writeExternal(out);
46         try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(out)) {
47             nnout.writeYangInstanceIdentifier(path);
48         }
49         out.writeBoolean(snapshotOnly);
50     }
51
52     @Override
53     public final void readExternal(final ObjectInput in) throws ClassNotFoundException, IOException {
54         super.readExternal(in);
55         path = NormalizedNodeInputOutput.newDataInput(in).readYangInstanceIdentifier();
56         snapshotOnly = in.readBoolean();
57     }
58
59     @Override
60     protected final T createRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo) {
61         return createReadRequest(target, sequence, replyTo, path, snapshotOnly);
62     }
63
64     abstract T createReadRequest(TransactionIdentifier target, long sequence, ActorRef replyTo,
65             YangInstanceIdentifier requestPath, boolean snapshotOnly);
66 }