E
- the type of object referred to by this referencepublic interface IAtomicReference<E> extends DistributedObject
AtomicReference
.
Asynchronous variants have been introduced in version 3.7.
Async methods immediately return a CompletionStage
from which
the operation's result can be obtained either in a blocking manner or by
registering a callback to be executed upon completion. For example:
CompletionStage<E> future = atomicRef.getAsync(); future.whenCompleteAsync((v, throwable) -> { if (throwable == null) { // do something with the old value returned by put operation } else { // handle failure } });
Actions supplied for dependent completions of default non-async methods and async methods
without an explicit Executor
argument are performed
by the ForkJoinPool.commonPool()
(unless it does not
support a parallelism level of at least 2, in which case a new Thread
is
created per task).
IAtomicReference is accessed via CPSubsystem.getAtomicReference(String)
.
It works on top of the Raft consensus algorithm.
It offers linearizability during crash failures and network
partitions. It is CP with respect to the CAP principle. If a network
partition occurs, it remains available on at most one side of the partition.
IAtomicReference impl does not offer exactly-once / effectively-once
execution semantics. It goes with at-least-once execution semantics
by default and can cause an API call to be committed multiple times
in case of CP member failures. It can be tuned to offer at-most-once
execution semantics. Please see
CPSubsystemConfig.setFailOnIndeterminateOperationState(boolean)
IAtomicLong
Modifier and Type | Method and Description |
---|---|
void |
alter(IFunction<E,E> function)
Alters the currently stored reference by applying a function on it.
|
E |
alterAndGet(IFunction<E,E> function)
Alters the currently stored reference by applying a function on it and
gets the result.
|
CompletionStage<E> |
alterAndGetAsync(IFunction<E,E> function)
Alters the currently stored reference by applying a function on it and
gets the result.
|
CompletionStage<Void> |
alterAsync(IFunction<E,E> function)
Alters the currently stored reference by applying a function on it.
|
<R> R |
apply(IFunction<E,R> function)
Applies a function on the value, the actual stored value will not
change.
|
<R> CompletionStage<R> |
applyAsync(IFunction<E,R> function)
Applies a function on the value, the actual stored value will not
change.
|
void |
clear()
Clears the current stored reference.
|
CompletionStage<Void> |
clearAsync()
Clears the current stored reference.
|
boolean |
compareAndSet(E expect,
E update)
Atomically sets the value to the given updated value
only if the current value
== the expected value. |
CompletionStage<Boolean> |
compareAndSetAsync(E expect,
E update)
Atomically sets the value to the given updated value only if the
current value
== the expected value. |
boolean |
contains(E value)
Checks if the reference contains the value.
|
CompletionStage<Boolean> |
containsAsync(E expected)
Checks if the reference contains the value.
|
E |
get()
Gets the current value.
|
E |
getAndAlter(IFunction<E,E> function)
Alters the currently stored reference by applying a function on it on
and gets the old value.
|
CompletionStage<E> |
getAndAlterAsync(IFunction<E,E> function)
Alters the currently stored reference by applying a function on it on
and gets the old value.
|
E |
getAndSet(E newValue)
Gets the old value and sets the new value.
|
CompletionStage<E> |
getAndSetAsync(E newValue)
Gets the value and sets the new value.
|
CompletionStage<E> |
getAsync()
Gets the current value.
|
boolean |
isNull()
Checks if the stored reference is
null . |
CompletionStage<Boolean> |
isNullAsync()
Checks if the stored reference is
null . |
void |
set(E newValue)
Atomically sets the given value.
|
CompletionStage<Void> |
setAsync(E newValue)
Atomically sets the given value.
|
destroy, getName, getPartitionKey, getServiceName
boolean compareAndSet(E expect, E update)
==
the expected value.expect
- the expected valueupdate
- the new valuetrue
if successful; or false
if the actual value
was not equal to the expected valueE get()
void set(E newValue)
newValue
- the new valueE getAndSet(E newValue)
newValue
- the new valueboolean isNull()
null
.true
if null
, false
otherwisevoid clear()
boolean contains(E value)
value
- the value to check (is allowed to be null
)true
if the value is found, false
otherwisevoid alter(IFunction<E,E> function)
function
- the function that alters the currently stored referenceIllegalArgumentException
- if function is null
E alterAndGet(IFunction<E,E> function)
function
- the function that alters the currently stored referenceIllegalArgumentException
- if function is null
E getAndAlter(IFunction<E,E> function)
function
- the function that alters the currently stored referenceIllegalArgumentException
- if function is null
<R> R apply(IFunction<E,R> function)
R
- the result type of the functionfunction
- the function applied on the value, the stored value does not changeIllegalArgumentException
- if function is null
CompletionStage<Boolean> compareAndSetAsync(E expect, E update)
==
the expected value.expect
- the expected valueupdate
- the new valuetrue
if successful; or false
if the actual value
was not equal to the expected valueCompletionStage<E> getAsync()
CompletionStage<Void> setAsync(E newValue)
newValue
- the new valueCompletionStage<E> getAndSetAsync(E newValue)
newValue
- the new valueCompletionStage<Boolean> isNullAsync()
null
.true
if null
, false
otherwiseCompletionStage<Void> clearAsync()
CompletionStage<Boolean> containsAsync(E expected)
expected
- the value to check (is allowed to be null)true
if the value is found, false
otherwiseCompletionStage<Void> alterAsync(IFunction<E,E> function)
function
- the functionIllegalArgumentException
- if function is null
CompletionStage<E> alterAndGetAsync(IFunction<E,E> function)
function
- the functionIllegalArgumentException
- if function is null
CompletionStage<E> getAndAlterAsync(IFunction<E,E> function)
function
- the functionIllegalArgumentException
- if function is null
<R> CompletionStage<R> applyAsync(IFunction<E,R> function)
R
- the result type of the functionfunction
- the functionIllegalArgumentException
- if function is null
Copyright © 2021 Hazelcast, Inc.. All rights reserved.