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.DOMStoreReadWriteTransaction;
15 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
16 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
22 * Transaction chain instantiated on top of a locally-available DataTree. It does not instantiate
23 * a transaction in the leader and rather chains transactions on top of themselves.
25 final class LocalTransactionChain extends AbstractSnapshotBackedTransactionChain<TransactionIdentifier>
26 implements LocalTransactionFactory {
27 private static final Throwable ABORTED = new Throwable("Transaction aborted");
28 private final TransactionChainProxy parent;
29 private final ActorSelection leader;
30 private final DataTree tree;
32 LocalTransactionChain(final TransactionChainProxy parent, final ActorSelection leader, final DataTree tree) {
33 this.parent = Preconditions.checkNotNull(parent);
34 this.leader = Preconditions.checkNotNull(leader);
35 this.tree = Preconditions.checkNotNull(tree);
38 DataTree getDataTree() {
43 protected TransactionIdentifier nextTransactionIdentifier() {
44 throw new UnsupportedOperationException();
48 protected boolean getDebugTransactions() {
53 protected DataTreeSnapshot takeSnapshot() {
54 return tree.takeSnapshot();
58 protected DOMStoreThreePhaseCommitCohort createCohort(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction, final DataTreeModification modification) {
59 return new LocalThreePhaseCommitCohort(parent.getActorContext(), leader, transaction, modification) {
61 protected void transactionAborted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
62 onTransactionFailed(transaction, ABORTED);
66 protected void transactionCommitted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
67 onTransactionCommited(transaction);
73 public DOMStoreReadWriteTransaction newReadWriteTransaction(TransactionIdentifier identifier) {
74 return super.newReadWriteTransaction(identifier);