Interface AsyncAtomicBoolean
-
- All Known Implementing Classes:
AsyncLocalAtomicBoolean
,AsyncRemoteAtomicBoolean
public interface AsyncAtomicBoolean
Aboolean
value that may be updated atomically.Unlike
AtomicBoolean
, each method from this interface is non-blocking, which allows asynchronous invocation and consumption of the return value viaCompletableFuture
API. This is particularly useful when usingremote
implementation, because of relatively high latency associated with an inevitable network call, but we do provide alocal
implementation as well.An
AsyncAtomicBoolean
is used in applications such as atomically updated flags, and cannot be used as a replacement for aBoolean
.- Since:
- 21.12
- Author:
- Aleks Seovic 2020.12.07
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CompletableFuture<Boolean>
compareAndExchange(boolean fExpectedValue, boolean fNewValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
.CompletableFuture<Boolean>
compareAndSet(boolean fExpectedValue, boolean fNewValue)
Atomically sets the value tonewValue
if the current value== expectedValue
.CompletableFuture<Boolean>
get()
Returns the current value.CompletableFuture<Boolean>
getAndSet(boolean fNewValue)
Atomically sets the value tonewValue
and returns the old value.CompletableFuture<Void>
set(boolean fNewValue)
Sets the value tonewValue
.
-
-
-
Method Detail
-
get
CompletableFuture<Boolean> get()
Returns the current value.- Returns:
- the current value
-
set
CompletableFuture<Void> set(boolean fNewValue)
Sets the value tonewValue
.- Parameters:
fNewValue
- the new value- Returns:
- a
CompletableFuture
that can be used to determine whether the operation completed
-
getAndSet
CompletableFuture<Boolean> getAndSet(boolean fNewValue)
Atomically sets the value tonewValue
and returns the old value.- Parameters:
fNewValue
- the new value- Returns:
- the previous value
-
compareAndSet
CompletableFuture<Boolean> compareAndSet(boolean fExpectedValue, boolean fNewValue)
Atomically sets the value tonewValue
if the current value== expectedValue
.- Parameters:
fExpectedValue
- the expected valuefNewValue
- the new value- Returns:
true
if successful. False return indicates that the actual value was not equal to the expected value.
-
compareAndExchange
CompletableFuture<Boolean> compareAndExchange(boolean fExpectedValue, boolean fNewValue)
Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
.- Parameters:
fExpectedValue
- the expected valuefNewValue
- the new value- Returns:
- the witness value, which will be the same as the expected value if successful
-
-