Class StmUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final TxnExecutor
private static final OrElseBlock
private static final TxnRefFactory
private static final TxnCollectionsFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
abort()
Aborts the Transaction in the TxnThreadLocal transaction.static void
static <E> E
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
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>
Creates a new committed unbound TxnDeque.static <E> TxnDeque<E>
newTxnDeque
(int capacity) Creates a new committed bound TxnDeque.static TxnDouble
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> Creates a new committed TxnMap.static <E> TxnSet<E>
Creates a new committed TxnSet that is based on a 'hashtable'.static TxnInteger
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>
Creates a new committed TxnList based on a double linked list.static TxnLong
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>
Creates a new committed unbound TxnQueue.static <E> TxnQueue<E>
newTxnQueue
(int capacity) Creates a new committed bound TxnQueue.static <E> TxnRef<E>
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>
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
Scheduled an deferred or compensating task on theTxn
in the TxnThreadLocal.static void
Scheduled a compensating task on theTxn
in theTxnThreadLocal
.static void
scheduleDeferredTask
(Runnable task) Scheduled an deferred task on theTxn
in theTxnThreadLocal
.
-
Field Details
-
refFactory
-
defaultTxnExecutor
-
orelseBlock
-
txnCollectionsFactory
-
-
Constructor Details
-
StmUtils
private StmUtils()
-
-
Method Details
-
newTxnLinkedList
Creates a new committed TxnList based on a double linked list.- Returns:
- the created TxnList.
-
newTxnStack
Creates a new committed unbound TxnStack.- Returns:
- the created TxnStack.
-
newTxnStack
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
Creates a new committed unbound TxnQueue.- Returns:
- the created TxnQueue.
-
newTxnQueue
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
Creates a new committed unbound TxnDeque.- Returns:
- the created TxnDeque
-
newTxnDeque
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
Creates a new committed TxnSet that is based on a 'hashtable'.- Returns:
- the created TxnSet.
-
newTxnHashMap
Creates a new committed TxnMap.- Returns:
- the created TxnMap
-
atomic
-
atomic
-
atomic
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Creates a committedTxnInteger
with the provided value using theGlobalStmInstance
.- Parameters:
value
- the initial value of the TnxInteger- Returns:
- the created TnxInteger.
-
newTxnInteger
Creates a committedTxnInteger
with 0 as initial value using theGlobalStmInstance
.- Returns:
- the created TxnInteger.
-
newTxnLong
Creates a committedTxnLong
with 0 as initial value using theGlobalStmInstance
.- Returns:
- the created TnxLong.
-
newTxnLong
Creates a committedTxnLong
with the provided value using theGlobalStmInstance
.- Parameters:
value
- the initial value of the TxnLong.- Returns:
- the created TnxLong.
-
newTxnDouble
Creates a committedTxnDouble
with 0 as initial value using theGlobalStmInstance
.- Returns:
- the created TxnDouble.
-
newTxnDouble
Creates a committedTxnDouble
with the provided value using theGlobalStmInstance
.- Parameters:
value
- the initial value.- Returns:
- the created TnxDouble.
-
newTxnBoolean
Creates a committedTxnBoolean
with false as initial value using theGlobalStmInstance
.- Returns:
- the created TxnBoolean.
-
newTxnBoolean
Creates a committedTxnBoolean
with the provided value using theGlobalStmInstance
.- Parameters:
value
- the initial value- Returns:
- the created TxnBoolean.
-
newTxnRef
Creates a committedTxnRef
with null as initial value using theGlobalStmInstance
.- Type Parameters:
E
- the type of the TxnRef.- Returns:
- the created Ref.
-
newTxnRef
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
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
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
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.
-