AtomicLong

class AtomicLong(context, group_id, service_name, proxy_name, object_name)

Bases: hazelcast.proxy.cp.BaseCPProxy

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)

Atomically adds the given value to the current value.

Parameters

delta (int) – The value to add to the current value.

Returns

The updated value, the given value added

to the current value

Return type

hazelcast.future.Future[int]

compare_and_set(expect, update)

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

Parameters
  • expect (int) – The expected value.

  • update (int) – The new value.

Returns

True if successful; or False if

the actual value was not equal to the expected value.

Return type

hazelcast.future.Future[bool]

decrement_and_get()

Atomically decrements the current value by one.

Returns

The updated value, the current value

decremented by one.

Return type

hazelcast.future.Future[int]

get_and_decrement()

Atomically decrements the current value by one.

Returns

The old value.

Return type

hazelcast.future.Future[int]

get()

Gets the current value.

Returns

The current value.

Return type

hazelcast.future.Future[int]

get_and_add(delta)

Atomically adds the given value to the current value.

Parameters

delta (int) – The value to add to the current value.

Returns

The old value before the add.

Return type

hazelcast.future.Future[int]

get_and_set(new_value)

Atomically sets the given value and returns the old value.

Parameters

new_value (int) – The new value.

Returns

The old value.

Return type

hazelcast.future.Future[int]

increment_and_get()

Atomically increments the current value by one.

Returns

The updated value, the current value

incremented by one.

Return type

hazelcast.future.Future[int]

get_and_increment()

Atomically increments the current value by one.

Returns

The old value.

Return type

hazelcast.future.Future[int]

set(new_value)

Atomically sets the given value.

Parameters

new_value (int) – The new value

Returns

Return type

hazelcast.future.Future[None]

alter(function)

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

Notes

function must be an instance of IdentifiedDataSerializable or Portable that has a counterpart that implements the com.hazelcast.core.IFunction interface registered on the server-side with the actual implementation of the function to be applied.

Parameters

function (hazelcast.serialization.api.Portable or hazelcast.serialization.api.IdentifiedDataSerializable) – The function that alters the currently stored value.

Returns

Return type

hazelcast.future.Future[None]

alter_and_get(function)

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

Notes

function must be an instance of IdentifiedDataSerializable or Portable that has a counterpart that implements the com.hazelcast.core.IFunction interface registered on the server-side with the actual implementation of the function to be applied.

Parameters

function (hazelcast.serialization.api.Portable or hazelcast.serialization.api.IdentifiedDataSerializable) – The function that alters the currently stored value.

Returns

The new value.

Return type

hazelcast.future.Future[int]

get_and_alter(function)

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

Notes

function must be an instance of IdentifiedDataSerializable or Portable that has a counterpart that implements the com.hazelcast.core.IFunction interface registered on the server-side with the actual implementation of the function to be applied.

Parameters

function (hazelcast.serialization.api.Portable or hazelcast.serialization.api.IdentifiedDataSerializable) – The function that alters the currently stored value.

Returns

The old value.

Return type

hazelcast.future.Future[int]

apply(function)

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

Notes

function must be an instance of IdentifiedDataSerializable or Portable that has a counterpart that implements the com.hazelcast.core.IFunction interface registered on the server-side with the actual implementation of the function to be applied.

Parameters

function (hazelcast.serialization.api.Portable or hazelcast.serialization.api.IdentifiedDataSerializable) – The function applied to the currently stored value.

Returns

The result of the function application.

Return type

hazelcast.future.Future[any]