Class StmUtils
- java.lang.Object
-
- org.multiverse.api.StmUtils
-
public final class StmUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
abort()
Aborts the Transaction in the TxnThreadLocal transaction.static void
atomic(Runnable runnable)
static <E> E
atomic(Callable<E> callable)
static boolean
atomic(TxnBooleanCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static boolean
atomic(TxnBooleanCallable either, TxnBooleanCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static <E> E
atomic(TxnCallable<E> callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static <E> E
atomic(TxnCallable<E> either, TxnCallable<E> orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static double
atomic(TxnDoubleCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static double
atomic(TxnDoubleCallable either, TxnDoubleCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static int
atomic(TxnIntCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static int
atomic(TxnIntCallable either, TxnIntCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static long
atomic(TxnLongCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static long
atomic(TxnLongCallable either, TxnLongCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static void
atomic(TxnVoidCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static void
atomic(TxnVoidCallable either, TxnVoidCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static boolean
atomicChecked(TxnBooleanCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static boolean
atomicChecked(TxnBooleanCallable either, TxnBooleanCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static <E> E
atomicChecked(TxnCallable<E> callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static <E> E
atomicChecked(TxnCallable<E> either, TxnCallable<E> orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static double
atomicChecked(TxnDoubleCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static double
atomicChecked(TxnDoubleCallable either, TxnDoubleCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static int
atomicChecked(TxnIntCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static int
atomicChecked(TxnIntCallable either, TxnIntCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static long
atomicChecked(TxnLongCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static long
atomicChecked(TxnLongCallable either, TxnLongCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static void
atomicChecked(TxnVoidCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static void
atomicChecked(TxnVoidCallable either, TxnVoidCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed.static void
commit()
Commits the Transaction in the TxnThreadLocal transaction.static TxnBoolean
newTxnBoolean()
Creates a committedTxnBoolean
with false as initial value using theGlobalStmInstance
.static TxnBoolean
newTxnBoolean(boolean value)
Creates a committedTxnBoolean
with the provided value using theGlobalStmInstance
.static <E> TxnDeque<E>
newTxnDeque()
Creates a new committed unbound TxnDeque.static <E> TxnDeque<E>
newTxnDeque(int capacity)
Creates a new committed bound TxnDeque.static TxnDouble
newTxnDouble()
Creates a committedTxnDouble
with 0 as initial value using theGlobalStmInstance
.static TxnDouble
newTxnDouble(double value)
Creates a committedTxnDouble
with the provided value using theGlobalStmInstance
.static <K,V>
TxnMap<K,V>newTxnHashMap()
Creates a new committed TxnMap.static <E> TxnSet<E>
newTxnHashSet()
Creates a new committed TxnSet that is based on a 'hashtable'.static TxnInteger
newTxnInteger()
Creates a committedTxnInteger
with 0 as initial value using theGlobalStmInstance
.static TxnInteger
newTxnInteger(int value)
Creates a committedTxnInteger
with the provided value using theGlobalStmInstance
.static <E> TxnList<E>
newTxnLinkedList()
Creates a new committed TxnList based on a double linked list.static TxnLong
newTxnLong()
Creates a committedTxnLong
with 0 as initial value using theGlobalStmInstance
.static TxnLong
newTxnLong(long value)
Creates a committedTxnLong
with the provided value using theGlobalStmInstance
.static <E> TxnQueue<E>
newTxnQueue()
Creates a new committed unbound TxnQueue.static <E> TxnQueue<E>
newTxnQueue(int capacity)
Creates a new committed bound TxnQueue.static <E> TxnRef<E>
newTxnRef()
Creates a committedTxnRef
with null as initial value using theGlobalStmInstance
.static <E> TxnRef<E>
newTxnRef(E value)
Creates a committedTxnRef
with the provided value using theGlobalStmInstance
.static <E> TxnStack<E>
newTxnStack()
Creates a new committed unbound TxnStack.static <E> TxnStack<E>
newTxnStack(int capacity)
Creates a new committed bound TxnStack.static void
prepare()
Prepares the Transaction in the TxnThreadLocal transaction.static void
retry()
Does a retry.static void
scheduleCompensatingOrDeferredTask(Runnable task)
Scheduled an deferred or compensating task on theTxn
in the TxnThreadLocal.static void
scheduleCompensatingTask(Runnable task)
Scheduled a compensating task on theTxn
in theTxnThreadLocal
.static void
scheduleDeferredTask(Runnable task)
Scheduled an deferred task on theTxn
in theTxnThreadLocal
.
-
-
-
Method Detail
-
newTxnLinkedList
public static <E> TxnList<E> newTxnLinkedList()
Creates a new committed TxnList based on a double linked list.- Returns:
- the created TxnList.
-
newTxnStack
public static <E> TxnStack<E> newTxnStack()
Creates a new committed unbound TxnStack.- Returns:
- the created TxnStack.
-
newTxnStack
public static <E> TxnStack<E> newTxnStack(int capacity)
Creates a new committed bound TxnStack.- Parameters:
capacity
- the maximum capacity of the stack. Integer.MAX_VALUE indicates that there is no bound.- Returns:
- the create TxnStack
- Throws:
IllegalArgumentException
- if capacity smaller than 0.
-
newTxnQueue
public static <E> TxnQueue<E> newTxnQueue()
Creates a new committed unbound TxnQueue.- Returns:
- the created TxnQueue.
-
newTxnQueue
public static <E> TxnQueue<E> newTxnQueue(int capacity)
Creates a new committed bound TxnQueue.- Parameters:
capacity
- the maximum capacity of the queue. Integer.MAX_VALUE indicates that there is no bound.- Returns:
- the created TxnQueue
- Throws:
IllegalArgumentException
- if capacity smaller than 0.
-
newTxnDeque
public static <E> TxnDeque<E> newTxnDeque()
Creates a new committed unbound TxnDeque.- Returns:
- the created TxnDeque
-
newTxnDeque
public static <E> TxnDeque<E> newTxnDeque(int capacity)
Creates a new committed bound TxnDeque.- Parameters:
capacity
- the maximum capacity of the deque. Integer.MAX_VALUE indicates that there is no bound.- Returns:
- the created TxnDeque.
- Throws:
IllegalArgumentException
- if capacity is smaller than 0.
-
newTxnHashSet
public static <E> TxnSet<E> newTxnHashSet()
Creates a new committed TxnSet that is based on a 'hashtable'.- Returns:
- the created TxnSet.
-
newTxnHashMap
public static <K,V> TxnMap<K,V> newTxnHashMap()
Creates a new committed TxnMap.- Returns:
- the created TxnMap
-
atomic
public static void atomic(Runnable runnable)
-
atomic
public static <E> E atomic(Callable<E> callable)
-
atomic
public static <E> E atomic(TxnCallable<E> callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.This method doesn't throw a checked exception, but if the callable does, it is wrapped inside an InvisibleCheckedException.
If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- The callableTxnCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if the callable throws a checked exception.
-
atomicChecked
public static <E> E atomicChecked(TxnCallable<E> callable) throws Exception
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- TheTxnCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.Exception
- is the callable throws an Exception
-
atomic
public static <E> E atomic(TxnCallable<E> either, TxnCallable<E> orelse)
Executes the either block, or in case of a retry, the orelse block is executed. If in the execution of the callable a checked exception is thrown, the exception is wrapped in a InvisibleCheckedException. The original exception can be retrieved by calling the getCause method.- Parameters:
either
- the either blockorelse
- the orelse block.- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if a checked exception is thrown by the callable.
-
atomicChecked
public static <E> E atomicChecked(TxnCallable<E> either, TxnCallable<E> orelse) throws Exception
Executes the either block, or in case of a retry, the orelse block is executed.- Parameters:
either
- the either blockorelse
- the orelse block- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.Exception
- if the execute call fails.
-
atomic
public static int atomic(TxnIntCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.This method doesn't throw a checked exception, but if the callable does, it is wrapped inside an InvisibleCheckedException.
If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- The callableTxnIntCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if the callable throws a checked exception.
-
atomicChecked
public static int atomicChecked(TxnIntCallable callable) throws Exception
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- TheTxnIntCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.Exception
- is the callable throws an Exception
-
atomic
public static int atomic(TxnIntCallable either, TxnIntCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed. If in the execution of the callable a checked exception is thrown, the exception is wrapped in a InvisibleCheckedException. The original exception can be retrieved by calling the getCause method.- Parameters:
either
- the either blockorelse
- the orelse block.- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if a checked exception is thrown by the callable.
-
atomicChecked
public static int atomicChecked(TxnIntCallable either, TxnIntCallable orelse) throws Exception
Executes the either block, or in case of a retry, the orelse block is executed.- Parameters:
either
- the either blockorelse
- the orelse block- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.Exception
- if the execute call fails.
-
atomic
public static long atomic(TxnLongCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.This method doesn't throw a checked exception, but if the callable does, it is wrapped inside an InvisibleCheckedException.
If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- The callableTxnLongCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if the callable throws a checked exception.
-
atomicChecked
public static long atomicChecked(TxnLongCallable callable) throws Exception
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- TheTxnLongCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.Exception
- is the callable throws an Exception
-
atomic
public static long atomic(TxnLongCallable either, TxnLongCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed. If in the execution of the callable a checked exception is thrown, the exception is wrapped in a InvisibleCheckedException. The original exception can be retrieved by calling the getCause method.- Parameters:
either
- the either blockorelse
- the orelse block.- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if a checked exception is thrown by the callable.
-
atomicChecked
public static long atomicChecked(TxnLongCallable either, TxnLongCallable orelse) throws Exception
Executes the either block, or in case of a retry, the orelse block is executed.- Parameters:
either
- the either blockorelse
- the orelse block- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.Exception
- if the execute call fails.
-
atomic
public static double atomic(TxnDoubleCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.This method doesn't throw a checked exception, but if the callable does, it is wrapped inside an InvisibleCheckedException.
If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- The callableTxnDoubleCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if the callable throws a checked exception.
-
atomicChecked
public static double atomicChecked(TxnDoubleCallable callable) throws Exception
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- TheTxnDoubleCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.Exception
- is the callable throws an Exception
-
atomic
public static double atomic(TxnDoubleCallable either, TxnDoubleCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed. If in the execution of the callable a checked exception is thrown, the exception is wrapped in a InvisibleCheckedException. The original exception can be retrieved by calling the getCause method.- Parameters:
either
- the either blockorelse
- the orelse block.- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if a checked exception is thrown by the callable.
-
atomicChecked
public static double atomicChecked(TxnDoubleCallable either, TxnDoubleCallable orelse) throws Exception
Executes the either block, or in case of a retry, the orelse block is executed.- Parameters:
either
- the either blockorelse
- the orelse block- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.Exception
- if the execute call fails.
-
atomic
public static boolean atomic(TxnBooleanCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.This method doesn't throw a checked exception, but if the callable does, it is wrapped inside an InvisibleCheckedException.
If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- The callableTxnBooleanCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if the callable throws a checked exception.
-
atomicChecked
public static boolean atomicChecked(TxnBooleanCallable callable) throws Exception
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- TheTxnBooleanCallable
to execute.- Returns:
- the result of the execution
- Throws:
NullPointerException
- if callable is null.Exception
- is the callable throws an Exception
-
atomic
public static boolean atomic(TxnBooleanCallable either, TxnBooleanCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed. If in the execution of the callable a checked exception is thrown, the exception is wrapped in a InvisibleCheckedException. The original exception can be retrieved by calling the getCause method.- Parameters:
either
- the either blockorelse
- the orelse block.- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if a checked exception is thrown by the callable.
-
atomicChecked
public static boolean atomicChecked(TxnBooleanCallable either, TxnBooleanCallable orelse) throws Exception
Executes the either block, or in case of a retry, the orelse block is executed.- Parameters:
either
- the either blockorelse
- the orelse block- Returns:
- the result of the execution.
- Throws:
NullPointerException
- if callable is null.Exception
- if the execute call fails.
-
atomic
public static void atomic(TxnVoidCallable callable)
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.This method doesn't throw a checked exception, but if the callable does, it is wrapped inside an InvisibleCheckedException.
If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- The callableTxnVoidCallable
to execute.- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if the callable throws a checked exception.
-
atomicChecked
public static void atomicChecked(TxnVoidCallable callable) throws Exception
Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor. If a Transaction already is active on the TxnThreadLocal, this transaction will lift on that transaction (so the propagation level is Requires) and will not commit this transaction.If you want to get most out of performance, it is best to make use of a customized
TxnExecutor
instead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable
- TheTxnVoidCallable
to execute.- Throws:
NullPointerException
- if callable is null.Exception
- is the callable throws an Exception
-
atomic
public static void atomic(TxnVoidCallable either, TxnVoidCallable orelse)
Executes the either block, or in case of a retry, the orelse block is executed. If in the execution of the callable a checked exception is thrown, the exception is wrapped in a InvisibleCheckedException. The original exception can be retrieved by calling the getCause method.- Parameters:
either
- the either blockorelse
- the orelse block.- Throws:
NullPointerException
- if callable is null.InvisibleCheckedException
- if a checked exception is thrown by the callable.
-
atomicChecked
public static void atomicChecked(TxnVoidCallable either, TxnVoidCallable orelse) throws Exception
Executes the either block, or in case of a retry, the orelse block is executed.- Parameters:
either
- the either blockorelse
- the orelse block- Throws:
NullPointerException
- if callable is null.Exception
- if the execute call fails.
-
newTxnInteger
public static TxnInteger newTxnInteger(int value)
Creates a committedTxnInteger
with the provided value using theGlobalStmInstance
.- Parameters:
value
- the initial value of the TnxInteger- Returns:
- the created TnxInteger.
-
newTxnInteger
public static TxnInteger newTxnInteger()
Creates a committedTxnInteger
with 0 as initial value using theGlobalStmInstance
.- Returns:
- the created TxnInteger.
-
newTxnLong
public static TxnLong newTxnLong()
Creates a committedTxnLong
with 0 as initial value using theGlobalStmInstance
.- Returns:
- the created TnxLong.
-
newTxnLong
public static TxnLong newTxnLong(long value)
Creates a committedTxnLong
with the provided value using theGlobalStmInstance
.- Parameters:
value
- the initial value of the TxnLong.- Returns:
- the created TnxLong.
-
newTxnDouble
public static TxnDouble newTxnDouble()
Creates a committedTxnDouble
with 0 as initial value using theGlobalStmInstance
.- Returns:
- the created TxnDouble.
-
newTxnDouble
public static TxnDouble newTxnDouble(double value)
Creates a committedTxnDouble
with the provided value using theGlobalStmInstance
.- Parameters:
value
- the initial value.- Returns:
- the created TnxDouble.
-
newTxnBoolean
public static TxnBoolean newTxnBoolean()
Creates a committedTxnBoolean
with false as initial value using theGlobalStmInstance
.- Returns:
- the created TxnBoolean.
-
newTxnBoolean
public static TxnBoolean newTxnBoolean(boolean value)
Creates a committedTxnBoolean
with the provided value using theGlobalStmInstance
.- Parameters:
value
- the initial value- Returns:
- the created TxnBoolean.
-
newTxnRef
public static <E> TxnRef<E> newTxnRef()
Creates a committedTxnRef
with null as initial value using theGlobalStmInstance
.- Type Parameters:
E
- the type of the TxnRef.- Returns:
- the created Ref.
-
newTxnRef
public static <E> TxnRef<E> newTxnRef(E value)
Creates a committedTxnRef
with the provided value using theGlobalStmInstance
.- Type Parameters:
E
- the type of the TxnRef.- Parameters:
value
- the initial value of the TxnRef.- Returns:
- the created TxnRef.
-
retry
public static void retry()
Does a retry. This behavior is needed for blocking transactions; transaction that wait for a state change to happen on certain datastructures, e.g. an item to come available on a transactional blocking queue.Under the hood the retry throws an Retry that will be caught up the callstack (by the
TxnExecutor
for example). The Retry should not be caught by user code in almost all cases.
-
prepare
public static void prepare()
Prepares the Transaction in the TxnThreadLocal transaction.For more information see
Txn.prepare()
.- Throws:
TxnMandatoryException
- if no active transaction is found.IllegalTransactionStateException
- if the active transaction is not in the correct state for this operation.ControlFlowError
-
abort
public static void abort()
Aborts the Transaction in the TxnThreadLocal transaction.For more information see
Txn.abort()
.- Throws:
TxnMandatoryException
- if no active transaction is found.IllegalTransactionStateException
- if the active transaction is not in the correct state for this operation.ControlFlowError
-
commit
public static void commit()
Commits the Transaction in the TxnThreadLocal transaction.For more information see
Txn.commit()
.- Throws:
TxnMandatoryException
- if no active transaction is found.IllegalTransactionStateException
- if the active transaction is not in the correct state for this operation.ControlFlowError
-
scheduleCompensatingOrDeferredTask
public static void scheduleCompensatingOrDeferredTask(Runnable task)
Scheduled an deferred or compensating task on theTxn
in the TxnThreadLocal. This task is executed after the transaction commits or aborts.- Parameters:
task
- the deferred task to execute.- Throws:
NullPointerException
- if task is null.TxnMandatoryException
- if no transaction is set on theTxnThreadLocal
.IllegalTxnStateException
- if the transaction is not in the correct state to accept a compensating or deferred task.
-
scheduleDeferredTask
public static void scheduleDeferredTask(Runnable task)
Scheduled an deferred task on theTxn
in theTxnThreadLocal
. This task is executed after the transaction commits and one of the use cases is starting transactions.- Parameters:
task
- the deferred task to execute.- Throws:
NullPointerException
- if task is null.TxnMandatoryException
- if no transaction is set on theTxnThreadLocal
.IllegalTxnStateException
- if the transaction is not in the correct state to accept a deferred task.
-
scheduleCompensatingTask
public static void scheduleCompensatingTask(Runnable task)
Scheduled a compensating task on theTxn
in theTxnThreadLocal
. This task is executed after the transaction aborts and one of the use cases is cleaning up non transaction resources like the file system.- Parameters:
task
- the deferred task to execute.- Throws:
NullPointerException
- if task is null.TxnMandatoryException
- if no transaction is set on theTxnThreadLocal
.IllegalTxnStateException
- if the transaction is not in the correct state to accept a compensating task.
-
-