ReplicatedMap

class ReplicatedMap(service_name, name, context)[source]

Bases: Proxy[BlockingReplicatedMap], Generic[KeyType, ValueType]

A ReplicatedMap is a map-like data structure with weak consistency and values locally stored on every node of the cluster.

Whenever a value is written asynchronously, the new value will be internally distributed to all existing cluster members, and eventually every node will have the new value.

When a new node joins the cluster, the new node initially will request existing values from older nodes and replicate them locally.

add_entry_listener(key: Optional[KeyType] = None, predicate: Optional[Predicate] = None, added_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None, removed_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None, updated_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None, evicted_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None, clear_all_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None) Future[str][source]

Adds a continuous entry listener for this map.

Listener will get notified for map events filtered with given parameters.

Parameters
  • key – Key for filtering the events.

  • predicate – Predicate for filtering the events.

  • added_func – Function to be called when an entry is added to map.

  • removed_func – Function to be called when an entry is removed from map.

  • updated_func – Function to be called when an entry is updated.

  • evicted_func – Function to be called when an entry is evicted from map.

  • clear_all_func – Function to be called when entries are cleared from map.

Returns

A registration id which is used as a key to remove the listener.

clear() Future[None][source]

Wipes data out of the replicated map.

contains_key(key: KeyType) Future[bool][source]

Determines whether this map contains an entry with the key.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters

key – The specified key.

Returns

True if this map contains an entry for the specified key, False otherwise.

contains_value(value: ValueType) Future[bool][source]

Determines whether this map contains one or more keys for the specified value.

Parameters

value – The specified value.

Returns

True if this map contains an entry for the specified value, False otherwise.

entry_set() Future[List[Tuple[KeyType, ValueType]]][source]

Returns a List clone of the mappings contained in this map.

Warning

The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.

Returns

The list of key-value tuples in the map.

get(key: KeyType) Future[Optional[ValueType]][source]
Returns the value for the specified key, or None if this map

does not contain this key.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters

key – The specified key.

Returns

The value associated with the specified key.

is_empty() Future[bool][source]

Returns True if this map contains no key-value mappings.

Returns

True if this map contains no key-value mappings.

key_set() Future[List[KeyType]][source]

Returns the list of keys in the ReplicatedMap.

Warning

The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.

Returns

A list of the clone of the keys.

put(key: KeyType, value: ValueType, ttl: float = 0) Future[Optional[ValueType]][source]

Associates the specified value with the specified key in this map.

If the map previously contained a mapping for the key, the old value is replaced by the specified value. If ttl is provided, entry will expire and get evicted after the ttl.

Parameters
  • key – The specified key.

  • value – The value to associate with the key.

  • ttl – Maximum time in seconds for this entry to stay, if not provided, the value configured on server side configuration will be used.

Returns

Previous value associated with key or None if there was no mapping for key.

put_all(source: Dict[KeyType, ValueType]) Future[None][source]

Copies all the mappings from the specified map to this map.

No atomicity guarantees are given. In the case of a failure, some key-value tuples may get written, while others are not.

Parameters

source – Map which includes mappings to be stored in this map.

remove(key: KeyType) Future[Optional[ValueType]][source]

Removes the mapping for a key from this map if it is present.

The map will not contain a mapping for the specified key once the call returns.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters

key – Key of the mapping to be deleted.

Returns

The previous value associated with key, or None if there was no mapping for key.

remove_entry_listener(registration_id: str) Future[bool][source]

Removes the specified entry listener.

Returns silently if there is no such listener added before.

Parameters

registration_id – Id of registered listener.

Returns

True if registration is removed, False otherwise.

size() Future[int][source]

Returns the number of entries in this multimap.

Returns

Number of entries in this multimap.

values() Future[List[ValueType]][source]

Returns the list of values in the map.

Warning

The returned list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.

Returns

The list of values in the map.

blocking() BlockingReplicatedMap[KeyType, ValueType][source]

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

class BlockingReplicatedMap(wrapped: ReplicatedMap[KeyType, ValueType])[source]

Bases: ReplicatedMap[KeyType, ValueType]

name
service_name
add_entry_listener(key: Optional[KeyType] = None, predicate: Optional[Predicate] = None, added_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None, removed_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None, updated_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None, evicted_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None, clear_all_func: Optional[Callable[[EntryEvent[KeyType, ValueType]], None]] = None) str[source]

Adds a continuous entry listener for this map.

Listener will get notified for map events filtered with given parameters.

Parameters
  • key – Key for filtering the events.

  • predicate – Predicate for filtering the events.

  • added_func – Function to be called when an entry is added to map.

  • removed_func – Function to be called when an entry is removed from map.

  • updated_func – Function to be called when an entry is updated.

  • evicted_func – Function to be called when an entry is evicted from map.

  • clear_all_func – Function to be called when entries are cleared from map.

Returns

A registration id which is used as a key to remove the listener.

clear() None[source]

Wipes data out of the replicated map.

contains_key(key: KeyType) bool[source]

Determines whether this map contains an entry with the key.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters

key – The specified key.

Returns

True if this map contains an entry for the specified key, False otherwise.

contains_value(value: ValueType) bool[source]

Determines whether this map contains one or more keys for the specified value.

Parameters

value – The specified value.

Returns

True if this map contains an entry for the specified value, False otherwise.

entry_set() List[Tuple[KeyType, ValueType]][source]

Returns a List clone of the mappings contained in this map.

Warning

The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.

Returns

The list of key-value tuples in the map.

get(key: KeyType) Optional[ValueType][source]
Returns the value for the specified key, or None if this map

does not contain this key.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters

key – The specified key.

Returns

The value associated with the specified key.

is_empty() bool[source]

Returns True if this map contains no key-value mappings.

Returns

True if this map contains no key-value mappings.

key_set() List[KeyType][source]

Returns the list of keys in the ReplicatedMap.

Warning

The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.

Returns

A list of the clone of the keys.

put(key: KeyType, value: ValueType, ttl: float = 0) Optional[ValueType][source]

Associates the specified value with the specified key in this map.

If the map previously contained a mapping for the key, the old value is replaced by the specified value. If ttl is provided, entry will expire and get evicted after the ttl.

Parameters
  • key – The specified key.

  • value – The value to associate with the key.

  • ttl – Maximum time in seconds for this entry to stay, if not provided, the value configured on server side configuration will be used.

Returns

Previous value associated with key or None if there was no mapping for key.

put_all(source: Dict[KeyType, ValueType]) None[source]

Copies all the mappings from the specified map to this map.

No atomicity guarantees are given. In the case of a failure, some key-value tuples may get written, while others are not.

Parameters

source – Map which includes mappings to be stored in this map.

remove(key: KeyType) Optional[ValueType][source]

Removes the mapping for a key from this map if it is present.

The map will not contain a mapping for the specified key once the call returns.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters

key – Key of the mapping to be deleted.

Returns

The previous value associated with key, or None if there was no mapping for key.

remove_entry_listener(registration_id: str) bool[source]

Removes the specified entry listener.

Returns silently if there is no such listener added before.

Parameters

registration_id – Id of registered listener.

Returns

True if registration is removed, False otherwise.

size() int[source]

Returns the number of entries in this multimap.

Returns

Number of entries in this multimap.

values() List[ValueType][source]

Returns the list of values in the map.

Warning

The returned list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.

Returns

The list of values in the map.

destroy() bool[source]

Destroys this proxy.

Returns

True if this proxy is destroyed successfully, False otherwise.

blocking() BlockingReplicatedMap[KeyType, ValueType][source]

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