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.cluster.datastore.utils.ActorContext;
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.SnapshotBackedTransactions;
19 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction;
20 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
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 static final Logger LOG = LoggerFactory.getLogger(LocalTransactionFactoryImpl.class);
35 private final ActorSelection leader;
36 private final DataTree dataTree;
37 private final ActorContext actorContext;
39 LocalTransactionFactoryImpl(final ActorContext actorContext, final ActorSelection leader, final DataTree dataTree) {
40 this.leader = Preconditions.checkNotNull(leader);
41 this.dataTree = Preconditions.checkNotNull(dataTree);
42 this.actorContext = actorContext;
45 DataTree 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(final SnapshotBackedWriteTransaction<TransactionIdentifier> tx,
71 final DataTreeModification tree) {
72 return new LocalThreePhaseCommitCohort(actorContext, leader, tx, tree) {
74 protected void transactionAborted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
76 LOG.debug("Transaction {} aborted", transaction);
80 protected void transactionCommitted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
82 LOG.debug("Transaction {} committed", transaction);