BUG-8704: rework seal mechanics to not wait during replay
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / LocalReadOnlyProxyTransaction.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.databroker.actors.dds;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.base.Verify;
12 import java.util.function.Consumer;
13 import javax.annotation.concurrent.NotThreadSafe;
14 import org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest;
15 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest;
16 import org.opendaylight.controller.cluster.access.commands.PersistenceProtocol;
17 import org.opendaylight.controller.cluster.access.concepts.Response;
18 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
22
23 /**
24  * A read-only specialization of {@link LocalProxyTransaction}.
25  *
26  * @author Robert Varga
27  */
28 @NotThreadSafe
29 final class LocalReadOnlyProxyTransaction extends LocalProxyTransaction {
30
31     private final DataTreeSnapshot snapshot;
32
33     LocalReadOnlyProxyTransaction(final ProxyHistory parent, final TransactionIdentifier identifier,
34         final DataTreeSnapshot snapshot) {
35         super(parent, identifier, false);
36         this.snapshot = Preconditions.checkNotNull(snapshot);
37     }
38
39     LocalReadOnlyProxyTransaction(final ProxyHistory parent, final TransactionIdentifier identifier) {
40         super(parent, identifier, true);
41         // It is an error to touch snapshot once we are DONE
42         this.snapshot = null;
43     }
44
45     @Override
46     boolean isSnapshotOnly() {
47         return true;
48     }
49
50     @Override
51     DataTreeSnapshot readOnlyView() {
52         return Preconditions.checkNotNull(snapshot, "Transaction %s is DONE", getIdentifier());
53     }
54
55     @Override
56     void doDelete(final YangInstanceIdentifier path) {
57         throw new UnsupportedOperationException("Read-only snapshot");
58     }
59
60     @Override
61     void doMerge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
62         throw new UnsupportedOperationException("Read-only snapshot");
63     }
64
65     @Override
66     void doWrite(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
67         throw new UnsupportedOperationException("Read-only snapshot");
68     }
69
70     @Override
71     CommitLocalTransactionRequest commitRequest(final boolean coordinated) {
72         throw new UnsupportedOperationException("Read-only snapshot");
73     }
74
75     @Override
76     void flushState(final AbstractProxyTransaction successor) {
77         // No-op
78     }
79
80     @Override
81     void applyForwardedModifyTransactionRequest(final ModifyTransactionRequest request,
82             final Consumer<Response<?, ?>> callback) {
83         commonModifyTransactionRequest(request);
84         abort();
85     }
86
87     @Override
88     void replayModifyTransactionRequest(final ModifyTransactionRequest request,
89             final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
90         commonModifyTransactionRequest(request);
91         enqueueAbort(callback, enqueuedTicks);
92     }
93
94     private static void commonModifyTransactionRequest(final ModifyTransactionRequest request) {
95         Verify.verify(request.getModifications().isEmpty());
96
97         final PersistenceProtocol protocol = request.getPersistenceProtocol().get();
98         Verify.verify(protocol == PersistenceProtocol.ABORT);
99     }
100 }

©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.