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%2FRemoteTransactionContext.java;h=20074c10289908d20839fb2fbbd43e0089a7d24c;hb=87c8362c7501408b281f5ddc9b78ed7440280fa1;hp=6bf0f7fc9c3e768697371bc0b216b5203c2cefaf;hpb=c7e1ddeaf842ebb696c8dd38c0ca14c925ee31a1;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContext.java index 6bf0f7fc9c..20074c1028 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContext.java @@ -11,6 +11,7 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSelection; import akka.dispatch.OnComplete; import com.google.common.base.Optional; +import com.google.common.base.Preconditions; import com.google.common.util.concurrent.SettableFuture; import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications; @@ -45,28 +46,27 @@ public class RemoteTransactionContext extends AbstractTransactionContext { private final ActorSelection actor; private final boolean isTxActorLocal; private final short remoteTransactionVersion; + private final OperationLimiter limiter; - private final OperationLimiter operationCompleter; private BatchedModifications batchedModifications; private int totalBatchedModificationsSent; - protected RemoteTransactionContext(ActorSelection actor, TransactionIdentifier identifier, + protected RemoteTransactionContext(TransactionIdentifier identifier, ActorSelection actor, ActorContext actorContext, boolean isTxActorLocal, short remoteTransactionVersion, OperationLimiter limiter) { super(identifier); + this.limiter = Preconditions.checkNotNull(limiter); this.actor = actor; this.actorContext = actorContext; this.isTxActorLocal = isTxActorLocal; this.remoteTransactionVersion = remoteTransactionVersion; - this.operationCompleter = limiter; } private Future completeOperation(Future operationFuture){ - operationFuture.onComplete(this.operationCompleter, actorContext.getClientDispatcher()); + operationFuture.onComplete(limiter, actorContext.getClientDispatcher()); return operationFuture; } - private ActorSelection getActor() { return actor; } @@ -178,6 +178,7 @@ public class RemoteTransactionContext extends AbstractTransactionContext { public void deleteData(YangInstanceIdentifier path) { LOG.debug("Tx {} deleteData called path = {}", getIdentifier(), path); + acquireOperation(); batchModification(new DeleteModification(path)); } @@ -185,6 +186,7 @@ public class RemoteTransactionContext extends AbstractTransactionContext { public void mergeData(YangInstanceIdentifier path, NormalizedNode data) { LOG.debug("Tx {} mergeData called path = {}", getIdentifier(), path); + acquireOperation(); batchModification(new MergeModification(path, data)); } @@ -192,6 +194,7 @@ public class RemoteTransactionContext extends AbstractTransactionContext { public void writeData(YangInstanceIdentifier path, NormalizedNode data) { LOG.debug("Tx {} writeData called path = {}", getIdentifier(), path); + acquireOperation(); batchModification(new WriteModification(path, data)); } @@ -204,6 +207,7 @@ public class RemoteTransactionContext extends AbstractTransactionContext { // Send any batched modifications. This is necessary to honor the read uncommitted semantics of the // public API contract. + acquireOperation(); sendBatchedModifications(); OnComplete onComplete = new OnComplete() { @@ -246,6 +250,7 @@ public class RemoteTransactionContext extends AbstractTransactionContext { // Send any batched modifications. This is necessary to honor the read uncommitted semantics of the // public API contract. + acquireOperation(); sendBatchedModifications(); OnComplete onComplete = new OnComplete() { @@ -276,4 +281,19 @@ public class RemoteTransactionContext extends AbstractTransactionContext { future.onComplete(onComplete, actorContext.getClientDispatcher()); } + + /** + * Acquire operation from the limiter if the hand-off has completed. If + * the hand-off is still ongoing, this method does nothing. + */ + private final void acquireOperation() { + if (isOperationHandOffComplete()) { + limiter.acquire(); + } + } + + @Override + public boolean usesOperationLimiting() { + return true; + } }