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%2FAbstractTransactionContext.java;h=571899ba14343f7b8f189571e18f708b397fc86b;hb=9e7a9b3725ad25f9adf85f0ad796b7cf748795a4;hp=d94e1c691e704051a81f74c2ba3ec135e1da002e;hpb=1d643894797401ebec8e2242c234779675ca37c3;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContext.java index d94e1c691e..571899ba14 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContext.java @@ -7,40 +7,78 @@ */ package org.opendaylight.controller.cluster.datastore; -import com.google.common.collect.ImmutableList; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; +import com.google.common.base.Preconditions; +import javax.annotation.Nonnull; import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; -import scala.concurrent.Future; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; abstract class AbstractTransactionContext implements TransactionContext { + private static final Logger LOG = LoggerFactory.getLogger(AbstractTransactionContext.class); + private final OperationLimiter limiter; + private long modificationCount = 0; + private boolean handoffComplete; - private final List> recordedOperationFutures = new ArrayList<>(); - private final TransactionIdentifier identifier; + protected AbstractTransactionContext(final OperationLimiter limiter) { + this.limiter = Preconditions.checkNotNull(limiter); + } - protected AbstractTransactionContext(TransactionIdentifier identifier) { - this.identifier = identifier; + /** + * Get the transaction identifier associated with this context. + * + * @return Transaction identifier. + */ + @Nonnull protected final TransactionIdentifier getIdentifier() { + return limiter.getIdentifier(); } - @Override - public final void copyRecordedOperationFutures(Collection> target) { - target.addAll(recordedOperationFutures); + /** + * Return the operation limiter associated with this context. + * @return Operation limiter. + */ + @Nonnull protected final OperationLimiter getLimiter() { + return limiter; + } + + /** + * Indicate whether all operations have been handed off by the {@link TransactionContextWrapper}. + * + * @return True if this context is responsible for throttling. + */ + protected final boolean isOperationHandoffComplete() { + return handoffComplete; } - protected final TransactionIdentifier getIdentifier() { - return identifier; + /** + * Acquire operation from the limiter if the handoff has completed. If + * the handoff is still ongoing, this method does nothing. + */ + protected final void acquireOperation() { + if (handoffComplete) { + limiter.acquire(); + } } - protected final Collection> copyRecordedOperationFutures() { - return ImmutableList.copyOf(recordedOperationFutures); + /** + * Acquire operation from the limiter if the handoff has NOT completed. If + * the handoff has completed, this method does nothing. + */ + protected final void releaseOperation() { + if (!handoffComplete) { + limiter.release(); + } } - protected final int recordedOperationCount() { - return recordedOperationFutures.size(); + protected final void incrementModificationCount() { + modificationCount++; } - protected final void recordOperationFuture(Future future) { - recordedOperationFutures.add(future); + protected final void logModificationCount() { + LOG.debug("Total modifications on Tx {} = [ {} ]", getIdentifier(), modificationCount); + } + + @Override + public final void operationHandoffComplete() { + handoffComplete = true; } }