public interface IAtomicLong extends DistributedObject
AtomicLong
.
Asynchronous variants of all methods have been introduced in version 3.7.
Async methods return immediately an ICompletableFuture
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:
ICompletableFuture future = atomicLong.addAndGetAsync(13);
future.andThen(new ExecutionCallback<Long>() {
void onResponse(Long response) {
// do something with the result
}
void onFailure(Throwable t) {
// handle failure
}
});
During a network partition event it is possible for the IAtomicLong
to exist in each of the partitioned clusters or to not exist at all. Under
these circumstances the values held in the IAtomicLong
may diverge.
Once the network partition heals, Hazelcast will use the configured
split-brain merge policy to resolve conflicting values.
Supports Quorum QuorumConfig
since 3.10 in
cluster versions 3.10 and higher.
IAtomicReference
Modifier and Type | Method and Description |
---|---|
long |
addAndGet(long delta)
Atomically adds the given value to the current value.
|
ICompletableFuture<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.
|
ICompletableFuture<Long> |
alterAndGetAsync(IFunction<Long,Long> function)
Alters the currently stored value by applying a function on it and gets
the result.
|
ICompletableFuture<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> ICompletableFuture<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. |
ICompletableFuture<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.
|
ICompletableFuture<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.
|
ICompletableFuture<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.
|
ICompletableFuture<Long> |
getAndAlterAsync(IFunction<Long,Long> function)
Alters the currently stored value by applying a function on it on and
gets the old value.
|
long |
getAndIncrement()
Atomically increments the current value by one.
|
ICompletableFuture<Long> |
getAndIncrementAsync()
Atomically increments the current value by one.
|
long |
getAndSet(long newValue)
Atomically sets the given value and returns the old value.
|
ICompletableFuture<Long> |
getAndSetAsync(long newValue)
Atomically sets the given value and returns the old value.
|
ICompletableFuture<Long> |
getAsync()
Gets the current value.
|
String |
getName()
Returns the name of this IAtomicLong instance.
|
long |
incrementAndGet()
Atomically increments the current value by one.
|
ICompletableFuture<Long> |
incrementAndGetAsync()
Atomically increments the current value by one.
|
void |
set(long newValue)
Atomically sets the given value.
|
ICompletableFuture<Void> |
setAsync(long newValue)
Atomically sets the given value.
|
destroy, 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 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)
function
- the function applied to the value, the value is not changedIllegalArgumentException
- if function is null
ICompletableFuture<Long> addAndGetAsync(long delta)
This method will dispatch a request and return immediately an
ICompletableFuture
.
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:
ICompletableFuture future = atomicLong.addAndGetAsync(13);
// do something else, then read the result
// this method will block until the result is available
Long result = future.get();
ICompletableFuture future = atomicLong.addAndGetAsync(13);
future.andThen(new ExecutionCallback<Long>() {
void onResponse(Long response) {
// do something with the result
}
void onFailure(Throwable t) {
// handle failure
}
});
delta
- the value to addICompletableFuture
bearing the responseICompletableFuture<Boolean> compareAndSetAsync(long expect, long update)
==
the expected value.
This method will dispatch a request and return immediately an
ICompletableFuture
.
expect
- the expected valueupdate
- the new valueICompletableFuture
with value true
if successful;
or false
if the actual value was not equal to the expected valueICompletableFuture<Long> decrementAndGetAsync()
This method will dispatch a request and return immediately an
ICompletableFuture
.
ICompletableFuture
with the updated valueICompletableFuture<Long> getAsync()
ICompletableFuture
.ICompletableFuture
with the current valueICompletableFuture<Long> getAndAddAsync(long delta)
This method will dispatch a request and return immediately an
ICompletableFuture
.
delta
- the value to addICompletableFuture
with the old value before the additionICompletableFuture<Long> getAndSetAsync(long newValue)
This method will dispatch a request and return immediately an
ICompletableFuture
.
newValue
- the new valueICompletableFuture
with the old valueICompletableFuture<Long> incrementAndGetAsync()
This method will dispatch a request and return immediately an
ICompletableFuture
.
ICompletableFuture
with the updated valueICompletableFuture<Long> getAndIncrementAsync()
This method will dispatch a request and return immediately an
ICompletableFuture
.
ICompletableFuture
with the old valueICompletableFuture<Void> setAsync(long newValue)
This method will dispatch a request and return immediately an
ICompletableFuture
.
newValue
- the new valueICompletableFuture
ICompletableFuture<Void> alterAsync(IFunction<Long,Long> function)
This method will dispatch a request and return immediately an
ICompletableFuture
.
function
- the functionICompletableFuture
with the new valueIllegalArgumentException
- if function is null
ICompletableFuture<Long> alterAndGetAsync(IFunction<Long,Long> function)
This method will dispatch a request and return immediately an
ICompletableFuture
.
function
- the functionICompletableFuture
with the new valueIllegalArgumentException
- if function is null
ICompletableFuture<Long> getAndAlterAsync(IFunction<Long,Long> function)
This method will dispatch a request and return immediately an
ICompletableFuture
.
function
- the functionICompletableFuture
with the old valueIllegalArgumentException
- if function is null
<R> ICompletableFuture<R> applyAsync(IFunction<Long,R> function)
This method will dispatch a request and return immediately an
ICompletableFuture
. For example:
class IsOneFunction implements IFunction {
@Override
public Boolean apply(Long input) {
return input.equals(1L);
}
}
ICompletableFuture future = atomicLong.applyAsync(new IsOneFunction());
future.andThen(new ExecutionCallback<;Boolean>() {
void onResponse(Boolean response) {
// do something with the response
}
void onFailure(Throwable t) {
// handle failure
}
});
function
- the functionICompletableFuture
with the result of the function applicationIllegalArgumentException
- if function is null
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.