MultiMap

class MultiMap(client, service_name, name)

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 events include an old value or not (optional).
  • key – (object), key for filtering the events (optional).
  • added_func – Function to be called when an entry is added to map (optional).
  • removed_func – Function to be called when an entry is removed_func from map (optional).
  • clear_all_func – Function to be called when entries are cleared from map (optional).
Returns:

(str), a registration id which is used as a key to remove the listener.

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 – (object), the specified key.
Returns:(bool), true if this multimap contains an entry for the specified key.
contains_value(value)

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

Parameters:value – (object), the specified value.
Returns:(bool), true if this multimap contains an entry for the specified value.
contains_entry(key, value)

Returns whether the multimap contains an entry with the value.

Parameters:
  • key – (object), the specified key.
  • value – (object), the specified value.
Returns:

(bool), true if this multimap contains the key-value tuple.

clear()

Clears the multimap. Removes all key-value tuples.

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:(Sequence), the list of key-value tuples in the multimap.
get(key)

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

Warning: This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equals 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 – (object), the specified key.
Returns:(Sequence), the list of the values associated with the specified key.
is_locked(key)

Checks the lock for the specified key. If the lock is acquired, returns true. Otherwise, returns false.

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 – (object), the key that is checked for lock.
Returns:(bool), true if lock is acquired, false otherwise.
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 – (object), the key to lock.
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:(Sequence), a list of the clone of the keys.
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 – (object), the key to lock.
  • lease_time – (int), time in seconds to wait before releasing the lock (optional).
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 – (object), the key of the entry to remove.
  • value – (object), the value of the entry to remove.
Returns:

(bool), true if the size of the multimap changed after the remove operation, false otherwise.

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-2: 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 – (object), the key of the entries to remove.
Returns:(Sequence), the collection of removed values associated with the given key.
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 – (object), the key to be stored.
  • value – (object), the value to be stored.
Returns:

(bool), true if size of the multimap is increased, false if the multimap already contains the key-value

tuple.

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:(bool), true if registration is removed, false otherwise.
size()

Returns the number of entries in this multimap.

Returns:(int), number of entries in this multimap.
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 – (object), the key whose values count is to be returned.
Returns:(int), the number of values that match the given key in the multimap.
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:(Sequence), the list of values in the multimap.
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 – (object), key to lock in this map.
  • lease_time – (int), time in seconds to wait before releasing the lock (optional).
  • timeout – (int), maximum time in seconds to wait for the lock (optional).
Returns:

(bool), true if the lock was acquired and otherwise, false.

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 – (object), the key to lock.