import akka.actor.ActorSelection;
import akka.dispatch.Futures;
import akka.dispatch.OnComplete;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Optional;
import java.util.SortedSet;
*
* @author Thomas Pantelis
*/
-public class RemoteTransactionContext extends AbstractTransactionContext {
+final class RemoteTransactionContext extends TransactionContext {
private static final Logger LOG = LoggerFactory.getLogger(RemoteTransactionContext.class);
private final ActorUtils actorUtils;
*/
private volatile Throwable failedModification;
- protected RemoteTransactionContext(final TransactionIdentifier identifier, final ActorSelection actor,
+ RemoteTransactionContext(final TransactionIdentifier identifier, final ActorSelection actor,
final ActorUtils actorUtils, final short remoteTransactionVersion, final OperationLimiter limiter) {
super(identifier, remoteTransactionVersion);
this.limiter = requireNonNull(limiter);
}
@Override
- public void closeTransaction() {
+ void closeTransaction() {
LOG.debug("Tx {} closeTransaction called", getIdentifier());
TransactionContextCleanup.untrack(this);
}
@Override
- public Future<Object> directCommit(final Boolean havePermit) {
+ Future<Object> directCommit(final Boolean havePermit) {
LOG.debug("Tx {} directCommit called", getIdentifier());
// Send the remaining batched modifications, if any, with the ready flag set.
}
@Override
- public Future<ActorSelection> readyTransaction(final Boolean havePermit,
+ Future<ActorSelection> readyTransaction(final Boolean havePermit,
final Optional<SortedSet<String>> participatingShardNames) {
logModificationCount();
bumpPermits(havePermit);
Future<Object> lastModificationsFuture = sendBatchedModifications(true, false, participatingShardNames);
- return transformReadyReply(lastModificationsFuture);
+ // Transform the last reply Future into a Future that returns the cohort actor path from
+ // the last reply message. That's the end result of the ready operation.
+ return TransactionReadyReplyMapper.transform(lastModificationsFuture, actorUtils, getIdentifier());
}
private void bumpPermits(final Boolean havePermit) {
}
}
- protected Future<ActorSelection> transformReadyReply(final Future<Object> readyReplyFuture) {
- // Transform the last reply Future into a Future that returns the cohort actor path from
- // the last reply message. That's the end result of the ready operation.
-
- return TransactionReadyReplyMapper.transform(readyReplyFuture, actorUtils, getIdentifier());
- }
-
private BatchedModifications newBatchedModifications() {
return new BatchedModifications(getIdentifier(), getTransactionVersion());
}
}
}
- protected Future<Object> sendBatchedModifications() {
+ @VisibleForTesting
+ Future<Object> sendBatchedModifications() {
return sendBatchedModifications(false, false, Optional.empty());
}
- protected Future<Object> sendBatchedModifications(final boolean ready, final boolean doCommitOnReady,
+ private Future<Object> sendBatchedModifications(final boolean ready, final boolean doCommitOnReady,
final Optional<SortedSet<String>> participatingShardNames) {
Future<Object> sent = null;
if (ready || batchedModifications != null && !batchedModifications.getModifications().isEmpty()) {
}
@Override
- public void executeDelete(final YangInstanceIdentifier path, final Boolean havePermit) {
+ void executeDelete(final YangInstanceIdentifier path, final Boolean havePermit) {
LOG.debug("Tx {} executeDelete called path = {}", getIdentifier(), path);
executeModification(new DeleteModification(path), havePermit);
}
@Override
- public void executeMerge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
- final Boolean havePermit) {
+ void executeMerge(final YangInstanceIdentifier path, final NormalizedNode data, final Boolean havePermit) {
LOG.debug("Tx {} executeMerge called path = {}", getIdentifier(), path);
executeModification(new MergeModification(path, data), havePermit);
}
@Override
- public void executeWrite(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
- final Boolean havePermit) {
+ void executeWrite(final YangInstanceIdentifier path, final NormalizedNode data, final Boolean havePermit) {
LOG.debug("Tx {} executeWrite called path = {}", getIdentifier(), path);
executeModification(new WriteModification(path, data), havePermit);
}
if (havePermit == null) {
permitToRelease = failedModification == null && acquireOperation();
} else {
- permitToRelease = havePermit.booleanValue();
+ permitToRelease = havePermit;
}
batchModification(modification, permitToRelease);
}
@Override
- public <T> void executeRead(final AbstractRead<T> readCmd, final SettableFuture<T> returnFuture,
+ <T> void executeRead(final AbstractRead<T> readCmd, final SettableFuture<T> returnFuture,
final Boolean havePermit) {
LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(),
readCmd.getPath());
// Send any batched modifications. This is necessary to honor the read uncommitted semantics of the
// public API contract.
- final boolean permitToRelease = havePermit == null ? acquireOperation() : havePermit.booleanValue();
+ final boolean permitToRelease = havePermit == null ? acquireOperation() : havePermit;
sendBatchedModifications();
OnComplete<Object> onComplete = new OnComplete<>() {
}
@Override
- public boolean usesOperationLimiting() {
+ boolean usesOperationLimiting() {
return true;
}
}