2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore;
10 import akka.actor.ActorSelection;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
13 import org.opendaylight.controller.sal.core.spi.data.AbstractSnapshotBackedTransactionChain;
14 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
15 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
18 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
24 * Transaction chain instantiated on top of a locally-available DataTree. It does not instantiate
25 * a transaction in the leader and rather chains transactions on top of themselves.
27 final class LocalTransactionChain extends AbstractSnapshotBackedTransactionChain<TransactionIdentifier>
28 implements LocalTransactionFactory {
29 private static final Throwable ABORTED = new Throwable("Transaction aborted");
30 private final TransactionChainProxy parent;
31 private final ActorSelection leader;
32 private final DataTree tree;
34 LocalTransactionChain(final TransactionChainProxy parent, final ActorSelection leader, final DataTree tree) {
35 this.parent = Preconditions.checkNotNull(parent);
36 this.leader = Preconditions.checkNotNull(leader);
37 this.tree = Preconditions.checkNotNull(tree);
40 DataTree getDataTree() {
45 protected TransactionIdentifier nextTransactionIdentifier() {
46 throw new UnsupportedOperationException();
50 protected boolean getDebugTransactions() {
55 protected DataTreeSnapshot takeSnapshot() {
56 return tree.takeSnapshot();
60 protected DOMStoreThreePhaseCommitCohort createCohort(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction, final DataTreeModification modification) {
61 return new LocalThreePhaseCommitCohort(parent.getActorContext(), leader, transaction, modification) {
63 protected void transactionAborted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
64 onTransactionFailed(transaction, ABORTED);
68 protected void transactionCommitted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
69 onTransactionCommited(transaction);
75 public DOMStoreReadTransaction newReadOnlyTransaction(TransactionIdentifier identifier) {
76 return super.newReadOnlyTransaction(identifier);
80 public DOMStoreReadWriteTransaction newReadWriteTransaction(TransactionIdentifier identifier) {
81 return super.newReadWriteTransaction(identifier);
85 public DOMStoreWriteTransaction newWriteOnlyTransaction(TransactionIdentifier identifier) {
86 return super.newWriteOnlyTransaction(identifier);