MultiMap

class MultiMap(service_name, name, context)

Bases: hazelcast.proxy.base.Proxy

A specialized map whose keys can be associated with multiple values.

add_entry_listener(include_value=False, key=None, added_func=None, removed_func=None, clear_all_func=None)

Adds an entry listener for this multimap.

The listener will be notified for all multimap add/remove/clear-all events.

Parameters
  • include_value (bool) – Whether received event should include the value or not.

  • key – Key for filtering the events.

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

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

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

Returns

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

Return type

hazelcast.future.Future[str]

contains_key(key)

Determines whether this multimap 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 multimap contains an entry for the specified key,

False otherwise.

Return type

hazelcast.future.Future[bool]

contains_value(value)

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

Parameters

value – The specified value.

Returns

True if this multimap contains an entry for the specified value,

False otherwise.

Return type

hazelcast.future.Future[bool]

contains_entry(key, value)

Returns whether the multimap contains an entry with the value.

Parameters
  • key – The specified key.

  • value – The specified value.

Returns

True if this multimap contains the key-value tuple, False otherwise.

Return type

hazelcast.future.Future[bool]

clear()

Clears the multimap. Removes all key-value tuples.

Returns

Return type

hazelcast.future.Future[None]

entry_set()

Returns the list of key-value tuples in the multimap.

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 multimap.

Return type

hazelcast.future.Future[list]

get(key)

Returns the list of values associated with the key. None if this map does not contain this key.

Warning

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

Warning-2:

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

Parameters

key – The specified key.

Returns

The list of the values associated with the specified key.

Return type

hazelcast.future.Future[list]

is_locked(key)

Checks the lock for the specified 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 key that is checked for lock.

Returns

True if lock is acquired, False otherwise.

Return type

hazelcast.future.Future[bool]

force_unlock(key)

Releases the lock for the specified key regardless of the lock owner.

It always successfully unlocks the key, never blocks, and returns immediately.

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 key to lock.

Returns

Return type

hazelcast.future.Future[None]

key_set()

Returns the list of keys in the multimap.

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.

Return type

hazelcast.future.Future[list]

lock(key, lease_time=- 1)

Acquires the lock for the specified key infinitely or for the specified lease time if provided.

If the lock is not available, the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.

Scope of the lock is this map only. Acquired lock is only for the key in this map.

Locks are re-entrant; so, if the key is locked N times, it should be unlocked N times before another thread can acquire it.

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 key to lock.

  • lease_time (int) – Time in seconds to wait before releasing the lock.

Returns

Return type

hazelcast.future.Future[None]

remove(key, value)

Removes the given key-value tuple from the multimap.

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 key of the entry to remove.

  • value – The value of the entry to remove.

Returns

True if the size of the multimap changed after the remove operation,

False otherwise.

Return type

hazelcast.future.Future[bool]

remove_all(key)

Removes all the entries with the given key and returns the value list associated with 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.

Warning

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

Parameters

key – The key of the entries to remove.

Returns

The collection of removed values associated with the given key.

Return type

hazelcast.future.Future[list]

put(key, value)

Stores a key-value tuple in the multimap.

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 key to be stored.

  • value – The value to be stored.

Returns

True if size of the multimap is increased,

False if the multimap already contains the key-value tuple.

Return type

hazelcast.future.Future[bool]

remove_entry_listener(registration_id)

Removes the specified entry listener.

Returns silently if there is no such listener added before.

Parameters

registration_id (str) – Id of registered listener.

Returns

True if registration is removed, False otherwise.

Return type

hazelcast.future.Future[bool]

size()

Returns the number of entries in this multimap.

Returns

Number of entries in this multimap.

Return type

hazelcast.future.Future[int]

value_count(key)

Returns the number of values that match the given key in the multimap.

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 key whose values count is to be returned.

Returns

The number of values that match the given key in the multimap.

Return type

hazelcast.future.Future[int]

values()

Returns the list of values in the multimap.

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 multimap.

Return type

hazelcast.future.Future[list]

try_lock(key, lease_time=- 1, timeout=- 1)

Tries to acquire the lock for the specified key.

When the lock is not available:

  • If timeout is not provided, the current thread doesn’t wait and returns false immediately.

  • If a timeout is provided, the current thread becomes disabled for thread scheduling purposes and lies dormant until one of the followings happens:

    • the lock is acquired by the current thread, or

    • the specified waiting time elapses.

If lease_time is provided, lock will be released after this time elapses.

Parameters
  • key – Key to lock in this map.

  • lease_time (int) – Time in seconds to wait before releasing the lock.

  • timeout (int) – Maximum time in seconds to wait for the lock.

Returns

True if the lock was acquired, False otherwise.

Return type

hazelcast.future.Future[bool]

unlock(key)

Releases the lock for the specified key. It never blocks and returns immediately.

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 key to lock.

Returns

Return type

hazelcast.future.Future[None]