X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FLocalTransactionFactoryImpl.java;fp=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FLocalTransactionFactoryImpl.java;h=dce9b5c55b1ccd7ec50635c176a6bbf1a11706ff;hp=0000000000000000000000000000000000000000;hb=daaef05cbf70e6cbec9af181258faead6d9620a6;hpb=e9ad27f7dd099e6e4930916ae26435977d58edf1 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactoryImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactoryImpl.java new file mode 100644 index 0000000000..dce9b5c55b --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactoryImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster.datastore; + +import akka.actor.ActorSelection; +import com.google.common.base.Preconditions; +import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import org.opendaylight.controller.cluster.datastore.utils.ActorContext; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; +import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedTransactions; +import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction; +import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction.TransactionReadyPrototype; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * {@link LocalTransactionFactory} for instantiating backing transactions which are + * disconnected from each other, ie not chained. These are used by {@link AbstractTransactionContextFactory} + * to instantiate transactions on shards which are co-located with the shard leader. + */ +final class LocalTransactionFactoryImpl extends TransactionReadyPrototype + implements LocalTransactionFactory { + + private static final Logger LOG = LoggerFactory.getLogger(LocalTransactionFactoryImpl.class); + private final ActorSelection leader; + private final DataTree dataTree; + private final ActorContext actorContext; + + LocalTransactionFactoryImpl(final ActorContext actorContext, final ActorSelection leader, final DataTree dataTree) { + this.leader = Preconditions.checkNotNull(leader); + this.dataTree = Preconditions.checkNotNull(dataTree); + this.actorContext = actorContext; + } + + DataTree getDataTree() { + return dataTree; + } + + @Override + public DOMStoreReadWriteTransaction newReadWriteTransaction(TransactionIdentifier identifier) { + return SnapshotBackedTransactions.newReadWriteTransaction(identifier, false, dataTree.takeSnapshot(), this); + } + + @Override + protected void transactionAborted(final SnapshotBackedWriteTransaction tx) { + // No-op + } + + @Override + protected DOMStoreThreePhaseCommitCohort transactionReady(final SnapshotBackedWriteTransaction tx, + final DataTreeModification tree) { + return new LocalThreePhaseCommitCohort(actorContext, leader, tx, tree) { + @Override + protected void transactionAborted(final SnapshotBackedWriteTransaction transaction) { + // No-op + LOG.debug("Transaction {} aborted", transaction); + } + + @Override + protected void transactionCommitted(final SnapshotBackedWriteTransaction transaction) { + // No-op + LOG.debug("Transaction {} committed", transaction); + } + }; + } +}