Class StmUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final TxnExecutorprivate static final OrElseBlockprivate static final TxnRefFactoryprivate static final TxnCollectionsFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidabort()Aborts the Transaction in the TxnThreadLocal transaction.static voidstatic <E> Estatic booleanatomic(TxnBooleanCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static booleanatomic(TxnBooleanCallable either, TxnBooleanCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static <E> Eatomic(TxnCallable<E> callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static <E> Eatomic(TxnCallable<E> either, TxnCallable<E> orelse) Executes the either block, or in case of a retry, the orelse block is executed.static doubleatomic(TxnDoubleCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static doubleatomic(TxnDoubleCallable either, TxnDoubleCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static intatomic(TxnIntCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static intatomic(TxnIntCallable either, TxnIntCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static longatomic(TxnLongCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static longatomic(TxnLongCallable either, TxnLongCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static voidatomic(TxnVoidCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static voidatomic(TxnVoidCallable either, TxnVoidCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static booleanatomicChecked(TxnBooleanCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static booleanatomicChecked(TxnBooleanCallable either, TxnBooleanCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static <E> EatomicChecked(TxnCallable<E> callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static <E> EatomicChecked(TxnCallable<E> either, TxnCallable<E> orelse) Executes the either block, or in case of a retry, the orelse block is executed.static doubleatomicChecked(TxnDoubleCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static doubleatomicChecked(TxnDoubleCallable either, TxnDoubleCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static intatomicChecked(TxnIntCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static intatomicChecked(TxnIntCallable either, TxnIntCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static longatomicChecked(TxnLongCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static longatomicChecked(TxnLongCallable either, TxnLongCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static voidatomicChecked(TxnVoidCallable callable) Executes the callable transactionally on the GlobalStmInstance using the default TxnExecutor.static voidatomicChecked(TxnVoidCallable either, TxnVoidCallable orelse) Executes the either block, or in case of a retry, the orelse block is executed.static voidcommit()Commits the Transaction in the TxnThreadLocal transaction.static TxnBooleanCreates a committedTxnBooleanwith false as initial value using theGlobalStmInstance.static TxnBooleannewTxnBoolean(boolean value) Creates a committedTxnBooleanwith 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 TxnDoubleCreates a committedTxnDoublewith 0 as initial value using theGlobalStmInstance.static TxnDoublenewTxnDouble(double value) Creates a committedTxnDoublewith 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 TxnIntegerCreates a committedTxnIntegerwith 0 as initial value using theGlobalStmInstance.static TxnIntegernewTxnInteger(int value) Creates a committedTxnIntegerwith the provided value using theGlobalStmInstance.static <E> TxnList<E> Creates a new committed TxnList based on a double linked list.static TxnLongCreates a committedTxnLongwith 0 as initial value using theGlobalStmInstance.static TxnLongnewTxnLong(long value) Creates a committedTxnLongwith 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 committedTxnRefwith null as initial value using theGlobalStmInstance.static <E> TxnRef<E> newTxnRef(E value) Creates a committedTxnRefwith 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 voidprepare()Prepares the Transaction in the TxnThreadLocal transaction.static voidretry()Does a retry.static voidScheduled an deferred or compensating task on theTxnin the TxnThreadLocal.static voidScheduled a compensating task on theTxnin theTxnThreadLocal.static voidscheduleDeferredTask(Runnable task) Scheduled an deferred task on theTxnin 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- The callableTxnCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- TheTxnCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- The callableTxnIntCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- TheTxnIntCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- The callableTxnLongCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- TheTxnLongCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- The callableTxnDoubleCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- TheTxnDoubleCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- The callableTxnBooleanCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- TheTxnBooleanCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- The callableTxnVoidCallableto 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
TxnExecutorinstead of relying on the default TxnExecutor that will always provide the most expensive transaction available.- Parameters:
callable- TheTxnVoidCallableto 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 committedTxnIntegerwith the provided value using theGlobalStmInstance.- Parameters:
value- the initial value of the TnxInteger- Returns:
- the created TnxInteger.
-
newTxnInteger
Creates a committedTxnIntegerwith 0 as initial value using theGlobalStmInstance.- Returns:
- the created TxnInteger.
-
newTxnLong
Creates a committedTxnLongwith 0 as initial value using theGlobalStmInstance.- Returns:
- the created TnxLong.
-
newTxnLong
Creates a committedTxnLongwith the provided value using theGlobalStmInstance.- Parameters:
value- the initial value of the TxnLong.- Returns:
- the created TnxLong.
-
newTxnDouble
Creates a committedTxnDoublewith 0 as initial value using theGlobalStmInstance.- Returns:
- the created TxnDouble.
-
newTxnDouble
Creates a committedTxnDoublewith the provided value using theGlobalStmInstance.- Parameters:
value- the initial value.- Returns:
- the created TnxDouble.
-
newTxnBoolean
Creates a committedTxnBooleanwith false as initial value using theGlobalStmInstance.- Returns:
- the created TxnBoolean.
-
newTxnBoolean
Creates a committedTxnBooleanwith the provided value using theGlobalStmInstance.- Parameters:
value- the initial value- Returns:
- the created TxnBoolean.
-
newTxnRef
Creates a committedTxnRefwith null as initial value using theGlobalStmInstance.- Type Parameters:
E- the type of the TxnRef.- Returns:
- the created Ref.
-
newTxnRef
Creates a committedTxnRefwith 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
TxnExecutorfor 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(). -
abort
public static void abort()Aborts the Transaction in the TxnThreadLocal transaction.For more information see
Txn.abort(). -
commit
public static void commit()Commits the Transaction in the TxnThreadLocal transaction.For more information see
Txn.commit(). -
scheduleCompensatingOrDeferredTask
Scheduled an deferred or compensating task on theTxnin 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 theTxnin 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 theTxnin 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.
-