/**
* Class translating transaction operations towards a particular backend shard.
*
+ * <p>
* This class is not safe to access from multiple application threads, as is usual for transactions. Internal state
* transitions coming from interactions with backend are expected to be thread-safe.
*
+ * <p>
* This class interacts with the queueing mechanism in ClientActorBehavior, hence once we arrive at a decision
* to use either a local or remote implementation, we are stuck with it. We can re-evaluate on the next transaction.
*
}
final void delete(final YangInstanceIdentifier path) {
- checkSealed();
+ checkNotSealed();
doDelete(path);
}
final void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
- checkSealed();
+ checkNotSealed();
doMerge(path, data);
}
final void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
- checkSealed();
+ checkNotSealed();
doWrite(path, data);
}
final CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
- checkSealed();
+ checkNotSealed();
return doExists(path);
}
final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
- checkSealed();
+ checkNotSealed();
return doRead(path);
}
}
/**
- * Seal this transaction before it is either
+ * Seals this transaction when ready.
*/
final void seal() {
- checkSealed();
+ checkNotSealed();
doSeal();
sealed = true;
}
+ private void checkNotSealed() {
+ Preconditions.checkState(!sealed, "Transaction %s has already been sealed", getIdentifier());
+ }
+
private void checkSealed() {
Preconditions.checkState(sealed, "Transaction %s has not been sealed yet", getIdentifier());
}
* being sent to the backend.
*/
final void abort() {
- checkSealed();
+ checkNotSealed();
doAbort();
}
+ void abort(final VotingFuture<Void> ret) {
+ checkSealed();
+
+ sendRequest(new TransactionAbortRequest(getIdentifier(), nextSequence(), localActor()), t -> {
+ if (t instanceof TransactionAbortSuccess) {
+ ret.voteYes();
+ } else if (t instanceof RequestFailure) {
+ ret.voteNo(((RequestFailure<?, ?>) t).getCause());
+ } else {
+ ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
+ }
+ });
+ }
+
/**
* Commit this transaction, possibly in a coordinated fashion.
*
return ret;
}
- void abort(final VotingFuture<Void> ret) {
- checkSealed();
-
- sendRequest(new TransactionAbortRequest(getIdentifier(), nextSequence(), localActor()), t -> {
- if (t instanceof TransactionAbortSuccess) {
- ret.voteYes();
- } else if (t instanceof RequestFailure) {
- ret.voteNo(((RequestFailure<?, ?>) t).getCause());
- } else {
- ret.voteNo(new IllegalStateException("Unhandled response " + t.getClass()));
- }
- });
- }
-
void canCommit(final VotingFuture<?> ret) {
checkSealed();
void preCommit(final VotingFuture<?> ret) {
checkSealed();
- sendRequest(new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor()), t-> {
+ sendRequest(new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor()), t -> {
if (t instanceof TransactionPreCommitSuccess) {
ret.voteYes();
} else if (t instanceof RequestFailure) {
void doCommit(final VotingFuture<?> ret) {
checkSealed();
- sendRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), t-> {
+ sendRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), t -> {
if (t instanceof TransactionCommitSuccess) {
ret.voteYes();
} else if (t instanceof RequestFailure) {
});
}
+ abstract TransactionRequest<?> doCommit(boolean coordinated);
+
abstract void doDelete(final YangInstanceIdentifier path);
abstract void doMerge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data);
abstract CheckedFuture<Boolean, ReadFailedException> doExists(final YangInstanceIdentifier path);
- abstract CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> doRead(final YangInstanceIdentifier path);
+ abstract CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> doRead(
+ final YangInstanceIdentifier path);
abstract void doSeal();
abstract void doAbort();
-
- abstract TransactionRequest<?> doCommit(boolean coordinated);
}