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.DOMStoreReadWriteTransaction;
15 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
16 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedTransactions;
17 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction;
18 import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
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.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * {@link LocalTransactionFactory} for instantiating backing transactions which are
26 * disconnected from each other, ie not chained. These are used by {@link AbstractTransactionContextFactory}
27 * to instantiate transactions on shards which are co-located with the shard leader.
29 final class LocalTransactionFactoryImpl extends TransactionReadyPrototype<TransactionIdentifier>
30 implements LocalTransactionFactory {
32 private static final Logger LOG = LoggerFactory.getLogger(LocalTransactionFactoryImpl.class);
33 private final ActorSelection leader;
34 private final DataTree dataTree;
35 private final ActorContext actorContext;
37 LocalTransactionFactoryImpl(final ActorContext actorContext, final ActorSelection leader, final DataTree dataTree) {
38 this.leader = Preconditions.checkNotNull(leader);
39 this.dataTree = Preconditions.checkNotNull(dataTree);
40 this.actorContext = actorContext;
43 DataTree getDataTree() {
48 public DOMStoreReadWriteTransaction newReadWriteTransaction(TransactionIdentifier identifier) {
49 return SnapshotBackedTransactions.newReadWriteTransaction(identifier, false, dataTree.takeSnapshot(), this);
53 protected void transactionAborted(final SnapshotBackedWriteTransaction<TransactionIdentifier> tx) {
58 protected DOMStoreThreePhaseCommitCohort transactionReady(final SnapshotBackedWriteTransaction<TransactionIdentifier> tx,
59 final DataTreeModification tree) {
60 return new LocalThreePhaseCommitCohort(actorContext, leader, tx, tree) {
62 protected void transactionAborted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
64 LOG.debug("Transaction {} aborted", transaction);
68 protected void transactionCommitted(final SnapshotBackedWriteTransaction<TransactionIdentifier> transaction) {
70 LOG.debug("Transaction {} committed", transaction);