public interface TxnRef<E> extends TxnObject
PropagationLevel.RequiresNew
).
For the other methods, always an txn needs to be available, else you will get the
TxnMandatoryException
.
All non atomic methods are able to throw a (subclass) of the ControlFlowError
. This error should
not be caught, it is task of the TxnExecutor
to deal with.
Most of the methods can throw a TxnExecutionException
.
This exception can be caught, but in most cases you want to figure out what the cause is (e.g. because
there are too many retries) and solve that problem.
All methods are threadsafe.
Modifier and Type | Method and Description |
---|---|
E |
alterAndGet(Function<E> function)
Alters the value stored in this Ref using the provided function and returns the result.
|
E |
alterAndGet(Txn txn,
Function<E> function)
Alters the value stored in this Ref using the provided function and lifting on the provided txn.
|
E |
atomicAlterAndGet(Function<E> function)
Atomically applies the function to the current value in this ref and returns the new value.
|
boolean |
atomicCompareAndSet(E expectedValue,
E newValue)
Executes a compare and set atomically.
|
E |
atomicGet()
Atomically gets the value.
|
E |
atomicGetAndAlter(Function<E> function)
Atomically applies the function to alter the value stored in this ref and returns the old value.
|
E |
atomicGetAndSet(E newValue)
Atomically sets the value and returns the previous value.
|
boolean |
atomicIsNull()
Atomically check if the current value is null.
|
E |
atomicSet(E newValue)
Atomically sets the value and returns the new value.
|
E |
atomicWeakGet()
Atomically gets the value without providing any ordering guarantees.
|
void |
await(E value)
Awaits for the value to become the given value.
|
void |
await(Predicate<E> predicate)
Awaits until the predicate holds.
|
void |
await(Txn txn,
E value)
Awaits for the reference to become the given value.
|
void |
await(Txn txn,
Predicate<E> predicate)
Awaits until the predicate holds using the provided txn.
|
E |
awaitNotNullAndGet()
Awaits for the value to become not null.
|
E |
awaitNotNullAndGet(Txn txn)
Awaits for the value to become not null using the provided txn.
|
void |
awaitNull()
Awaits for the value to become null.
|
void |
awaitNull(Txn txn)
Awaits for the value to become not null using the provided txn.
|
void |
commute(Function<E> function)
Applies the function on the ref in a commuting manner.
|
void |
commute(Txn txn,
Function<E> function)
Applies the function on the ref in a commuting manner.
|
E |
get()
Gets the value using the provided txn.
|
E |
get(Txn txn)
Gets the value using the provided txn.
|
E |
getAndAlter(Function<E> function)
Alters the value stored in this Ref using the provided function amd returns the old value.
|
E |
getAndAlter(Txn txn,
Function<E> function)
Alters the value stored in this Ref using the function and returns the old value, using the provided txn.
|
E |
getAndLock(LockMode lockMode)
Gets the value and applies the lock.
|
E |
getAndLock(Txn txn,
LockMode lockMode)
Gets the value using the provided txn and acquired the lock with the specified LockMode.
|
E |
getAndSet(E value)
Sets the value the value and returns the new value.
|
E |
getAndSet(Txn txn,
E value)
Sets the value using the provided txn.
|
E |
getAndSetAndLock(E value,
LockMode lockMode)
Sets the value, acquired the Lock with the specified Lockmode and returns the previous value.
|
E |
getAndSetAndLock(Txn txn,
E value,
LockMode lockMode)
Sets the value and acquired the Lock with the provided LockMode.
|
boolean |
isNull()
Checks if the current value is null.
|
boolean |
isNull(Txn txn)
Checks if the current value is null using the provided txn.
|
E |
set(E value)
Sets the new value.
|
E |
set(Txn txn,
E value)
Sets the new value using the provided txn.
|
E |
setAndLock(E value,
LockMode lockMode)
Sets the new value and applies the lock.
|
E |
setAndLock(Txn txn,
E value,
LockMode lockMode)
Sets the new value using the provided txn.
|
atomicToString, ensure, ensure, getLock, getStm, getVersion, toDebugString, toString, toString
E get()
TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.atomicGet()
E getAndLock(LockMode lockMode)
This call lifts on the Txn
stored in the TxnThreadLocal
.
lockMode
- the LockMode applied.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.atomicGet()
E get(Txn txn)
txn
- the Txn
used for this operation.NullPointerException
- if txn is null.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E getAndLock(Txn txn, LockMode lockMode)
txn
- the Txn
used for this operation.lockMode
- the LockMode usedNullPointerException
- if txn is null or if lockMode is null. If LockMode is null and a running txn is available
it will be aborted.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E set(E value)
This call lifts on the Txn
stored in the TxnThreadLocal
.
value
- the new value.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E setAndLock(E value, LockMode lockMode)
This call lifts on the Txn
stored in the TxnThreadLocal
.
value
- the new value.lockMode
- the used LockMode.NullPointerException
- if lockMode is null (if the txn is alive, it will also be aborted.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E set(Txn txn, E value)
txn
- the Txn
used for this operation.value
- the new valueNullPointerException
- if txn is null.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E setAndLock(Txn txn, E value, LockMode lockMode)
txn
- the Txn
used for this operation.value
- the new valuelockMode
- the lockMode used.NullPointerException
- if txn is null or lockMode is null. If the lockMode is null and the txn
is alive, it will be aborted.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E getAndSet(E value)
This call lifts on the Txn
stored in the TxnThreadLocal
.
value
- the new value.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E getAndSetAndLock(E value, LockMode lockMode)
This call lifts on the Txn
stored in the TxnThreadLocal
.
value
- the new value.lockMode
- the LockMode used.NullPointerException
- if LockMode is null. If a running txn is available, it will be aborted.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E getAndSet(Txn txn, E value)
value
- the new value.txn
- the Txn
used for this operation.NullPointerException
- if txn is null.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E getAndSetAndLock(Txn txn, E value, LockMode lockMode)
This call lifts on the Txn
stored in the TxnThreadLocal
.
value
- the new value.txn
- the Txn
used for this operation.lockMode
- the LockMode used.NullPointerException
- if txn or LockMode is null. If the txn is running, and the LockMode is null,
it will be aborted.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E atomicGet()
atomicWeakGet()
.TxnExecutionException
E atomicWeakGet()
It is the best method to call if you just want to get the current value stored.
E atomicSet(E newValue)
newValue
- the new value.TxnExecutionException
E atomicGetAndSet(E newValue)
newValue
- the new value.TxnExecutionException
void commute(Function<E> function)
This is different than the behavior in Clojure where the commute will be re-applied at the end of the txn, even though some dependency is introduced, which can lead to inconsistencies.
This call lifts on the Txn
stored in the TxnThreadLocal
.
function
- the function to apply to this reference.NullPointerException
- if function is null.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.void commute(Txn txn, Function<E> function)
This is different than the behavior in Clojure where the commute will be re-applied at the end of the txn, even though some dependency is introduced, which can lead to inconsistencies.
This call lifts on the Txn
stored in the TxnThreadLocal
.
txn
- the Txn
used for this operation.function
- the function to apply to this reference.NullPointerException
- if function is null. If there is an active txn, it will be aborted.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E atomicAlterAndGet(Function<E> function)
function
- the Function usedNullPointerException
- if function is null.E alterAndGet(Function<E> function)
This call lifts on the Txn
stored in the TxnThreadLocal
.
function
- the function that alters the value stored in this Ref.NullPointerException
- if function is null. The Txn will also be aborted.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E alterAndGet(Txn txn, Function<E> function)
function
- the function that alters the value stored in this Ref.txn
- the Txn
used for this operation.NullPointerException
- if function or txn is null.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E atomicGetAndAlter(Function<E> function)
function
- the Function usedNullPointerException
- if function is null.TxnExecutionException
E getAndAlter(Function<E> function)
This call lifts on the Txn
stored in the TxnThreadLocal
.
function
- the function that alters the value stored in this Ref.NullPointerException
- if function is null. The txn will be aborted as well.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E getAndAlter(Txn txn, Function<E> function)
function
- the function that alters the value stored in this Ref.txn
- the Txn
used for this operation.NullPointerException
- if function or txn is null. The txn will be aborted as well.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.boolean atomicCompareAndSet(E expectedValue, E newValue)
expectedValue
- the expected value.newValue
- the new value.TxnExecutionException
boolean isNull()
This call lifts on the Txn
stored in the TxnThreadLocal
.
TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.boolean isNull(Txn txn)
txn
- the Txn
used for this operation.NullPointerException
- if txn is null.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.boolean atomicIsNull()
TxnExecutionException
E awaitNotNullAndGet()
This call lifts on the Txn
stored in the TxnThreadLocal
.
TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.E awaitNotNullAndGet(Txn txn)
txn
- the Txn
used for this operation.NullPointerException
- if txn is null.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.void awaitNull()
This call lifts on the Txn
stored in the TxnThreadLocal
.
TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.void awaitNull(Txn txn)
txn
- the Txn
used for this operation.NullPointerException
- if txn is null.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.void await(E value)
This call lifts on the Txn
stored in the TxnThreadLocal
.
value
- the value to wait for.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.void await(Txn txn, E value)
txn
- the Txn
used for this operation.value
- the value to wait for.NullPointerException
- if txn is null.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.void await(Predicate<E> predicate)
This call lifts on the Txn
stored in the TxnThreadLocal
.
predicate
- the predicate to evaluate.NullPointerException
- if predicate is null. When there is a non dead txn,
it will be aborted.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.void await(Txn txn, Predicate<E> predicate)
txn
- the Txn
used for this operation.predicate
- the predicate to evaluate.NullPointerException
- if predicate is null or txn is null. When there is a non dead txn,
it will be aborted.TxnExecutionException
- if something failed while using the txn. The txn is guaranteed to have been aborted.ControlFlowError
- if the Stm needs to control the flow in a different way than normal returns of exceptions. The txn
is guaranteed to have been aborted.Copyright © 2020. All rights reserved.