BUG-8538: rework transaction abort paths
[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);
36         this.snapshot = Preconditions.checkNotNull(snapshot);
37     }
38
39     @Override
40     boolean isSnapshotOnly() {
41         return true;
42     }
43
44     @Override
45     DataTreeSnapshot readOnlyView() {
46         return snapshot;
47     }
48
49     @Override
50     void doDelete(final YangInstanceIdentifier path) {
51         throw new UnsupportedOperationException("Read-only snapshot");
52     }
53
54     @Override
55     void doMerge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
56         throw new UnsupportedOperationException("Read-only snapshot");
57     }
58
59     @Override
60     void doWrite(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
61         throw new UnsupportedOperationException("Read-only snapshot");
62     }
63
64     @Override
65     CommitLocalTransactionRequest commitRequest(final boolean coordinated) {
66         throw new UnsupportedOperationException("Read-only snapshot");
67     }
68
69     @Override
70     void doSeal() {
71         // No-op
72     }
73
74     @Override
75     void flushState(final AbstractProxyTransaction successor) {
76         // No-op
77     }
78
79     @Override
80     void applyForwardedModifyTransactionRequest(final ModifyTransactionRequest request,
81             final Consumer<Response<?, ?>> callback) {
82         commonModifyTransactionRequest(request);
83         abort();
84     }
85
86     @Override
87     void replayModifyTransactionRequest(final ModifyTransactionRequest request,
88             final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
89         commonModifyTransactionRequest(request);
90         enqueueAbort(callback, enqueuedTicks);
91     }
92
93     private static void commonModifyTransactionRequest(final ModifyTransactionRequest request) {
94         Verify.verify(request.getModifications().isEmpty());
95
96         final PersistenceProtocol protocol = request.getPersistenceProtocol().get();
97         Verify.verify(protocol == PersistenceProtocol.ABORT);
98     }
99 }

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