Interface IAtomicReference<E>
- Type Parameters:
- E- the type of object referred to by this reference
- All Superinterfaces:
- 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)
- Since:
- 3.2
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionvoidAlters the currently stored reference by applying a function on it.alterAndGet(IFunction<E, E> function) Alters the currently stored reference by applying a function on it and gets the result.alterAndGetAsync(IFunction<E, E> function) Alters the currently stored reference by applying a function on it and gets the result.alterAsync(IFunction<E, E> function) Alters the currently stored reference by applying a function on it.<R> RApplies 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.voidclear()Clears the current stored reference.Clears the current stored reference.booleancompareAndSet(E expect, E update) Atomically sets the value to the given updated value only if the current value==the expected value.compareAndSetAsync(E expect, E update) Atomically sets the value to the given updated value only if the current value==the expected value.booleanChecks if the reference contains the value.containsAsync(E expected) Checks if the reference contains the value.get()Gets the current value.getAndAlter(IFunction<E, E> function) Alters the currently stored reference by applying a function on it on and gets the old value.getAndAlterAsync(IFunction<E, E> function) Alters the currently stored reference by applying a function on it on and gets the old value.Gets the old value and sets the new value.getAndSetAsync(E newValue) Gets the value and sets the new value.getAsync()Gets the current value.booleanisNull()Checks if the stored reference isnull.Checks if the stored reference isnull.voidAtomically sets the given value.Atomically sets the given value.Methods inherited from interface com.hazelcast.core.DistributedObjectdestroy, getDestroyContextForTenant, getName, getPartitionKey, getServiceName
- 
Method Details- 
compareAndSetAtomically sets the value to the given updated value only if the current value==the expected value.- Parameters:
- expect- the expected value
- update- the new value
- Returns:
- trueif successful; or- falseif the actual value was not equal to the expected value
 
- 
getE get()Gets the current value.- Returns:
- the current value
 
- 
setAtomically sets the given value.- Parameters:
- newValue- the new value
 
- 
getAndSetGets the old value and sets the new value.- Parameters:
- newValue- the new value
- Returns:
- the old value
 
- 
isNullboolean isNull()Checks if the stored reference isnull.- Returns:
- trueif- null,- falseotherwise
 
- 
clearvoid clear()Clears the current stored reference.
- 
containsChecks if the reference contains the value.- Parameters:
- value- the value to check (is allowed to be- null)
- Returns:
- trueif the value is found,- falseotherwise
 
- 
alterAlters the currently stored reference by applying a function on it.- Parameters:
- function- the function that alters the currently stored reference
- Throws:
- IllegalArgumentException- if function is- null
 
- 
alterAndGetAlters the currently stored reference by applying a function on it and gets the result.- Parameters:
- function- the function that alters the currently stored reference
- Returns:
- the new value, the result of the applied function
- Throws:
- IllegalArgumentException- if function is- null
 
- 
getAndAlterAlters the currently stored reference by applying a function on it on and gets the old value.- Parameters:
- function- the function that alters the currently stored reference
- Returns:
- the old value, the value before the function is applied
- Throws:
- IllegalArgumentException- if function is- null
 
- 
applyApplies a function on the value, the actual stored value will not change.- Type Parameters:
- R- the result type of the function
- Parameters:
- function- the function applied on the value, the stored value does not change
- Returns:
- the result of the function application
- Throws:
- IllegalArgumentException- if function is- null
 
- 
compareAndSetAsyncAtomically sets the value to the given updated value only if the current value==the expected value.- Parameters:
- expect- the expected value
- update- the new value
- Returns:
- trueif successful; or- falseif the actual value was not equal to the expected value
 
- 
getAsyncCompletionStage<E> getAsync()Gets the current value.- Returns:
- the current value
 
- 
setAsyncAtomically sets the given value.- Parameters:
- newValue- the new value
 
- 
getAndSetAsyncGets the value and sets the new value.- Parameters:
- newValue- the new value
- Returns:
- the old value
 
- 
isNullAsyncCompletionStage<Boolean> isNullAsync()Checks if the stored reference isnull.- Returns:
- trueif- null,- falseotherwise
 
- 
clearAsyncCompletionStage<Void> clearAsync()Clears the current stored reference.
- 
containsAsyncChecks if the reference contains the value.- Parameters:
- expected- the value to check (is allowed to be null)
- Returns:
- trueif the value is found,- falseotherwise
 
- 
alterAsyncAlters the currently stored reference by applying a function on it.- Parameters:
- function- the function
- Throws:
- IllegalArgumentException- if function is- null
 
- 
alterAndGetAsyncAlters the currently stored reference by applying a function on it and gets the result.- Parameters:
- function- the function
- Returns:
- the new value
- Throws:
- IllegalArgumentException- if function is- null
 
- 
getAndAlterAsyncAlters the currently stored reference by applying a function on it on and gets the old value.- Parameters:
- function- the function
- Returns:
- the old value
- Throws:
- IllegalArgumentException- if function is- null
 
- 
applyAsyncApplies a function on the value, the actual stored value will not change.- Type Parameters:
- R- the result type of the function
- Parameters:
- function- the function
- Returns:
- the result of the function application
- Throws:
- IllegalArgumentException- if function is- null
 
 
-