public static class Transaction.Runner extends Object
If otherwise unspecified, the default isolation level is Transaction.IsolationLevel.SNAPSHOT
.
Similarly, if unspecified, the default maximum number of isolation failures is 1000, and the
default maximum number of deadlock failures is 10.
Constructor and Description |
---|
Runner() |
Modifier and Type | Method and Description |
---|---|
<T,X extends Throwable> |
compute(Transaction.Computation<T,X> computation)
Performs the specified computation in a transaction and returns its result.
|
<T,X extends Throwable> |
computeNonIdempotent(Transaction.Computation<T,X> computation)
Performs the specified computation in a transaction and returns its result.
|
<X extends Throwable> |
execute(Transaction.Task<X> task)
Performs the specified task in a transaction.
|
<X extends Throwable> |
executeNonIdempotent(Transaction.Task<X> task)
Performs the specified task in a transaction.
|
Transaction.Runner |
maxDeadlockFailures(int maxFailures)
Defines the maximum number of deadlock failures in a transaction.
|
Transaction.Runner |
maxIsolationFailures(int maxFailures)
Defines the maximum number of isolation failures in a transaction.
|
Transaction.Runner |
withIsolationLevel(Transaction.IsolationLevel level)
Runs transactions using the specified isolation level.
|
public Transaction.Runner withIsolationLevel(Transaction.IsolationLevel level)
level
- the isolation level in which to run transactionsNullPointerException
- if the specified isolation level is nullpublic Transaction.Runner maxIsolationFailures(int maxFailures)
TransactionIsolationException
is thrown while running the transaction. After
this many failures have been observed, the transaction is aborted and the last observed
exception is propagated. If the transaction is not idempotent, the specified value is
ignored as such transactions are never retried.
The minimum valid value is one, which means that after observing just one such failure, the transaction is aborted.
maxFailures
- the maximum number of isolation failuresIllegalArgumentException
- if the specified number of failures is less than onepublic Transaction.Runner maxDeadlockFailures(int maxFailures)
DeadlockException
is thrown while running the transaction. After this many
failures have been observed, the transaction is aborted and the last observed exception is
propagated. If the transaction is not idempotent, the specified value is ignored as such
transactions are never re-tried.
The minimum valid value is one, which means that after observing just one such failure, the transaction is aborted.
maxFailures
- the maximum number of deadlock failuresIllegalArgumentException
- if the specified number of failures is less than onepublic <T,X extends Throwable> T compute(Transaction.Computation<T,X> computation) throws X extends Throwable
If the computation has side effects, then it may not tolerate being re-tried and may
not be idempotent. For such computations, use Transaction.computeNonIdempotent(Computation)
instead.
computation
- the computation to perform in a transactionIllegalStateException
- if a transaction is already in progress on the current threadX
- a type of exception thrown by the computationTransactionIsolationException
- if there is too much contention over the atoms such
that the computation cannot be performed with the proper isolation levelDeadlockException
- if this computation generated deadlock exceptions when accessing
and modifying atomsX extends Throwable
public <X extends Throwable> void execute(Transaction.Task<X> task) throws X extends Throwable
If the task has side effects, then it may not tolerate being re-tried and may not be
idempotent. For such tasks, use Transaction.executeNonIdempotent(Task)
instead.
task
- the task to perform in a transactionIllegalStateException
- if a transaction is already in progress on the current threadX
- a type of exception thrown by the taskTransactionIsolationException
- if there is too much contention over the atoms such
that the task cannot be performed with the proper isolation levelDeadlockException
- if this task generated deadlock exceptions when accessing
and modifying atomsX extends Throwable
public <T,X extends Throwable> T computeNonIdempotent(Transaction.Computation<T,X> computation) throws X extends Throwable
If the computation has no side effects and is idempotent, then it is less likely to be
aborted if you use Transaction.compute(Computation)
instead.
computation
- the computation to perform in a transactionIllegalStateException
- if a transaction is already in progress on the current threadX
- a type of exception thrown by the computationTransactionIsolationException
- if there is contention over the atoms that prevent
the computation from running with the proper isolation levelDeadlockException
- if this computation generated a deadlock exception when accessing
and modifying atomsX extends Throwable
public <X extends Throwable> void executeNonIdempotent(Transaction.Task<X> task) throws X extends Throwable
If the task has no side effects and is idempotent, then it is less likely to be aborted
if you use Transaction.execute(Task)
instead.
task
- the task to perform in a transactionIllegalStateException
- if a transaction is already in progress on the current threadX
- a type of exception thrown by the taskTransactionIsolationException
- if there is contention over the atoms that prevent
the task from running with the proper isolation levelDeadlockException
- if this task generated a deadlock exception when accessing and
modifying atomsX extends Throwable