public interface TxnDouble 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 |
---|---|
double |
alterAndGet(DoubleFunction function)
Alters the value stored in this Ref using the provided function and returns the result.
|
double |
alterAndGet(Txn txn,
DoubleFunction function)
Alters the value stored in this Ref using the provided function and lifting on the provided txn.
|
double |
atomicAlterAndGet(DoubleFunction function)
Atomically applies the function to the current value in this ref and returns the new value.
|
boolean |
atomicCompareAndSet(double expectedValue,
double newValue)
Executes a compare and set atomically.
|
double |
atomicGet()
Atomically gets the value.
|
double |
atomicGetAndAlter(DoubleFunction function)
Atomically applies the function to alter the value stored in this ref and returns the old value.
|
double |
atomicGetAndIncrement(double amount)
Atomically increments the value and returns the old value.
|
double |
atomicGetAndSet(double newValue)
Atomically sets the value and returns the previous value.
|
double |
atomicIncrementAndGet(double amount)
Atomically increments the value and returns the old value.
|
double |
atomicSet(double newValue)
Atomically sets the value and returns the new value.
|
double |
atomicWeakGet()
Atomically gets the value without providing any ordering guarantees.
|
void |
await(double value)
Awaits for the value to become the given value.
|
void |
await(DoublePredicate predicate)
Awaits until the predicate holds.
|
void |
await(Txn txn,
double value)
Awaits for the reference to become the given value.
|
void |
await(Txn txn,
DoublePredicate predicate)
Awaits until the predicate holds using the provided txn.
|
void |
commute(DoubleFunction function)
Applies the function on the ref in a commuting manner.
|
void |
commute(Txn txn,
DoubleFunction function)
Applies the function on the ref in a commuting manner.
|
double |
get()
Gets the value using the provided txn.
|
double |
get(Txn txn)
Gets the value using the provided txn.
|
double |
getAndAlter(DoubleFunction function)
Alters the value stored in this Ref using the provided function amd returns the old value.
|
double |
getAndAlter(Txn txn,
DoubleFunction function)
Alters the value stored in this Ref using the function and returns the old value, using the provided txn.
|
double |
getAndIncrement(double amount)
Increments the value and returns the old value.
|
double |
getAndIncrement(Txn txn,
double amount)
Increments the value and returns the old value using the provided txn.
|
double |
getAndLock(LockMode lockMode)
Gets the value and applies the lock.
|
double |
getAndLock(Txn txn,
LockMode lockMode)
Gets the value using the provided txn and acquired the lock with the specified LockMode.
|
double |
getAndSet(double value)
Sets the value the value and returns the new value.
|
double |
getAndSet(Txn txn,
double value)
Sets the value using the provided txn.
|
double |
getAndSetAndLock(double value,
LockMode lockMode)
Sets the value, acquired the Lock with the specified Lockmode and returns the previous value.
|
double |
getAndSetAndLock(Txn txn,
double value,
LockMode lockMode)
Sets the value and acquired the Lock with the provided LockMode.
|
double |
incrementAndGet(double amount)
Increments and gets the new value.
|
double |
incrementAndGet(Txn txn,
double amount)
Increments and gets the new value using the provided txn.
|
double |
set(double value)
Sets the new value.
|
double |
set(Txn txn,
double value)
Sets the new value using the provided txn.
|
double |
setAndLock(double value,
LockMode lockMode)
Sets the new value and applies the lock.
|
double |
setAndLock(Txn txn,
double value,
LockMode lockMode)
Sets the new value using the provided txn.
|
atomicToString, ensure, ensure, getLock, getStm, getVersion, toDebugString, toString, toString
double 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()
double 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()
double 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.double 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.double set(double 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.double setAndLock(double 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.double set(Txn txn, double 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.double setAndLock(Txn txn, double 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.double getAndSet(double 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.double getAndSetAndLock(double 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.double getAndSet(Txn txn, double 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.double getAndSetAndLock(Txn txn, double 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.double atomicGet()
atomicWeakGet()
.TxnExecutionException
double atomicWeakGet()
It is the best method to call if you just want to get the current value stored.
double atomicSet(double newValue)
newValue
- the new value.TxnExecutionException
double atomicGetAndSet(double newValue)
newValue
- the new value.TxnExecutionException
void commute(DoubleFunction 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, DoubleFunction 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.double atomicAlterAndGet(DoubleFunction function)
function
- the Function usedNullPointerException
- if function is null.double alterAndGet(DoubleFunction 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.double alterAndGet(Txn txn, DoubleFunction 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.double atomicGetAndAlter(DoubleFunction function)
function
- the Function usedNullPointerException
- if function is null.TxnExecutionException
double getAndAlter(DoubleFunction 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.double getAndAlter(Txn txn, DoubleFunction 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(double expectedValue, double newValue)
expectedValue
- the expected value.newValue
- the new value.TxnExecutionException
double atomicGetAndIncrement(double amount)
amount
- the amount to increase with.TxnExecutionException
double getAndIncrement(double 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.double getAndIncrement(Txn txn, double 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.double atomicIncrementAndGet(double amount)
amount
- the amount to increment with.TxnExecutionException
double incrementAndGet(double 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.double incrementAndGet(Txn txn, double 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 await(double 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, double 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(DoublePredicate 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, DoublePredicate 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.