public interface IAtomicLong extends DistributedObject
AtomicLong
.
Asynchronous variants of all methods have been introduced in version 3.7.
Async methods immediately return a CompletionStage
which can be used to
chain further computation stages or can be converted to a CompletableFuture
from which the operation's result can be obtained in a blocking manner. For example:
CompletionStage<Long> stage = atomicLong.addAndGetAsync(13); stage.whenCompleteAsync((response, t) -> { if (t == null) { // do something with the result } 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).
IAtomicLong is accessed via CPSubsystem.getAtomicLong(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.
IAtomicLong 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)
IAtomicReference
Modifier and Type | Method and Description |
---|---|
long |
addAndGet(long delta)
Atomically adds the given value to the current value.
|
CompletionStage<Long> |
addAndGetAsync(long delta)
Atomically adds the given value to the current value.
|
void |
alter(IFunction<Long,Long> function)
Alters the currently stored value by applying a function on it.
|
long |
alterAndGet(IFunction<Long,Long> function)
Alters the currently stored value by applying a function on it and
gets the result.
|
CompletionStage<Long> |
alterAndGetAsync(IFunction<Long,Long> function)
Alters the currently stored value by applying a function on it and gets
the result.
|
CompletionStage<Void> |
alterAsync(IFunction<Long,Long> function)
Alters the currently stored value by applying a function on it.
|
<R> R |
apply(IFunction<Long,R> function)
Applies a function on the value, the actual stored value will not change.
|
<R> CompletionStage<R> |
applyAsync(IFunction<Long,R> function)
Applies a function on the value, the actual stored value will not
change.
|
boolean |
compareAndSet(long expect,
long update)
Atomically sets the value to the given updated value
only if the current value
== the expected value. |
CompletionStage<Boolean> |
compareAndSetAsync(long expect,
long update)
Atomically sets the value to the given updated value
only if the current value
== the expected value. |
long |
decrementAndGet()
Atomically decrements the current value by one.
|
CompletionStage<Long> |
decrementAndGetAsync()
Atomically decrements the current value by one.
|
long |
get()
Gets the current value.
|
long |
getAndAdd(long delta)
Atomically adds the given value to the current value.
|
CompletionStage<Long> |
getAndAddAsync(long delta)
Atomically adds the given value to the current value.
|
long |
getAndAlter(IFunction<Long,Long> function)
Alters the currently stored value by applying a function on it on and
gets the old value.
|
CompletionStage<Long> |
getAndAlterAsync(IFunction<Long,Long> function)
Alters the currently stored value by applying a function on it on and
gets the old value.
|
long |
getAndDecrement()
Atomically decrements the current value by one.
|
CompletionStage<Long> |
getAndDecrementAsync()
Atomically decrements the current value by one.
|
long |
getAndIncrement()
Atomically increments the current value by one.
|
CompletionStage<Long> |
getAndIncrementAsync()
Atomically increments the current value by one.
|
long |
getAndSet(long newValue)
Atomically sets the given value and returns the old value.
|
CompletionStage<Long> |
getAndSetAsync(long newValue)
Atomically sets the given value and returns the old value.
|
CompletionStage<Long> |
getAsync()
Gets the current value.
|
String |
getName()
Returns the name of this IAtomicLong instance.
|
long |
incrementAndGet()
Atomically increments the current value by one.
|
CompletionStage<Long> |
incrementAndGetAsync()
Atomically increments the current value by one.
|
void |
set(long newValue)
Atomically sets the given value.
|
CompletionStage<Void> |
setAsync(long newValue)
Atomically sets the given value.
|
destroy, getDestroyContextForTenant, getPartitionKey, getServiceName
String getName()
getName
in interface DistributedObject
long addAndGet(long delta)
delta
- the value to add to the current valueboolean compareAndSet(long expect, long 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 value.long decrementAndGet()
long getAndDecrement()
long get()
long getAndAdd(long delta)
delta
- the value to add to the current valuelong getAndSet(long newValue)
newValue
- the new valuelong incrementAndGet()
long getAndIncrement()
void set(long newValue)
newValue
- the new valuevoid alter(IFunction<Long,Long> function)
function
- the function applied to the currently stored valueIllegalArgumentException
- if function is null
long alterAndGet(IFunction<Long,Long> function)
function
- the function applied to the currently stored valueIllegalArgumentException
- if function is null
long getAndAlter(IFunction<Long,Long> function)
function
- the function applied to the currently stored valueIllegalArgumentException
- if function is null
<R> R apply(IFunction<Long,R> function)
R
- the result type of the functionfunction
- the function applied to the value, the value is not changedIllegalArgumentException
- if function is null
CompletionStage<Long> addAndGetAsync(long delta)
This method will dispatch a request and return immediately a
CompletionStage
.
The operations result can be obtained in a blocking way, or a callback can be provided for execution upon completion, as demonstrated in the following examples:
CompletionStage<Long> stage = atomicLong.addAndGetAsync(13); // do something else, then read the result // this method will block until the result is available Long result = stage.toCompletableFuture().get();
CompletionStage<Long> stage = atomicLong.addAndGetAsync(13); stage.whenCompleteAsync((response, t) -> { if (t == null) { // do something with the result } else { // handle failure } });
delta
- the value to addCompletionStage
bearing the responseCompletionStage<Boolean> compareAndSetAsync(long expect, long update)
==
the expected value.
This method will dispatch a request and return immediately a
CompletionStage
.
expect
- the expected valueupdate
- the new valueCompletionStage
with value true
if successful;
or false
if the actual value was not equal to the expected valueCompletionStage<Long> decrementAndGetAsync()
This method will dispatch a request and return immediately a
CompletionStage
.
CompletionStage
with the updated valueCompletionStage<Long> getAndDecrementAsync()
This method will dispatch a request and return immediately a
CompletionStage
.
CompletionStage
with the old valueCompletionStage<Long> getAsync()
CompletionStage
.CompletionStage
with the current valueCompletionStage<Long> getAndAddAsync(long delta)
This method will dispatch a request and return immediately a
CompletionStage
.
delta
- the value to addCompletionStage
with the old value before the additionCompletionStage<Long> getAndSetAsync(long newValue)
This method will dispatch a request and return immediately a
CompletionStage
.
newValue
- the new valueCompletionStage
with the old valueCompletionStage<Long> incrementAndGetAsync()
This method will dispatch a request and return immediately a
CompletionStage
.
CompletionStage
with the updated valueCompletionStage<Long> getAndIncrementAsync()
This method will dispatch a request and return immediately a
CompletionStage
.
CompletionStage
with the old valueCompletionStage<Void> setAsync(long newValue)
This method will dispatch a request and return immediately a
CompletionStage
.
newValue
- the new valueCompletionStage
CompletionStage<Void> alterAsync(IFunction<Long,Long> function)
This method will dispatch a request and return immediately a
CompletionStage
.
function
- the functionCompletionStage
with the new valueIllegalArgumentException
- if function is null
CompletionStage<Long> alterAndGetAsync(IFunction<Long,Long> function)
This method will dispatch a request and return immediately a
CompletionStage
.
function
- the functionCompletionStage
with the new valueIllegalArgumentException
- if function is null
CompletionStage<Long> getAndAlterAsync(IFunction<Long,Long> function)
This method will dispatch a request and return immediately a
CompletionStage
.
function
- the functionCompletionStage
with the old valueIllegalArgumentException
- if function is null
<R> CompletionStage<R> applyAsync(IFunction<Long,R> function)
This method will dispatch a request and return immediately a
CompletionStage
. For example:
class IsOneFunction implements IFunction<Long, Boolean> { @Override public Boolean apply(Long input) { return input.equals(1L); } } CompletionStage<Boolean> stage = atomicLong.applyAsync(new IsOneFunction()); stage.whenCompleteAsync((response, t) -> { if (t == null) { // do something with the response } else { // handle failure } });
R
- the result type of the functionfunction
- the functionCompletionStage
with the result of the function applicationIllegalArgumentException
- if function is null
Copyright © 2024 Hazelcast, Inc.. All rights reserved.