X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FTransactionContext.java;h=549136b589fb1db11842ce1b9a2b7d5a83820844;hb=546cd1fd100dbaa36908b22c2f422320dbd8c4b2;hp=fe36661e671032d82caf8579967efa92e84b9513;hpb=5b69c8e66b12a29a36457955cac4a45affd7c73f;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionContext.java index fe36661e67..549136b589 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionContext.java @@ -11,32 +11,46 @@ import akka.actor.ActorSelection; import com.google.common.util.concurrent.SettableFuture; import java.util.Optional; import java.util.SortedSet; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.AbstractRead; +import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import scala.concurrent.Future; -/* - * FIXME: why do we need this interface? It should be possible to integrate it with - * AbstractTransactionContext, which is the only implementation anyway. - */ -interface TransactionContext { - void closeTransaction(); +abstract class TransactionContext extends AbstractSimpleIdentifiable { + private static final Logger LOG = LoggerFactory.getLogger(TransactionContext.class); + + private final short transactionVersion; - Future readyTransaction(Boolean havePermit, Optional> participatingShardNames); + private long modificationCount = 0; + private boolean handOffComplete; - void executeRead(AbstractRead readCmd, SettableFuture promise, Boolean havePermit); + TransactionContext(final TransactionIdentifier transactionIdentifier) { + this(transactionIdentifier, DataStoreVersions.CURRENT_VERSION); + } - void executeDelete(YangInstanceIdentifier path, Boolean havePermit); + TransactionContext(final TransactionIdentifier transactionIdentifier, final short transactionVersion) { + super(transactionIdentifier); + this.transactionVersion = transactionVersion; + } - void executeMerge(YangInstanceIdentifier path, NormalizedNode data, Boolean havePermit); + final short getTransactionVersion() { + return transactionVersion; + } - void executeWrite(YangInstanceIdentifier path, NormalizedNode data, Boolean havePermit); + final void incrementModificationCount() { + modificationCount++; + } - Future directCommit(Boolean havePermit); + final void logModificationCount() { + LOG.debug("Total modifications on Tx {} = [ {} ]", getIdentifier(), modificationCount); + } /** - * Invoked by {@link TransactionContextWrapper} when it has finished handing + * Invoked by {@link AbstractTransactionContextWrapper} when it has finished handing * off operations to this context. From this point on, the context is responsible * for throttling operations. * @@ -44,14 +58,35 @@ interface TransactionContext { * Implementations can rely on the wrapper calling this operation in a synchronized * block, so they do not need to ensure visibility of this state transition themselves. */ - void operationHandOffComplete(); + final void operationHandOffComplete() { + handOffComplete = true; + } + + final boolean isOperationHandOffComplete() { + return handOffComplete; + } /** * A TransactionContext that uses operation limiting should return true else false. * * @return true if operation limiting is used, false otherwise */ - boolean usesOperationLimiting(); + boolean usesOperationLimiting() { + return false; + } + + abstract void executeDelete(YangInstanceIdentifier path, Boolean havePermit); + + abstract void executeMerge(YangInstanceIdentifier path, NormalizedNode data, Boolean havePermit); + + abstract void executeWrite(YangInstanceIdentifier path, NormalizedNode data, Boolean havePermit); + + abstract void executeRead(AbstractRead readCmd, SettableFuture proxyFuture, Boolean havePermit); + + abstract Future readyTransaction(Boolean havePermit, + Optional> participatingShardNames); + + abstract Future directCommit(Boolean havePermit); - short getTransactionVersion(); + abstract void closeTransaction(); }