Interface AsyncAtomicBoolean
- All Known Implementing Classes:
AsyncLocalAtomicBoolean
,AsyncRemoteAtomicBoolean
public interface AsyncAtomicBoolean
A
boolean
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
via CompletableFuture
API. This is particularly useful when using
remote
implementation, because of relatively
high latency associated with an inevitable network call, but we do provide a
local
implementation as well.
An AsyncAtomicBoolean
is used in applications such as atomically updated
flags, and cannot be used as a replacement for a Boolean
.
- Since:
- 21.12
- Author:
- Aleks Seovic 2020.12.07
-
Method Summary
Modifier and TypeMethodDescriptioncompareAndExchange
(boolean fExpectedValue, boolean fNewValue) Atomically sets the value tonewValue
if the current value, referred to as the witness value,== expectedValue
.compareAndSet
(boolean fExpectedValue, boolean fNewValue) Atomically sets the value tonewValue
if the current value== expectedValue
.get()
Returns the current value.getAndSet
(boolean fNewValue) Atomically sets the value tonewValue
and returns the old value.set
(boolean fNewValue) Sets the value tonewValue
.
-
Method Details
-
get
CompletableFuture<Boolean> get()Returns the current value.- Returns:
- the current value
-
set
Sets the value tonewValue
.- Parameters:
fNewValue
- the new value- Returns:
- a
CompletableFuture
that can be used to determine whether the operation completed
-
getAndSet
Atomically sets the value tonewValue
and returns the old value.- Parameters:
fNewValue
- the new value- Returns:
- the previous value
-
compareAndSet
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
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
-