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 static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import akka.actor.ActorSelection;
14 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
15 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
16 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
17 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
18 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
19 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
20 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedTransactions;
21 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction;
22 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
23 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
24 import org.opendaylight.yangtools.yang.data.api.schema.tree.ReadOnlyDataTree;
27 * {@link LocalTransactionFactory} for instantiating backing transactions which are
28 * disconnected from each other, ie not chained. These are used by {@link AbstractTransactionContextFactory}
29 * to instantiate transactions on shards which are co-located with the shard leader.
31 final class LocalTransactionFactoryImpl extends TransactionReadyPrototype<TransactionIdentifier>
32 implements LocalTransactionFactory {
34 private final ActorSelection leader;
35 private final ReadOnlyDataTree dataTree;
36 private final ActorUtils actorUtils;
38 LocalTransactionFactoryImpl(final ActorUtils actorUtils, final ActorSelection leader,
39 final ReadOnlyDataTree dataTree) {
40 this.leader = requireNonNull(leader);
41 this.dataTree = requireNonNull(dataTree);
42 this.actorUtils = actorUtils;
45 ReadOnlyDataTree getDataTree() {
50 public DOMStoreReadTransaction newReadOnlyTransaction(TransactionIdentifier identifier) {
51 return SnapshotBackedTransactions.newReadTransaction(identifier, false, dataTree.takeSnapshot());
55 public DOMStoreReadWriteTransaction newReadWriteTransaction(TransactionIdentifier identifier) {
56 return SnapshotBackedTransactions.newReadWriteTransaction(identifier, false, dataTree.takeSnapshot(), this);
60 public DOMStoreWriteTransaction newWriteOnlyTransaction(TransactionIdentifier identifier) {
61 return SnapshotBackedTransactions.newWriteTransaction(identifier, false, dataTree.takeSnapshot(), this);
65 protected void transactionAborted(final SnapshotBackedWriteTransaction<TransactionIdentifier> tx) {
70 protected DOMStoreThreePhaseCommitCohort transactionReady(
71 final SnapshotBackedWriteTransaction<TransactionIdentifier> tx,
72 final DataTreeModification tree,
73 final Exception readyError) {
74 return new LocalThreePhaseCommitCohort(actorUtils, leader, tx, tree, readyError);
77 @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch"})
79 public LocalThreePhaseCommitCohort onTransactionReady(DOMStoreWriteTransaction tx, Exception operationError) {
80 checkArgument(tx instanceof SnapshotBackedWriteTransaction);
81 if (operationError != null) {
82 return new LocalThreePhaseCommitCohort(actorUtils, leader,
83 (SnapshotBackedWriteTransaction<TransactionIdentifier>)tx, operationError);
86 return (LocalThreePhaseCommitCohort) tx.ready();