AtomicLong

class AtomicLong(context, group_id, service_name, proxy_name, object_name)[source]

Bases: BaseCPProxy[BlockingAtomicLong]

AtomicLong is a redundant and highly available distributed counter for 64-bit integers (long type in Java).

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.

AtomicLong implementation 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 fail-on-indeterminate-operation-state server-side setting.

add_and_get(delta: int) Future[int][source]

Atomically adds the given value to the current value.

Parameters

delta – The value to add to the current value.

Returns

The updated value, the given value added to the current value.

compare_and_set(expect: int, update: int) Future[bool][source]

Atomically sets the value to the given updated value only if the current value equals the expected value.

Parameters
  • expect – The expected value.

  • update – The new value.

Returns

True if successful; or False if the actual value was not equal to the expected value.

decrement_and_get() Future[int][source]

Atomically decrements the current value by one.

Returns

The updated value, the current value decremented by one.

get_and_decrement() Future[int][source]

Atomically decrements the current value by one.

Returns

The old value.

get() Future[int][source]

Gets the current value.

Returns

The current value.

get_and_add(delta: int) Future[int][source]

Atomically adds the given value to the current value.

Parameters

delta – The value to add to the current value.

Returns

The old value before the add.

get_and_set(new_value: int) Future[int][source]

Atomically sets the given value and returns the old value.

Parameters

new_value – The new value.

Returns

The old value.

increment_and_get() Future[int][source]

Atomically increments the current value by one.

Returns

The updated value, the current value incremented by one.

get_and_increment() Future[int][source]

Atomically increments the current value by one.

Returns

The old value.

set(new_value: int) Future[None][source]

Atomically sets the given value.

Parameters

new_value – The new value

alter(function: Any) Future[None][source]

Alters the currently stored value by applying a function on it.

Notes

function must be an instance of Hazelcast serializable type. It must have a counterpart registered in the server-side that implements the com.hazelcast.core.IFunction interface with the actual logic of the function to be applied.

Parameters

function – The function that alters the currently stored value.

alter_and_get(function: Any) Future[int][source]

Alters the currently stored value by applying a function on it and gets the result.

Notes

function must be an instance of Hazelcast serializable type. It must have a counterpart registered in the server-side that implements the com.hazelcast.core.IFunction interface with the actual logic of the function to be applied.

Parameters

function – The function that alters the currently stored value.

Returns

The new value.

get_and_alter(function: Any) Future[int][source]

Alters the currently stored value by applying a function on it and gets the old value.

Notes

function must be an instance of Hazelcast serializable type. It must have a counterpart registered in the server-side that implements the com.hazelcast.core.IFunction interface with the actual logic of the function to be applied.

Parameters

function – The function that alters the currently stored value.

Returns

The old value.

apply(function: Any) Future[Any][source]

Applies a function on the value, the actual stored value will not change.

Notes

function must be an instance of Hazelcast serializable type. It must have a counterpart registered in the server-side that implements the com.hazelcast.core.IFunction interface with the actual logic of the function to be applied.

Parameters

function – The function applied to the currently stored value.

Returns

The result of the function application.

blocking() BlockingAtomicLong[source]

Returns a version of this proxy with only blocking method calls.

class BlockingAtomicLong(wrapped: AtomicLong)[source]

Bases: AtomicLong

add_and_get(delta: int) int[source]

Atomically adds the given value to the current value.

Parameters

delta – The value to add to the current value.

Returns

The updated value, the given value added to the current value.

compare_and_set(expect: int, update: int) bool[source]

Atomically sets the value to the given updated value only if the current value equals the expected value.

Parameters
  • expect – The expected value.

  • update – The new value.

Returns

True if successful; or False if the actual value was not equal to the expected value.

decrement_and_get() int[source]

Atomically decrements the current value by one.

Returns

The updated value, the current value decremented by one.

get_and_decrement() int[source]

Atomically decrements the current value by one.

Returns

The old value.

get() int[source]

Gets the current value.

Returns

The current value.

get_and_add(delta: int) int[source]

Atomically adds the given value to the current value.

Parameters

delta – The value to add to the current value.

Returns

The old value before the add.

get_and_set(new_value: int) int[source]

Atomically sets the given value and returns the old value.

Parameters

new_value – The new value.

Returns

The old value.

increment_and_get() int[source]

Atomically increments the current value by one.

Returns

The updated value, the current value incremented by one.

get_and_increment() int[source]

Atomically increments the current value by one.

Returns

The old value.

set(new_value: int) None[source]

Atomically sets the given value.

Parameters

new_value – The new value

alter(function: Any) None[source]

Alters the currently stored value by applying a function on it.

Notes

function must be an instance of Hazelcast serializable type. It must have a counterpart registered in the server-side that implements the com.hazelcast.core.IFunction interface with the actual logic of the function to be applied.

Parameters

function – The function that alters the currently stored value.

alter_and_get(function: Any) int[source]

Alters the currently stored value by applying a function on it and gets the result.

Notes

function must be an instance of Hazelcast serializable type. It must have a counterpart registered in the server-side that implements the com.hazelcast.core.IFunction interface with the actual logic of the function to be applied.

Parameters

function – The function that alters the currently stored value.

Returns

The new value.

get_and_alter(function: Any) int[source]

Alters the currently stored value by applying a function on it and gets the old value.

Notes

function must be an instance of Hazelcast serializable type. It must have a counterpart registered in the server-side that implements the com.hazelcast.core.IFunction interface with the actual logic of the function to be applied.

Parameters

function – The function that alters the currently stored value.

Returns

The old value.

apply(function: Any) Any[source]

Applies a function on the value, the actual stored value will not change.

Notes

function must be an instance of Hazelcast serializable type. It must have a counterpart registered in the server-side that implements the com.hazelcast.core.IFunction interface with the actual logic of the function to be applied.

Parameters

function – The function applied to the currently stored value.

Returns

The result of the function application.

destroy() None[source]

Destroys this proxy.

blocking() BlockingAtomicLong[source]

Returns a version of this proxy with only blocking method calls.