|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface TxnLong
A Transactional Reference comparable to the Clojure Ref.
If a method is prefixed with atomic, the call will always run under its own txn, no
matter if there already is a txn available (so the propagation level is 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.
| Method Summary | |
|---|---|
long |
alterAndGet(LongFunction function)
Alters the value stored in this Ref using the provided function and returns the result. |
long |
alterAndGet(Txn txn,
LongFunction function)
Alters the value stored in this Ref using the provided function and lifting on the provided txn. |
long |
atomicAlterAndGet(LongFunction function)
Atomically applies the function to the current value in this ref and returns the new value. |
boolean |
atomicCompareAndSet(long expectedValue,
long newValue)
Executes a compare and set atomically. |
long |
atomicGet()
Atomically gets the value. |
long |
atomicGetAndAlter(LongFunction function)
Atomically applies the function to alter the value stored in this ref and returns the old value. |
long |
atomicGetAndIncrement(long amount)
Atomically increments the value and returns the old value. |
long |
atomicGetAndSet(long newValue)
Atomically sets the value and returns the previous value. |
long |
atomicIncrementAndGet(long amount)
Atomically increments the value and returns the old value. |
long |
atomicSet(long newValue)
Atomically sets the value and returns the new value. |
long |
atomicWeakGet()
Atomically gets the value without providing any ordering guarantees. |
void |
await(long value)
Awaits for the value to become the given value. |
void |
await(LongPredicate predicate)
Awaits until the predicate holds. |
void |
await(Txn txn,
long value)
Awaits for the reference to become the given value. |
void |
await(Txn txn,
LongPredicate predicate)
Awaits until the predicate holds using the provided txn. |
void |
commute(LongFunction function)
Applies the function on the ref in a commuting manner. |
void |
commute(Txn txn,
LongFunction function)
Applies the function on the ref in a commuting manner. |
void |
decrement()
Decrements the value by one. |
void |
decrement(long amount)
Decrements the value by the given amount. |
void |
decrement(Txn txn)
Decrements the value by one using the provided txn. |
void |
decrement(Txn txn,
long amount)
Decrements the value by the given amount using the provided txn. |
long |
get()
Gets the value using the provided txn. |
long |
get(Txn txn)
Gets the value using the provided txn. |
long |
getAndAlter(LongFunction function)
Alters the value stored in this Ref using the provided function amd returns the old value. |
long |
getAndAlter(Txn txn,
LongFunction function)
Alters the value stored in this Ref using the function and returns the old value, using the provided txn. |
long |
getAndIncrement(long amount)
Increments the value and returns the old value. |
long |
getAndIncrement(Txn txn,
long amount)
Increments the value and returns the old value using the provided txn. |
long |
getAndLock(LockMode lockMode)
Gets the value and applies the lock. |
long |
getAndLock(Txn txn,
LockMode lockMode)
Gets the value using the provided txn and acquired the lock with the specified LockMode. |
long |
getAndSet(long value)
Sets the value the value and returns the new value. |
long |
getAndSet(Txn txn,
long value)
Sets the value using the provided txn. |
long |
getAndSetAndLock(long value,
LockMode lockMode)
Sets the value, acquired the Lock with the specified Lockmode and returns the previous value. |
long |
getAndSetAndLock(Txn txn,
long value,
LockMode lockMode)
Sets the value and acquired the Lock with the provided LockMode. |
void |
increment()
Increments the value by one. |
void |
increment(long amount)
Increments the value by the given amount. |
void |
increment(Txn txn)
Increments the value by one using the provided txn. |
void |
increment(Txn txn,
long amount)
Increments the value by the given amount using the provided txn. |
long |
incrementAndGet(long amount)
Increments and gets the new value. |
long |
incrementAndGet(Txn txn,
long amount)
Increments and gets the new value using the provided txn. |
long |
set(long value)
Sets the new value. |
long |
set(Txn txn,
long value)
Sets the new value using the provided txn. |
long |
setAndLock(long value,
LockMode lockMode)
Sets the new value and applies the lock. |
long |
setAndLock(Txn txn,
long value,
LockMode lockMode)
Sets the new value using the provided txn. |
| Methods inherited from interface org.multiverse.api.TxnObject |
|---|
atomicToString, ensure, ensure, getLock, getStm, getVersion, toDebugString, toString, toString |
| Method Detail |
|---|
long 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()long 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()long 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.
long getAndLock(Txn txn,
LockMode lockMode)
txn - the Txn used for this operation.lockMode - the LockMode used
NullPointerException - 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.long set(long 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.
long setAndLock(long 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.
long set(Txn txn,
long value)
txn - the Txn used for this operation.value - the new value
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.
long setAndLock(Txn txn,
long 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.long getAndSet(long 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.
long getAndSetAndLock(long 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.
long getAndSet(Txn txn,
long 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.
long getAndSetAndLock(Txn txn,
long 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.long atomicGet()
atomicWeakGet().
TxnExecutionExceptionlong atomicWeakGet()
It is the best method to call if you just want to get the current value stored.
long atomicSet(long newValue)
newValue - the new value.
TxnExecutionExceptionlong atomicGetAndSet(long newValue)
newValue - the new value.
TxnExecutionExceptionvoid commute(LongFunction 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,
LongFunction 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.long atomicAlterAndGet(LongFunction function)
function - the Function used
NullPointerException - if function is null.long alterAndGet(LongFunction 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.
long alterAndGet(Txn txn,
LongFunction 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.long atomicGetAndAlter(LongFunction function)
function - the Function used
NullPointerException - if function is null.
TxnExecutionExceptionlong getAndAlter(LongFunction 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.
long getAndAlter(Txn txn,
LongFunction 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(long expectedValue,
long newValue)
expectedValue - the expected value.newValue - the new value.
TxnExecutionExceptionlong atomicGetAndIncrement(long amount)
amount - the amount to increase with.
TxnExecutionExceptionlong getAndIncrement(long amount)
This call lifts on the Txn stored in the TxnThreadLocal.
amount - the amount to increment with.
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.
long getAndIncrement(Txn txn,
long amount)
txn - the Txn used for this operation.amount - the amount to increment with.
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.long atomicIncrementAndGet(long amount)
amount - the amount to increment with.
TxnExecutionExceptionlong incrementAndGet(long amount)
This call lifts on the Txn stored in the TxnThreadLocal.
amount - the amount to increment with.
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.
long incrementAndGet(Txn txn,
long amount)
txn - the Txn used for this operation.amount - the amount to increment with.
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 increment()
This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.
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 increment(Txn txn)
This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return 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.void increment(long amount)
This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.
This call lifts on the Txn stored in the TxnThreadLocal.
amount - the amount to increase with
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.ControlFlowError
void increment(Txn txn,
long amount)
This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.
txn - the Txn used for this operation.amount - the amount to increment with
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 decrement()
This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.
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 decrement(Txn txn)
This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return 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.void decrement(long amount)
This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.
This call lifts on the Txn stored in the TxnThreadLocal.
amount - the amount to decrement with
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 decrement(Txn txn,
long amount)
This call is able to commute if there are no dependencies on the value in the txn. That is why this method doesn't have a return value.
txn - the Txn used for this operation.amount - the amount to decrement with
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(long 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,
long 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(LongPredicate 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,
LongPredicate 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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||