INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Closes the connection with given address. :param address: (:class:`~hazelcast.core.Address`), address of the connection to be closed. :param cause: (Exception), the cause for closing the connection. :return: (bool), ``true`` if the connection is closed, ``false`` otherwise.
def close_connection(self, address, cause): """ Closes the connection with given address. :param address: (:class:`~hazelcast.core.Address`), address of the connection to be closed. :param cause: (Exception), the cause for closing the connection. :return: (bool), ``true`` if the connection is closed, ``false`` otherwise. """ try: connection = self.connections[address] connection.close(cause) except KeyError: self.logger.warning("No connection with %s was found to close.", address, extra=self._logger_extras) return False
Starts sending periodic HeartBeat operations.
def start(self): """ Starts sending periodic HeartBeat operations. """ def _heartbeat(): if not self._client.lifecycle.is_live: return self._heartbeat() self._heartbeat_timer = self._client.reactor.add_timer(self._heartbeat_interval, _heartbeat) self._heartbeat_timer = self._client.reactor.add_timer(self._heartbeat_interval, _heartbeat)
Sends a message to this connection. :param message: (Message), message to be sent to this connection.
def send_message(self, message): """ Sends a message to this connection. :param message: (Message), message to be sent to this connection. """ if not self.live(): raise IOError("Connection is not live.") message.add_flag(BEGIN_END_FLAG) self.write(message.buffer)
Receives a message from this connection.
def receive_message(self): """ Receives a message from this connection. """ # split frames while len(self._read_buffer) >= INT_SIZE_IN_BYTES: frame_length = struct.unpack_from(FMT_LE_INT, self._read_buffer, 0)[0] if frame_length > len(self._read_buffer): return message = ClientMessage(memoryview(self._read_buffer)[:frame_length]) self._read_buffer = self._read_buffer[frame_length:] self._builder.on_message(message)
Transactional implementation of :func:`Set.add(item) <hazelcast.proxy.set.Set.add>` :param item: (object), the new item to be added. :return: (bool), ``true`` if item is added successfully, ``false`` otherwise.
def add(self, item): """ Transactional implementation of :func:`Set.add(item) <hazelcast.proxy.set.Set.add>` :param item: (object), the new item to be added. :return: (bool), ``true`` if item is added successfully, ``false`` otherwise. """ check_not_none(item, "item can't be none") return self._encode_invoke(transactional_set_add_codec, item=self._to_data(item))
Transactional implementation of :func:`Set.remove(item) <hazelcast.proxy.set.Set.remove>` :param item: (object), the specified item to be deleted. :return: (bool), ``true`` if item is remove successfully, ``false`` otherwise.
def remove(self, item): """ Transactional implementation of :func:`Set.remove(item) <hazelcast.proxy.set.Set.remove>` :param item: (object), the specified item to be deleted. :return: (bool), ``true`` if item is remove successfully, ``false`` otherwise. """ check_not_none(item, "item can't be none") return self._encode_invoke(transactional_set_remove_codec, item=self._to_data(item))
Calculates the request payload size
def calculate_size(name, attribute, ordered): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(name) data_size += calculate_size_str(attribute) data_size += BOOLEAN_SIZE_IN_BYTES return data_size
Encode request into client_message
def encode_request(name, attribute, ordered): """ Encode request into client_message""" client_message = ClientMessage(payload_size=calculate_size(name, attribute, ordered)) client_message.set_message_type(REQUEST_TYPE) client_message.set_retryable(RETRYABLE) client_message.append_str(name) client_message.append_str(attribute) client_message.append_bool(ordered) client_message.update_frame_length() return client_message
Calculates the request payload size
def calculate_size(name, sequence): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(name) data_size += LONG_SIZE_IN_BYTES return data_size
Calculates the request payload size
def calculate_size(name, count): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(name) data_size += INT_SIZE_IN_BYTES return data_size
Try to initialize this Semaphore instance with the given permit count. :param permits: (int), the given permit count. :return: (bool), ``true`` if initialization success.
def init(self, permits): """ Try to initialize this Semaphore instance with the given permit count. :param permits: (int), the given permit count. :return: (bool), ``true`` if initialization success. """ check_not_negative(permits, "Permits cannot be negative!") return self._encode_invoke(semaphore_init_codec, permits=permits)
Acquires one or specified amount of permits if available, and returns immediately, reducing the number of available permits by one or given amount. If insufficient permits are available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of following happens: * some other thread invokes one of the release methods for this semaphore, the current thread is next to be assigned permits and the number of available permits satisfies this request, * this Semaphore instance is destroyed, or * some other thread interrupts the current thread. :param permits: (int), the number of permits to acquire (optional).
def acquire(self, permits=1): """ Acquires one or specified amount of permits if available, and returns immediately, reducing the number of available permits by one or given amount. If insufficient permits are available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of following happens: * some other thread invokes one of the release methods for this semaphore, the current thread is next to be assigned permits and the number of available permits satisfies this request, * this Semaphore instance is destroyed, or * some other thread interrupts the current thread. :param permits: (int), the number of permits to acquire (optional). """ check_not_negative(permits, "Permits cannot be negative!") return self._encode_invoke(semaphore_acquire_codec, permits=permits)
Shrinks the number of available permits by the indicated reduction. This method differs from acquire in that it does not block waiting for permits to become available. :param reduction: (int), the number of permits to remove.
def reduce_permits(self, reduction): """ Shrinks the number of available permits by the indicated reduction. This method differs from acquire in that it does not block waiting for permits to become available. :param reduction: (int), the number of permits to remove. """ check_not_negative(reduction, "Reduction cannot be negative!") return self._encode_invoke(semaphore_reduce_permits_codec, reduction=reduction)
Releases one or given number of permits, increasing the number of available permits by one or that amount. There is no requirement that a thread that releases a permit must have acquired that permit by calling one of the acquire methods. Correct usage of a semaphore is established by programming convention in the application. :param permits: (int), the number of permits to release (optional).
def release(self, permits=1): """ Releases one or given number of permits, increasing the number of available permits by one or that amount. There is no requirement that a thread that releases a permit must have acquired that permit by calling one of the acquire methods. Correct usage of a semaphore is established by programming convention in the application. :param permits: (int), the number of permits to release (optional). """ check_not_negative(permits, "Permits cannot be negative!") return self._encode_invoke(semaphore_release_codec, permits=permits)
Tries to acquire one or the given number of permits, if they are available, and returns immediately, with the value ``true``, reducing the number of available permits by the given amount. If there are insufficient permits and a timeout is provided, the current thread becomes disabled for thread scheduling purposes and lies dormant until one of following happens: * some other thread invokes the release() method for this semaphore and the current thread is next to be assigned a permit, or * some other thread interrupts the current thread, or * the specified waiting time elapses. If there are insufficient permits and no timeout is provided, this method will return immediately with the value ``false`` and the number of available permits is unchanged. :param permits: (int), the number of permits to acquire (optional). :param timeout: (long), the maximum time in seconds to wait for the permit(s) (optional). :return: (bool), ``true`` if desired amount of permits was acquired, ``false`` otherwise.
def try_acquire(self, permits=1, timeout=0): """ Tries to acquire one or the given number of permits, if they are available, and returns immediately, with the value ``true``, reducing the number of available permits by the given amount. If there are insufficient permits and a timeout is provided, the current thread becomes disabled for thread scheduling purposes and lies dormant until one of following happens: * some other thread invokes the release() method for this semaphore and the current thread is next to be assigned a permit, or * some other thread interrupts the current thread, or * the specified waiting time elapses. If there are insufficient permits and no timeout is provided, this method will return immediately with the value ``false`` and the number of available permits is unchanged. :param permits: (int), the number of permits to acquire (optional). :param timeout: (long), the maximum time in seconds to wait for the permit(s) (optional). :return: (bool), ``true`` if desired amount of permits was acquired, ``false`` otherwise. """ check_not_negative(permits, "Permits cannot be negative!") return self._encode_invoke(semaphore_try_acquire_codec, permits=permits, timeout=to_millis(timeout))
Event handler
def handle(client_message, handle_event_topic=None, to_object=None): """ Event handler """ message_type = client_message.get_message_type() if message_type == EVENT_TOPIC and handle_event_topic is not None: item = client_message.read_data() publish_time = client_message.read_long() uuid = client_message.read_str() handle_event_topic(item=item, publish_time=publish_time, uuid=uuid)
Calculates the request payload size
def calculate_size(name, entry_processor, keys): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(name) data_size += calculate_size_data(entry_processor) data_size += INT_SIZE_IN_BYTES for keys_item in keys: data_size += calculate_size_data(keys_item) return data_size
Encode request into client_message
def encode_request(name, entry_processor, keys): """ Encode request into client_message""" client_message = ClientMessage(payload_size=calculate_size(name, entry_processor, keys)) client_message.set_message_type(REQUEST_TYPE) client_message.set_retryable(RETRYABLE) client_message.append_str(name) client_message.append_data(entry_processor) client_message.append_int(len(keys)) for keys_item in keys: client_message.append_data(keys_item) client_message.update_frame_length() return client_message
Calculates the request payload size
def calculate_size(username, password, uuid, owner_uuid, is_owner_connection, client_type, serialization_version, client_hazelcast_version): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(username) data_size += calculate_size_str(password) data_size += BOOLEAN_SIZE_IN_BYTES if uuid is not None: data_size += calculate_size_str(uuid) data_size += BOOLEAN_SIZE_IN_BYTES if owner_uuid is not None: data_size += calculate_size_str(owner_uuid) data_size += BOOLEAN_SIZE_IN_BYTES data_size += calculate_size_str(client_type) data_size += BYTE_SIZE_IN_BYTES data_size += calculate_size_str(client_hazelcast_version) return data_size
Encode request into client_message
def encode_request(username, password, uuid, owner_uuid, is_owner_connection, client_type, serialization_version, client_hazelcast_version): """ Encode request into client_message""" client_message = ClientMessage(payload_size=calculate_size(username, password, uuid, owner_uuid, is_owner_connection, client_type, serialization_version, client_hazelcast_version)) client_message.set_message_type(REQUEST_TYPE) client_message.set_retryable(RETRYABLE) client_message.append_str(username) client_message.append_str(password) client_message.append_bool(uuid is None) if uuid is not None: client_message.append_str(uuid) client_message.append_bool(owner_uuid is None) if owner_uuid is not None: client_message.append_str(owner_uuid) client_message.append_bool(is_owner_connection) client_message.append_str(client_type) client_message.append_byte(serialization_version) client_message.append_str(client_hazelcast_version) client_message.update_frame_length() return client_message
Decode response from client message
def decode_response(client_message, to_object=None): """ Decode response from client message""" parameters = dict(status=None, address=None, uuid=None, owner_uuid=None, serialization_version=None, server_hazelcast_version=None, client_unregistered_members=None) parameters['status'] = client_message.read_byte() if not client_message.read_bool(): parameters['address'] = AddressCodec.decode(client_message, to_object) if not client_message.read_bool(): parameters['uuid'] = client_message.read_str() if not client_message.read_bool(): parameters['owner_uuid'] = client_message.read_str() parameters['serialization_version'] = client_message.read_byte() if client_message.is_complete(): return parameters parameters['server_hazelcast_version'] = client_message.read_str() if not client_message.read_bool(): client_unregistered_members_size = client_message.read_int() client_unregistered_members = [] for _ in range(0, client_unregistered_members_size): client_unregistered_members_item = MemberCodec.decode(client_message, to_object) client_unregistered_members.append(client_unregistered_members_item) parameters['client_unregistered_members'] = ImmutableLazyDataList(client_unregistered_members, to_object) return parameters
Helper method for adding membership listeners :param member_added: (Function), Function to be called when a member is added, in the form of f(member) (optional). :param member_removed: (Function), Function to be called when a member is removed, in the form of f(member) (optional). :param fire_for_existing: if True, already existing members will fire member_added event (optional). :return: `self` for cascading configuration
def add_membership_listener(self, member_added=None, member_removed=None, fire_for_existing=False): """ Helper method for adding membership listeners :param member_added: (Function), Function to be called when a member is added, in the form of f(member) (optional). :param member_removed: (Function), Function to be called when a member is removed, in the form of f(member) (optional). :param fire_for_existing: if True, already existing members will fire member_added event (optional). :return: `self` for cascading configuration """ self.membership_listeners.append((member_added, member_removed, fire_for_existing)) return self
Assign a serializer for the type. :param _type: (Type), the target type of the serializer :param serializer: (Serializer), Custom Serializer constructor function
def set_custom_serializer(self, _type, serializer): """ Assign a serializer for the type. :param _type: (Type), the target type of the serializer :param serializer: (Serializer), Custom Serializer constructor function """ validate_type(_type) validate_serializer(serializer, StreamSerializer) self._custom_serializers[_type] = serializer
Gets the value of the given property. First checks client config properties, then environment variables and lastly fall backs to the default value of the property. :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from :return: Value of the given property
def get(self, property): """ Gets the value of the given property. First checks client config properties, then environment variables and lastly fall backs to the default value of the property. :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from :return: Value of the given property """ return self._properties.get(property.name) or os.getenv(property.name) or property.default_value
Gets the value of the given property as boolean. :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from :return: (bool), Value of the given property
def get_bool(self, property): """ Gets the value of the given property as boolean. :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get value from :return: (bool), Value of the given property """ value = self.get(property) if isinstance(value, bool): return value return value.lower() == "true"
Gets the value of the given property in seconds. If the value of the given property is not a number, throws TypeError. :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from :return: (float), Value of the given property in seconds
def get_seconds(self, property): """ Gets the value of the given property in seconds. If the value of the given property is not a number, throws TypeError. :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from :return: (float), Value of the given property in seconds """ return TimeUnit.to_seconds(self.get(property), property.time_unit)
Gets the value of the given property in seconds. If the value of the given property is not a number, throws TypeError. If the value of the given property in seconds is not positive, tries to return the default value in seconds. :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from :return: (float), Value of the given property in seconds if it is positive. Else, value of the default value of given property in seconds.
def get_seconds_positive_or_default(self, property): """ Gets the value of the given property in seconds. If the value of the given property is not a number, throws TypeError. If the value of the given property in seconds is not positive, tries to return the default value in seconds. :param property: (:class:`~hazelcast.config.ClientProperty`), Property to get seconds from :return: (float), Value of the given property in seconds if it is positive. Else, value of the default value of given property in seconds. """ seconds = self.get_seconds(property) return seconds if seconds > 0 else TimeUnit.to_seconds(property.default_value, property.time_unit)
Calculates the request payload size
def calculate_size(credentials, uuid, owner_uuid, is_owner_connection, client_type, serialization_version, client_hazelcast_version): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_data(credentials) data_size += BOOLEAN_SIZE_IN_BYTES if uuid is not None: data_size += calculate_size_str(uuid) data_size += BOOLEAN_SIZE_IN_BYTES if owner_uuid is not None: data_size += calculate_size_str(owner_uuid) data_size += BOOLEAN_SIZE_IN_BYTES data_size += calculate_size_str(client_type) data_size += BYTE_SIZE_IN_BYTES data_size += calculate_size_str(client_hazelcast_version) return data_size
Calculates the request payload size
def calculate_size(name, replica_timestamps, target_replica): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(name) data_size += INT_SIZE_IN_BYTES for replica_timestamps_item in replica_timestamps: key = replica_timestamps_item[0] val = replica_timestamps_item[1] data_size += calculate_size_str(key) data_size += LONG_SIZE_IN_BYTES data_size += calculate_size_address(target_replica) return data_size
Encode request into client_message
def encode_request(name, replica_timestamps, target_replica): """ Encode request into client_message""" client_message = ClientMessage(payload_size=calculate_size(name, replica_timestamps, target_replica)) client_message.set_message_type(REQUEST_TYPE) client_message.set_retryable(RETRYABLE) client_message.append_str(name) client_message.append_int(len(replica_timestamps)) for replica_timestamps_item in replica_timestamps: key = replica_timestamps_item[0] val = replica_timestamps_item[1] client_message.append_str(key) client_message.append_long(val) AddressCodec.encode(client_message, target_replica) client_message.update_frame_length() return client_message
Decode response from client message
def decode_response(client_message, to_object=None): """ Decode response from client message""" parameters = dict(value=None, replica_timestamps=None, replica_count=None) parameters['value'] = client_message.read_long() replica_timestamps_size = client_message.read_int() replica_timestamps = [] for _ in range(0, replica_timestamps_size): replica_timestamps_item = (client_message.read_str(), client_message.read_long()) replica_timestamps.append(replica_timestamps_item) parameters['replica_timestamps'] = ImmutableLazyDataList(replica_timestamps, to_object) parameters['replica_count'] = client_message.read_int() return parameters
Calculates the request payload size
def calculate_size(name, value): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(name) data_size += calculate_size_data(value) return data_size
Adds a continuous entry listener for this map. Listener will get notified for map events filtered with given parameters. :param key: (object), key for filtering the events (optional). :param predicate: (Predicate), predicate for filtering the events (optional). :param added_func: Function to be called when an entry is added to map (optional). :param removed_func: Function to be called when an entry is removed from map (optional). :param updated_func: Function to be called when an entry is updated (optional). :param evicted_func: Function to be called when an entry is evicted from map (optional). :param clear_all_func: Function to be called when entries are cleared from map (optional). :return: (str), a registration id which is used as a key to remove the listener. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
def add_entry_listener(self, key=None, predicate=None, added_func=None, removed_func=None, updated_func=None, evicted_func=None, clear_all_func=None): """ Adds a continuous entry listener for this map. Listener will get notified for map events filtered with given parameters. :param key: (object), key for filtering the events (optional). :param predicate: (Predicate), predicate for filtering the events (optional). :param added_func: Function to be called when an entry is added to map (optional). :param removed_func: Function to be called when an entry is removed from map (optional). :param updated_func: Function to be called when an entry is updated (optional). :param evicted_func: Function to be called when an entry is evicted from map (optional). :param clear_all_func: Function to be called when entries are cleared from map (optional). :return: (str), a registration id which is used as a key to remove the listener. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. """ if key and predicate: key_data = self._to_data(key) predicate_data = self._to_data(predicate) request = replicated_map_add_entry_listener_to_key_with_predicate_codec.encode_request(self.name, key_data, predicate_data, False) elif key and not predicate: key_data = self._to_data(key) request = replicated_map_add_entry_listener_to_key_codec.encode_request(self.name, key_data, False) elif not key and predicate: predicate = self._to_data(predicate) request = replicated_map_add_entry_listener_with_predicate_codec.encode_request(self.name, predicate, False) else: request = replicated_map_add_entry_listener_codec.encode_request(self.name, False) def handle_event_entry(**_kwargs): event = EntryEvent(self._to_object, **_kwargs) if event.event_type == EntryEventType.added and added_func: added_func(event) elif event.event_type == EntryEventType.removed and removed_func: removed_func(event) elif event.event_type == EntryEventType.updated and updated_func: updated_func(event) elif event.event_type == EntryEventType.evicted and evicted_func: evicted_func(event) elif event.event_type == EntryEventType.clear_all and clear_all_func: clear_all_func(event) return self._start_listening(request, lambda m: replicated_map_add_entry_listener_codec.handle(m, handle_event_entry), lambda r: replicated_map_add_entry_listener_codec.decode_response(r)[ 'response'])
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.** :param key: (object), the specified key. :return: (bool), ``true`` if this map contains an entry for the specified key.
def contains_key(self, key): """ 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.** :param key: (object), the specified key. :return: (bool), ``true`` if this map contains an entry for the specified key. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._encode_invoke_on_key(replicated_map_contains_key_codec, key_data, key=key_data)
Determines whether this map contains one or more keys for the specified value. :param value: (object), the specified value. :return: (bool), ``true`` if this map contains an entry for the specified value.
def contains_value(self, value): """ Determines whether this map contains one or more keys for the specified value. :param value: (object), the specified value. :return: (bool), ``true`` if this map contains an entry for the specified value. """ check_not_none(value, "value can't be None") return self._encode_invoke_on_target_partition(replicated_map_contains_value_codec, value=self._to_data(value))
Returns the value for the specified key, or 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.** :param key: (object), the specified key. :return: (Sequence), the list of the values associated with the specified key.
def get(self, key): """ Returns the value for the specified key, or 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.** :param key: (object), the specified key. :return: (Sequence), the list of the values associated with the specified key. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._encode_invoke_on_key(replicated_map_get_codec, key_data, key=key_data)
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. :param key: (object), the specified key. :param value: (object), the value to associate with the key. :param ttl: (int), maximum time in seconds for this entry to stay, if not provided, the value configured on server side configuration will be used(optional). :return: (object), previous value associated with key or None if there was no mapping for key.
def put(self, key, value, ttl=0): """ 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. :param key: (object), the specified key. :param value: (object), the value to associate with the key. :param ttl: (int), maximum time in seconds for this entry to stay, if not provided, the value configured on server side configuration will be used(optional). :return: (object), previous value associated with key or None if there was no mapping for key. """ check_not_none(key, "key can't be None") check_not_none(key, "value can't be None") key_data = self._to_data(key) value_data = self._to_data(value) return self._encode_invoke_on_key(replicated_map_put_codec, key_data, key=key_data, value=value_data, ttl=to_millis(ttl))
Copies all of the mappings from the specified map to this map. No atomicity guarantees are given. In the case of a failure, some of the key-value tuples may get written, while others are not. :param map: (dict), map which includes mappings to be stored in this map.
def put_all(self, map): """ Copies all of the mappings from the specified map to this map. No atomicity guarantees are given. In the case of a failure, some of the key-value tuples may get written, while others are not. :param map: (dict), map which includes mappings to be stored in this map. """ entries = {} for key, value in six.iteritems(map): check_not_none(key, "key can't be None") check_not_none(value, "value can't be None") entries[self._to_data(key)] = self._to_data(value) self._encode_invoke(replicated_map_put_all_codec, entries=entries)
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.** :param key: (object), key of the mapping to be deleted. :return: (object), the previous value associated with key, or None if there was no mapping for key.
def remove(self, key): """ 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.** :param key: (object), key of the mapping to be deleted. :return: (object), the previous value associated with key, or None if there was no mapping for key. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._encode_invoke_on_key(replicated_map_remove_codec, key_data, key=key_data)
Removes the specified entry listener. Returns silently if there is no such listener added before. :param registration_id: (str), id of registered listener. :return: (bool), ``true`` if registration is removed, ``false`` otherwise.
def remove_entry_listener(self, registration_id): """ Removes the specified entry listener. Returns silently if there is no such listener added before. :param registration_id: (str), id of registered listener. :return: (bool), ``true`` if registration is removed, ``false`` otherwise. """ return self._stop_listening(registration_id, lambda i: replicated_map_remove_entry_listener_codec.encode_request(self.name, i))
Calculates the request payload size
def calculate_size(name, timeout): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(name) data_size += LONG_SIZE_IN_BYTES return data_size
Starts the partition service.
def start(self): """ Starts the partition service. """ self.logger.debug("Starting partition service", extra=self._logger_extras) def partition_updater(): self._do_refresh() self.timer = self._client.reactor.add_timer(PARTITION_UPDATE_INTERVAL, partition_updater) self.timer = self._client.reactor.add_timer(PARTITION_UPDATE_INTERVAL, partition_updater)
Gets the owner of the partition if it's set. Otherwise it will trigger partition assignment. :param partition_id: (int), the partition id. :return: (:class:`~hazelcast.core.Address`), owner of partition or ``None`` if it's not set yet.
def get_partition_owner(self, partition_id): """ Gets the owner of the partition if it's set. Otherwise it will trigger partition assignment. :param partition_id: (int), the partition id. :return: (:class:`~hazelcast.core.Address`), owner of partition or ``None`` if it's not set yet. """ if partition_id not in self.partitions: self._do_refresh() return self.partitions.get(partition_id, None)
Returns the partition id for a Data key. :param key: (object), the data key. :return: (int), the partition id.
def get_partition_id(self, key): """ Returns the partition id for a Data key. :param key: (object), the data key. :return: (int), the partition id. """ data = self._client.serialization_service.to_data(key) count = self.get_partition_count() if count <= 0: return 0 return hash_to_index(data.get_partition_hash(), count)
murmur3 hash function to determine partition :param data: (byte array), input byte array :param offset: (long), offset. :param size: (long), byte length. :param seed: murmur hash seed hazelcast uses 0x01000193 :return: (int32), calculated hash value.
def murmur_hash3_x86_32(data, offset, size, seed=0x01000193): """ murmur3 hash function to determine partition :param data: (byte array), input byte array :param offset: (long), offset. :param size: (long), byte length. :param seed: murmur hash seed hazelcast uses 0x01000193 :return: (int32), calculated hash value. """ key = bytearray(data[offset: offset + size]) length = len(key) nblocks = int(length / 4) h1 = seed c1 = 0xcc9e2d51 c2 = 0x1b873593 # body for block_start in range(0, nblocks * 4, 4): # ??? big endian? k1 = key[block_start + 3] << 24 | \ key[block_start + 2] << 16 | \ key[block_start + 1] << 8 | \ key[block_start + 0] k1 = c1 * k1 & 0xFFFFFFFF k1 = (k1 << 15 | k1 >> 17) & 0xFFFFFFFF # inlined ROTL32 k1 = (c2 * k1) & 0xFFFFFFFF h1 ^= k1 h1 = (h1 << 13 | h1 >> 19) & 0xFFFFFFFF # inlined _ROTL32 h1 = (h1 * 5 + 0xe6546b64) & 0xFFFFFFFF # tail tail_index = nblocks * 4 k1 = 0 tail_size = length & 3 if tail_size >= 3: k1 ^= key[tail_index + 2] << 16 if tail_size >= 2: k1 ^= key[tail_index + 1] << 8 if tail_size >= 1: k1 ^= key[tail_index + 0] if tail_size != 0: k1 = (k1 * c1) & 0xFFFFFFFF k1 = (k1 << 15 | k1 >> 17) & 0xFFFFFFFF # _ROTL32 k1 = (k1 * c2) & 0xFFFFFFFF h1 ^= k1 result = _fmix(h1 ^ length) return -(result & 0x80000000) | (result & 0x7FFFFFFF)
Calculates the request payload size
def calculate_size(name, index, value): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(name) data_size += INT_SIZE_IN_BYTES data_size += calculate_size_data(value) return data_size
Calculates the request payload size
def calculate_size(name, index): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(name) data_size += INT_SIZE_IN_BYTES return data_size
Adds the specified item to the end of this list. :param item: (object), the specified item to be appended to this list. :return: (bool), ``true`` if item is added, ``false`` otherwise.
def add(self, item): """ Adds the specified item to the end of this list. :param item: (object), the specified item to be appended to this list. :return: (bool), ``true`` if item is added, ``false`` otherwise. """ check_not_none(item, "Value can't be None") element_data = self._to_data(item) return self._encode_invoke(list_add_codec, value=element_data)
Adds the specified item at the specific position in this list. Element in this position and following elements are shifted to the right, if any. :param index: (int), the specified index to insert the item. :param item: (object), the specified item to be inserted.
def add_at(self, index, item): """ Adds the specified item at the specific position in this list. Element in this position and following elements are shifted to the right, if any. :param index: (int), the specified index to insert the item. :param item: (object), the specified item to be inserted. """ check_not_none(item, "Value can't be None") element_data = self._to_data(item) return self._encode_invoke(list_add_with_index_codec, index=index, value=element_data)
Adds all of the items in the specified collection to the end of this list. The order of new elements is determined by the specified collection's iterator. :param items: (Collection), the specified collection which includes the elements to be added to list. :return: (bool), ``true`` if this call changed the list, ``false`` otherwise.
def add_all(self, items): """ Adds all of the items in the specified collection to the end of this list. The order of new elements is determined by the specified collection's iterator. :param items: (Collection), the specified collection which includes the elements to be added to list. :return: (bool), ``true`` if this call changed the list, ``false`` otherwise. """ check_not_none(items, "Value can't be None") data_items = [] for item in items: check_not_none(item, "Value can't be None") data_items.append(self._to_data(item)) return self._encode_invoke(list_add_all_codec, value_list=data_items)
Adds all of the elements in the specified collection into this list at the specified position. Elements in this positions and following elements are shifted to the right, if any. The order of new elements is determined by the specified collection's iterator. :param index: (int), the specified index at which the first element of specified collection is added. :param items: (Collection), the specified collection which includes the elements to be added to list. :return: (bool), ``true`` if this call changed the list, ``false`` otherwise.
def add_all_at(self, index, items): """ Adds all of the elements in the specified collection into this list at the specified position. Elements in this positions and following elements are shifted to the right, if any. The order of new elements is determined by the specified collection's iterator. :param index: (int), the specified index at which the first element of specified collection is added. :param items: (Collection), the specified collection which includes the elements to be added to list. :return: (bool), ``true`` if this call changed the list, ``false`` otherwise. """ check_not_none(items, "Value can't be None") data_items = [] for item in items: check_not_none(item, "Value can't be None") data_items.append(self._to_data(item)) return self._encode_invoke(list_add_all_with_index_codec, index=index, value_list=data_items)
Determines whether this list contains all of the items in specified collection or not. :param items: (Collection), the specified collection which includes the items to be searched. :return: (bool), ``true`` if all of the items in specified collection exist in this list, ``false`` otherwise.
def contains_all(self, items): """ Determines whether this list contains all of the items in specified collection or not. :param items: (Collection), the specified collection which includes the items to be searched. :return: (bool), ``true`` if all of the items in specified collection exist in this list, ``false`` otherwise. """ check_not_none(items, "Items can't be None") data_items = [] for item in items: check_not_none(item, "item can't be None") data_items.append(self._to_data(item)) return self._encode_invoke(list_contains_all_codec, values=data_items)
Returns the first index of specified items's occurrences in this list. If specified item is not present in this list, returns -1. :param item: (object), the specified item to be searched for. :return: (int), the first index of specified items's occurrences, -1 if item is not present in this list.
def index_of(self, item): """ Returns the first index of specified items's occurrences in this list. If specified item is not present in this list, returns -1. :param item: (object), the specified item to be searched for. :return: (int), the first index of specified items's occurrences, -1 if item is not present in this list. """ check_not_none(item, "Value can't be None") item_data = self._to_data(item) return self._encode_invoke(list_index_of_codec, value=item_data)
Returns the last index of specified items's occurrences in this list. If specified item is not present in this list, returns -1. :param item: (object), the specified item to be searched for. :return: (int), the last index of specified items's occurrences, -1 if item is not present in this list.
def last_index_of(self, item): """ Returns the last index of specified items's occurrences in this list. If specified item is not present in this list, returns -1. :param item: (object), the specified item to be searched for. :return: (int), the last index of specified items's occurrences, -1 if item is not present in this list. """ check_not_none(item, "Value can't be None") item_data = self._to_data(item) return self._encode_invoke(list_last_index_of_codec, value=item_data)
Removes the specified element's first occurrence from the list if it exists in this list. :param item: (object), the specified element. :return: (bool), ``true`` if the specified element is present in this list.
def remove(self, item): """ Removes the specified element's first occurrence from the list if it exists in this list. :param item: (object), the specified element. :return: (bool), ``true`` if the specified element is present in this list. """ check_not_none(item, "Value can't be None") item_data = self._to_data(item) return self._encode_invoke(list_remove_codec, value=item_data)
Removes all of the elements that is present in the specified collection from this list. :param items: (Collection), the specified collection. :return: (bool), ``true`` if this list changed as a result of the call.
def remove_all(self, items): """ Removes all of the elements that is present in the specified collection from this list. :param items: (Collection), the specified collection. :return: (bool), ``true`` if this list changed as a result of the call. """ check_not_none(items, "Value can't be None") data_items = [] for item in items: check_not_none(item, "Value can't be None") data_items.append(self._to_data(item)) return self._encode_invoke(list_compare_and_remove_all_codec, values=data_items)
Removes the specified item listener. Returns silently if the specified listener was not added before. :param registration_id: (str), id of the listener to be deleted. :return: (bool), ``true`` if the item listener is removed, ``false`` otherwise.
def remove_listener(self, registration_id): """ Removes the specified item listener. Returns silently if the specified listener was not added before. :param registration_id: (str), id of the listener to be deleted. :return: (bool), ``true`` if the item listener is removed, ``false`` otherwise. """ return self._stop_listening(registration_id, lambda i: list_remove_listener_codec.encode_request(self.name, i))
Retains only the items that are contained in the specified collection. It means, items which are not present in the specified collection are removed from this list. :param items: (Collection), collections which includes the elements to be retained in this list. :return: (bool), ``true`` if this list changed as a result of the call.
def retain_all(self, items): """ Retains only the items that are contained in the specified collection. It means, items which are not present in the specified collection are removed from this list. :param items: (Collection), collections which includes the elements to be retained in this list. :return: (bool), ``true`` if this list changed as a result of the call. """ check_not_none(items, "Value can't be None") data_items = [] for item in items: check_not_none(item, "Value can't be None") data_items.append(self._to_data(item)) return self._encode_invoke(list_compare_and_retain_all_codec, values=data_items)
Replaces the specified element with the element at the specified position in this list. :param index: (int), index of the item to be replaced. :param item: (object), item to be stored. :return: (object), the previous item in the specified index.
def set_at(self, index, item): """ Replaces the specified element with the element at the specified position in this list. :param index: (int), index of the item to be replaced. :param item: (object), item to be stored. :return: (object), the previous item in the specified index. """ check_not_none(item, "Value can't be None") element_data = self._to_data(item) return self._encode_invoke(list_set_codec, index=index, value=element_data)
Returns a sublist from this list, whose range is specified with from_index(inclusive) and to_index(exclusive). The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. :param from_index: (int), the start point(inclusive) of the sub_list. :param to_index: (int), th end point(exclusive) of the sub_list. :return: (Sequence), a view of the specified range within this list.
def sub_list(self, from_index, to_index): """ Returns a sublist from this list, whose range is specified with from_index(inclusive) and to_index(exclusive). The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. :param from_index: (int), the start point(inclusive) of the sub_list. :param to_index: (int), th end point(exclusive) of the sub_list. :return: (Sequence), a view of the specified range within this list. """ return self._encode_invoke(list_sub_codec, from_=from_index, to=to_index)
Adds a continuous entry listener for this map. Listener will get notified for map events filtered with given parameters. :param include_value: (bool), whether received event should include the value or not (optional). :param key: (object), key for filtering the events (optional). :param predicate: (Predicate), predicate for filtering the events (optional). :param added_func: Function to be called when an entry is added to map (optional). :param removed_func: Function to be called when an entry is removed from map (optional). :param updated_func: Function to be called when an entry is updated (optional). :param evicted_func: Function to be called when an entry is evicted from map (optional). :param evict_all_func: Function to be called when entries are evicted from map (optional). :param clear_all_func: Function to be called when entries are cleared from map (optional). :param merged_func: Function to be called when WAN replicated entry is merged_func (optional). :param expired_func: Function to be called when an entry's live time is expired (optional). :return: (str), a registration id which is used as a key to remove the listener. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
def add_entry_listener(self, include_value=False, key=None, predicate=None, added_func=None, removed_func=None, updated_func=None, evicted_func=None, evict_all_func=None, clear_all_func=None, merged_func=None, expired_func=None): """ Adds a continuous entry listener for this map. Listener will get notified for map events filtered with given parameters. :param include_value: (bool), whether received event should include the value or not (optional). :param key: (object), key for filtering the events (optional). :param predicate: (Predicate), predicate for filtering the events (optional). :param added_func: Function to be called when an entry is added to map (optional). :param removed_func: Function to be called when an entry is removed from map (optional). :param updated_func: Function to be called when an entry is updated (optional). :param evicted_func: Function to be called when an entry is evicted from map (optional). :param evict_all_func: Function to be called when entries are evicted from map (optional). :param clear_all_func: Function to be called when entries are cleared from map (optional). :param merged_func: Function to be called when WAN replicated entry is merged_func (optional). :param expired_func: Function to be called when an entry's live time is expired (optional). :return: (str), a registration id which is used as a key to remove the listener. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. """ flags = get_entry_listener_flags(added=added_func, removed=removed_func, updated=updated_func, evicted=evicted_func, evict_all=evict_all_func, clear_all=clear_all_func, merged=merged_func, expired=expired_func) if key and predicate: key_data = self._to_data(key) predicate_data = self._to_data(predicate) request = map_add_entry_listener_to_key_with_predicate_codec.encode_request(self.name, key_data, predicate_data, include_value, flags, False) elif key and not predicate: key_data = self._to_data(key) request = map_add_entry_listener_to_key_codec.encode_request(self.name, key_data, include_value, flags, False) elif not key and predicate: predicate = self._to_data(predicate) request = map_add_entry_listener_with_predicate_codec.encode_request(self.name, predicate, include_value, flags, False) else: request = map_add_entry_listener_codec.encode_request(self.name, include_value, flags, False) def handle_event_entry(**_kwargs): event = EntryEvent(self._to_object, **_kwargs) if event.event_type == EntryEventType.added: added_func(event) elif event.event_type == EntryEventType.removed: removed_func(event) elif event.event_type == EntryEventType.updated: updated_func(event) elif event.event_type == EntryEventType.evicted: evicted_func(event) elif event.event_type == EntryEventType.evict_all: evict_all_func(event) elif event.event_type == EntryEventType.clear_all: clear_all_func(event) elif event.event_type == EntryEventType.merged: merged_func(event) elif event.event_type == EntryEventType.expired: expired_func(event) return self._start_listening(request, lambda m: map_add_entry_listener_codec.handle(m, handle_event_entry), lambda r: map_add_entry_listener_codec.decode_response(r)['response'])
Adds an index to this map for the specified entries so that queries can run faster. Example: Let's say your map values are Employee objects. >>> class Employee(IdentifiedDataSerializable): >>> active = false >>> age = None >>> name = None >>> #other fields >>> >>> #methods If you query your values mostly based on age and active fields, you should consider indexing these. >>> map = self.client.get_map("employees") >>> map.add_index("age" , true) #ordered, since we have ranged queries for this field >>> map.add_index("active", false) #not ordered, because boolean field cannot have range :param attribute: (str), index attribute of the value. :param ordered: (bool), for ordering the index or not (optional).
def add_index(self, attribute, ordered=False): """ Adds an index to this map for the specified entries so that queries can run faster. Example: Let's say your map values are Employee objects. >>> class Employee(IdentifiedDataSerializable): >>> active = false >>> age = None >>> name = None >>> #other fields >>> >>> #methods If you query your values mostly based on age and active fields, you should consider indexing these. >>> map = self.client.get_map("employees") >>> map.add_index("age" , true) #ordered, since we have ranged queries for this field >>> map.add_index("active", false) #not ordered, because boolean field cannot have range :param attribute: (str), index attribute of the value. :param ordered: (bool), for ordering the index or not (optional). """ return self._encode_invoke(map_add_index_codec, attribute=attribute, ordered=ordered)
Adds an interceptor for this map. Added interceptor will intercept operations and execute user defined methods. :param interceptor: (object), interceptor for the map which includes user defined methods. :return: (str),id of registered interceptor.
def add_interceptor(self, interceptor): """ Adds an interceptor for this map. Added interceptor will intercept operations and execute user defined methods. :param interceptor: (object), interceptor for the map which includes user defined methods. :return: (str),id of registered interceptor. """ return self._encode_invoke(map_add_interceptor_codec, interceptor=self._to_data(interceptor))
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.** :param key: (object), the specified key. :return: (bool), ``true`` if this map contains an entry for the specified key.
def contains_key(self, key): """ 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.** :param key: (object), the specified key. :return: (bool), ``true`` if this map contains an entry for the specified key. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._contains_key_internal(key_data)
Determines whether this map contains one or more keys for the specified value. :param value: (object), the specified value. :return: (bool), ``true`` if this map contains an entry for the specified value.
def contains_value(self, value): """ Determines whether this map contains one or more keys for the specified value. :param value: (object), the specified value. :return: (bool), ``true`` if this map contains an entry for the specified value. """ check_not_none(value, "value can't be None") value_data = self._to_data(value) return self._encode_invoke(map_contains_value_codec, value=value_data)
Removes the mapping for a key from this map if it is present (optional operation). Unlike remove(object), this operation does not return the removed value, which avoids the serialization cost of the returned value. If the removed value will not be used, a delete operation is preferred over a remove operation for better performance. The map will not contain a mapping for the specified key once the call returns. **Warning: This method breaks the contract of EntryListener. When an entry is removed by delete(), it fires an EntryEvent with a** ``None`` **oldValue. Also, a listener with predicates will have** ``None`` **values, so only the keys can be queried via predicates.** :param key: (object), key of the mapping to be deleted.
def delete(self, key): """ Removes the mapping for a key from this map if it is present (optional operation). Unlike remove(object), this operation does not return the removed value, which avoids the serialization cost of the returned value. If the removed value will not be used, a delete operation is preferred over a remove operation for better performance. The map will not contain a mapping for the specified key once the call returns. **Warning: This method breaks the contract of EntryListener. When an entry is removed by delete(), it fires an EntryEvent with a** ``None`` **oldValue. Also, a listener with predicates will have** ``None`` **values, so only the keys can be queried via predicates.** :param key: (object), key of the mapping to be deleted. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._delete_internal(key_data)
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.** :param predicate: (Predicate), predicate for the map to filter entries (optional). :return: (Sequence), the list of key-value tuples in the map. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
def entry_set(self, predicate=None): """ 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.** :param predicate: (Predicate), predicate for the map to filter entries (optional). :return: (Sequence), the list of key-value tuples in the map. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. """ if predicate: predicate_data = self._to_data(predicate) return self._encode_invoke(map_entries_with_predicate_codec, predicate=predicate_data) else: return self._encode_invoke(map_entry_set_codec)
Evicts the specified key from this map. **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.** :param key: (object), key to evict. :return: (bool), ``true`` if the key is evicted, ``false`` otherwise.
def evict(self, key): """ Evicts the specified key from this map. **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.** :param key: (object), key to evict. :return: (bool), ``true`` if the key is evicted, ``false`` otherwise. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._evict_internal(key_data)
Applies the user defined EntryProcessor to all the entries in the map or entries in the map which satisfies the predicate if provided. Returns the results mapped by each key in the map. :param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on server side. This object must have a serializable EntryProcessor counter part registered on server side with the actual ``org.hazelcast.map.EntryProcessor`` implementation. :param predicate: (Predicate), predicate for filtering the entries (optional). :return: (Sequence), list of map entries which includes the keys and the results of the entry process. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
def execute_on_entries(self, entry_processor, predicate=None): """ Applies the user defined EntryProcessor to all the entries in the map or entries in the map which satisfies the predicate if provided. Returns the results mapped by each key in the map. :param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on server side. This object must have a serializable EntryProcessor counter part registered on server side with the actual ``org.hazelcast.map.EntryProcessor`` implementation. :param predicate: (Predicate), predicate for filtering the entries (optional). :return: (Sequence), list of map entries which includes the keys and the results of the entry process. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. """ if predicate: return self._encode_invoke(map_execute_with_predicate_codec, entry_processor=self._to_data(entry_processor), predicate=self._to_data(predicate)) return self._encode_invoke(map_execute_on_all_keys_codec, entry_processor=self._to_data(entry_processor))
Applies the user defined EntryProcessor to the entry mapped by the key. Returns the object which is the result of EntryProcessor's process method. :param key: (object), specified key for the entry to be processed. :param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on server side. This object must have a serializable EntryProcessor counter part registered on server side with the actual ``org.hazelcast.map.EntryProcessor`` implementation. :return: (object), result of entry process.
def execute_on_key(self, key, entry_processor): """ Applies the user defined EntryProcessor to the entry mapped by the key. Returns the object which is the result of EntryProcessor's process method. :param key: (object), specified key for the entry to be processed. :param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on server side. This object must have a serializable EntryProcessor counter part registered on server side with the actual ``org.hazelcast.map.EntryProcessor`` implementation. :return: (object), result of entry process. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._execute_on_key_internal(key_data, entry_processor)
Applies the user defined EntryProcessor to the entries mapped by the collection of keys. Returns the results mapped by each key in the collection. :param keys: (Collection), collection of the keys for the entries to be processed. :param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on server side. This object must have a serializable EntryProcessor counter part registered on server side with the actual ``org.hazelcast.map.EntryProcessor`` implementation. :return: (Sequence), list of map entries which includes the keys and the results of the entry process.
def execute_on_keys(self, keys, entry_processor): """ Applies the user defined EntryProcessor to the entries mapped by the collection of keys. Returns the results mapped by each key in the collection. :param keys: (Collection), collection of the keys for the entries to be processed. :param entry_processor: (object), A stateful serializable object which represents the EntryProcessor defined on server side. This object must have a serializable EntryProcessor counter part registered on server side with the actual ``org.hazelcast.map.EntryProcessor`` implementation. :return: (Sequence), list of map entries which includes the keys and the results of the entry process. """ key_list = [] for key in keys: check_not_none(key, "key can't be None") key_list.append(self._to_data(key)) if len(keys) == 0: return ImmediateFuture([]) return self._encode_invoke(map_execute_on_keys_codec, entry_processor=self._to_data(entry_processor), keys=key_list)
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.** :param key: (object), the key to lock.
def force_unlock(self, 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.** :param key: (object), the key to lock. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._encode_invoke_on_key(map_force_unlock_codec, key_data, key=key_data, reference_id=self.reference_id_generator.get_and_increment())
Returns the value for the specified key, or ``None`` if this map does not contain this key. **Warning: This method returns a clone of original value, modifying the returned value does not change the actual value in the map. One should put modified value back to make changes visible to all nodes.** >>> value = map.get(key) >>> value.update_some_property() >>> map.put(key,value) **Warning 2: 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.** :param key: (object), the specified key. :return: (object), the value for the specified key.
def get(self, key): """ Returns the value for the specified key, or ``None`` if this map does not contain this key. **Warning: This method returns a clone of original value, modifying the returned value does not change the actual value in the map. One should put modified value back to make changes visible to all nodes.** >>> value = map.get(key) >>> value.update_some_property() >>> map.put(key,value) **Warning 2: 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.** :param key: (object), the specified key. :return: (object), the value for the specified key. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._get_internal(key_data)
Returns the entries for the given keys. **Warning: The returned map is NOT backed by the original map, so changes to the original map are NOT reflected in the returned map, and vice-versa.** **Warning 2: 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.** :param keys: (Collection), keys to get. :return: (dict), dictionary of map entries.
def get_all(self, keys): """ Returns the entries for the given keys. **Warning: The returned map is NOT backed by the original map, so changes to the original map are NOT reflected in the returned map, and vice-versa.** **Warning 2: 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.** :param keys: (Collection), keys to get. :return: (dict), dictionary of map entries. """ check_not_none(keys, "keys can't be None") if not keys: return ImmediateFuture({}) partition_service = self._client.partition_service partition_to_keys = {} for key in keys: check_not_none(key, "key can't be None") key_data = self._to_data(key) partition_id = partition_service.get_partition_id(key_data) try: partition_to_keys[partition_id][key] = key_data except KeyError: partition_to_keys[partition_id] = {key: key_data} return self._get_all_internal(partition_to_keys)
Returns the EntryView for the specified key. **Warning: This method returns a clone of original mapping, modifying the returned value does not change the actual value in the map. One should put modified value back to make changes visible to all nodes.** **Warning 2: 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.** :param key: (object), the key of the entry. :return: (EntryView), EntryView of the specified key. .. seealso:: :class:`~hazelcast.core.EntryView` for more info about EntryView.
def get_entry_view(self, key): """ Returns the EntryView for the specified key. **Warning: This method returns a clone of original mapping, modifying the returned value does not change the actual value in the map. One should put modified value back to make changes visible to all nodes.** **Warning 2: 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.** :param key: (object), the key of the entry. :return: (EntryView), EntryView of the specified key. .. seealso:: :class:`~hazelcast.core.EntryView` for more info about EntryView. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._encode_invoke_on_key(map_get_entry_view_codec, key_data, key=key_data, thread_id=thread_id())
Checks the lock for the specified key. If the lock is acquired, it returns ``true``. Otherwise, it 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.** :param key: (object), the key that is checked for lock :return: (bool), ``true`` if lock is acquired, ``false`` otherwise.
def is_locked(self, key): """ Checks the lock for the specified key. If the lock is acquired, it returns ``true``. Otherwise, it 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.** :param key: (object), the key that is checked for lock :return: (bool), ``true`` if lock is acquired, ``false`` otherwise. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._encode_invoke_on_key(map_is_locked_codec, key_data, key=key_data)
Returns a List clone of the keys contained in this map or the keys of the entries filtered with the predicate if provided. **Warning: The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.** :param predicate: (Predicate), predicate to filter the entries (optional). :return: (Sequence), a list of the clone of the keys. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
def key_set(self, predicate=None): """ Returns a List clone of the keys contained in this map or the keys of the entries filtered with the predicate if provided. **Warning: The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.** :param predicate: (Predicate), predicate to filter the entries (optional). :return: (Sequence), a list of the clone of the keys. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. """ if predicate: predicate_data = self._to_data(predicate) return self._encode_invoke(map_key_set_with_predicate_codec, predicate=predicate_data) else: return self._encode_invoke(map_key_set_codec)
Loads all keys from the store at server side or loads the given keys if provided. :param keys: (Collection), keys of the entry values to load (optional). :param replace_existing_values: (bool), whether the existing values will be replaced or not with those loaded from the server side MapLoader (optional).
def load_all(self, keys=None, replace_existing_values=True): """ Loads all keys from the store at server side or loads the given keys if provided. :param keys: (Collection), keys of the entry values to load (optional). :param replace_existing_values: (bool), whether the existing values will be replaced or not with those loaded from the server side MapLoader (optional). """ if keys: key_data_list = list(map(self._to_data, keys)) return self._load_all_internal(key_data_list, replace_existing_values) else: return self._encode_invoke(map_load_all_codec, replace_existing_values=replace_existing_values)
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. You get a lock whether the value is present in the map or not. Other threads (possibly on other systems) would block on their invoke of lock() until the non-existent key is unlocked. If the lock holder introduces the key to the map, the put() operation is not blocked. If a thread not holding a lock on the non-existent key tries to introduce the key while a lock exists on the non-existent key, the put() operation blocks until it is unlocked. 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.** :param key: (object), the key to lock. :param ttl: (int), time in seconds to wait before releasing the lock (optional).
def lock(self, key, ttl=-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. You get a lock whether the value is present in the map or not. Other threads (possibly on other systems) would block on their invoke of lock() until the non-existent key is unlocked. If the lock holder introduces the key to the map, the put() operation is not blocked. If a thread not holding a lock on the non-existent key tries to introduce the key while a lock exists on the non-existent key, the put() operation blocks until it is unlocked. 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.** :param key: (object), the key to lock. :param ttl: (int), time in seconds to wait before releasing the lock (optional). """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._encode_invoke_on_key(map_lock_codec, key_data, invocation_timeout=MAX_SIZE, key=key_data, thread_id=thread_id(), ttl=to_millis(ttl), reference_id=self.reference_id_generator.get_and_increment())
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. **Warning: This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.** **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.** :param key: (object), the specified key. :param value: (object), the value to associate with the key. :param ttl: (int), maximum time in seconds for this entry to stay, if not provided, the value configured on server side configuration will be used(optional). :return: (object), previous value associated with key or ``None`` if there was no mapping for key.
def put(self, key, value, ttl=-1): """ 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. **Warning: This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.** **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.** :param key: (object), the specified key. :param value: (object), the value to associate with the key. :param ttl: (int), maximum time in seconds for this entry to stay, if not provided, the value configured on server side configuration will be used(optional). :return: (object), previous value associated with key or ``None`` if there was no mapping for key. """ check_not_none(key, "key can't be None") check_not_none(value, "value can't be None") key_data = self._to_data(key) value_data = self._to_data(value) return self._put_internal(key_data, value_data, ttl)
Copies all of the mappings from the specified map to this map. No atomicity guarantees are given. In the case of a failure, some of the key-value tuples may get written, while others are not. :param map: (dict), map which includes mappings to be stored in this map.
def put_all(self, map): """ Copies all of the mappings from the specified map to this map. No atomicity guarantees are given. In the case of a failure, some of the key-value tuples may get written, while others are not. :param map: (dict), map which includes mappings to be stored in this map. """ check_not_none(map, "map can't be None") if not map: return ImmediateFuture(None) partition_service = self._client.partition_service partition_map = {} for key, value in six.iteritems(map): check_not_none(key, "key can't be None") check_not_none(value, "value can't be None") entry = (self._to_data(key), self._to_data(value)) partition_id = partition_service.get_partition_id(entry[0]) try: partition_map[partition_id].append(entry) except KeyError: partition_map[partition_id] = [entry] futures = [] for partition_id, entry_list in six.iteritems(partition_map): future = self._encode_invoke_on_partition(map_put_all_codec, partition_id, entries=dict(entry_list)) futures.append(future) return combine_futures(*futures)
Associates the specified key with the given value if it is not already associated. If ttl is provided, entry will expire and get evicted after the ttl. This is equivalent to: >>> if not map.contains_key(key): >>> return map.put(key,value) >>> else: >>> return map.get(key) except that the action is performed atomically. **Warning: This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.** **Warning 2: 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.** :param key: (object), key of the entry. :param value: (object), value of the entry. :param ttl: (int), maximum time in seconds for this entry to stay in the map, if not provided, the value configured on server side configuration will be used (optional). :return: (object), old value of the entry.
def put_if_absent(self, key, value, ttl=-1): """ Associates the specified key with the given value if it is not already associated. If ttl is provided, entry will expire and get evicted after the ttl. This is equivalent to: >>> if not map.contains_key(key): >>> return map.put(key,value) >>> else: >>> return map.get(key) except that the action is performed atomically. **Warning: This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.** **Warning 2: 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.** :param key: (object), key of the entry. :param value: (object), value of the entry. :param ttl: (int), maximum time in seconds for this entry to stay in the map, if not provided, the value configured on server side configuration will be used (optional). :return: (object), old value of the entry. """ check_not_none(key, "key can't be None") check_not_none(value, "value can't be None") key_data = self._to_data(key) value_data = self._to_data(value) return self._put_if_absent_internal(key_data, value_data, ttl)
Same as put(TKey, TValue, Ttl), but MapStore defined at the server side will not be called. **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.** :param key: (object), key of the entry. :param value: (object), value of the entry. :param ttl: (int), maximum time in seconds for this entry to stay in the map, if not provided, the value configured on server side configuration will be used (optional).
def put_transient(self, key, value, ttl=-1): """ Same as put(TKey, TValue, Ttl), but MapStore defined at the server side will not be called. **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.** :param key: (object), key of the entry. :param value: (object), value of the entry. :param ttl: (int), maximum time in seconds for this entry to stay in the map, if not provided, the value configured on server side configuration will be used (optional). """ check_not_none(key, "key can't be None") check_not_none(value, "value can't be None") key_data = self._to_data(key) value_data = self._to_data(value) return self._put_transient_internal(key_data, value_data, ttl)
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.** :param key: (object), key of the mapping to be deleted. :return: (object), the previous value associated with key, or ``None`` if there was no mapping for key.
def remove(self, key): """ 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.** :param key: (object), key of the mapping to be deleted. :return: (object), the previous value associated with key, or ``None`` if there was no mapping for key. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._remove_internal(key_data)
Removes the entry for a key only if it is currently mapped to a given value. This is equivalent to: >>> if map.contains_key(key) and map.get(key).equals(value): >>> map.remove(key) >>> return true >>> else: >>> return false except that the action is performed atomically. **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.** :param key: (object), the specified key. :param value: (object), remove the key if it has this value. :return: (bool), ``true`` if the value was removed.
def remove_if_same(self, key, value): """ Removes the entry for a key only if it is currently mapped to a given value. This is equivalent to: >>> if map.contains_key(key) and map.get(key).equals(value): >>> map.remove(key) >>> return true >>> else: >>> return false except that the action is performed atomically. **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.** :param key: (object), the specified key. :param value: (object), remove the key if it has this value. :return: (bool), ``true`` if the value was removed. """ check_not_none(key, "key can't be None") check_not_none(value, "value can't be None") key_data = self._to_data(key) value_data = self._to_data(value) return self._remove_if_same_internal_(key_data, value_data)
Removes the specified entry listener. Returns silently if there is no such listener added before. :param registration_id: (str), id of registered listener. :return: (bool), ``true`` if registration is removed, ``false`` otherwise.
def remove_entry_listener(self, registration_id): """ Removes the specified entry listener. Returns silently if there is no such listener added before. :param registration_id: (str), id of registered listener. :return: (bool), ``true`` if registration is removed, ``false`` otherwise. """ return self._stop_listening(registration_id, lambda i: map_remove_entry_listener_codec.encode_request(self.name, i))
Replaces the entry for a key only if it is currently mapped to some value. This is equivalent to: >>> if map.contains_key(key): >>> return map.put(key,value) >>> else: >>> return None except that the action is performed atomically. **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: This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.** :param key: (object), the specified key. :param value: (object), the value to replace the previous value. :return: (object), previous value associated with key, or ``None`` if there was no mapping for key.
def replace(self, key, value): """ Replaces the entry for a key only if it is currently mapped to some value. This is equivalent to: >>> if map.contains_key(key): >>> return map.put(key,value) >>> else: >>> return None except that the action is performed atomically. **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: This method returns a clone of the previous value, not the original (identically equal) value previously put into the map.** :param key: (object), the specified key. :param value: (object), the value to replace the previous value. :return: (object), previous value associated with key, or ``None`` if there was no mapping for key. """ check_not_none(key, "key can't be None") check_not_none(value, "value can't be None") key_data = self._to_data(key) value_data = self._to_data(value) return self._replace_internal(key_data, value_data)
Replaces the entry for a key only if it is currently mapped to a given value. This is equivalent to: >>> if map.contains_key(key) and map.get(key).equals(old_value): >>> map.put(key, new_value) >>> return true >>> else: >>> return false except that the action is performed atomically. **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.** :param key: (object), the specified key. :param old_value: (object), replace the key value if it is the old value. :param new_value: (object), the new value to replace the old value. :return: (bool), ``true`` if the value was replaced.
def replace_if_same(self, key, old_value, new_value): """ Replaces the entry for a key only if it is currently mapped to a given value. This is equivalent to: >>> if map.contains_key(key) and map.get(key).equals(old_value): >>> map.put(key, new_value) >>> return true >>> else: >>> return false except that the action is performed atomically. **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.** :param key: (object), the specified key. :param old_value: (object), replace the key value if it is the old value. :param new_value: (object), the new value to replace the old value. :return: (bool), ``true`` if the value was replaced. """ check_not_none(key, "key can't be None") check_not_none(old_value, "old_value can't be None") check_not_none(new_value, "new_value can't be None") key_data = self._to_data(key) old_value_data = self._to_data(old_value) new_value_data = self._to_data(new_value) return self._replace_if_same_internal(key_data, old_value_data, new_value_data)
Puts an entry into this map. Similar to the put operation except that set doesn't return the old value, which is more efficient. If ttl is provided, entry will expire and get evicted after the ttl. **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.** :param key: (object), key of the entry. :param value: (object), value of the entry. :param ttl: (int), maximum time in seconds for this entry to stay in the map, 0 means infinite. If ttl is not provided, the value configured on server side configuration will be used (optional).
def set(self, key, value, ttl=-1): """ Puts an entry into this map. Similar to the put operation except that set doesn't return the old value, which is more efficient. If ttl is provided, entry will expire and get evicted after the ttl. **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.** :param key: (object), key of the entry. :param value: (object), value of the entry. :param ttl: (int), maximum time in seconds for this entry to stay in the map, 0 means infinite. If ttl is not provided, the value configured on server side configuration will be used (optional). """ check_not_none(key, "key can't be None") check_not_none(value, "value can't be None") key_data = self._to_data(key) value_data = self._to_data(value) return self._set_internal(key_data, value_data, ttl)
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 ttl is provided, lock will be released after this time elapses. :param key: (object), key to lock in this map. :param ttl: (int), time in seconds to wait before releasing the lock (optional). :param timeout: (int), maximum time in seconds to wait for the lock (optional). :return: (bool), ``true`` if the lock was acquired and otherwise, ``false``.
def try_lock(self, key, ttl=-1, timeout=0): """ 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 ttl is provided, lock will be released after this time elapses. :param key: (object), key to lock in this map. :param ttl: (int), time in seconds to wait before releasing the lock (optional). :param timeout: (int), maximum time in seconds to wait for the lock (optional). :return: (bool), ``true`` if the lock was acquired and otherwise, ``false``. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._encode_invoke_on_key(map_try_lock_codec, key_data, invocation_timeout=MAX_SIZE, key=key_data, thread_id=thread_id(), lease=to_millis(ttl), timeout=to_millis(timeout), reference_id=self.reference_id_generator.get_and_increment())
Tries to put the given key and value into this map and returns immediately if timeout is not provided. If timeout is provided, operation waits until it is completed or timeout is reached. :param key: (object), key of the entry. :param value: (object), value of the entry. :param timeout: (int), operation timeout in seconds (optional). :return: (bool), ``true`` if the put is successful, ``false`` otherwise.
def try_put(self, key, value, timeout=0): """ Tries to put the given key and value into this map and returns immediately if timeout is not provided. If timeout is provided, operation waits until it is completed or timeout is reached. :param key: (object), key of the entry. :param value: (object), value of the entry. :param timeout: (int), operation timeout in seconds (optional). :return: (bool), ``true`` if the put is successful, ``false`` otherwise. """ check_not_none(key, "key can't be None") check_not_none(value, "value can't be None") key_data = self._to_data(key) value_data = self._to_data(value) return self._try_put_internal(key_data, value_data, timeout)
Tries to remove the given key from this map and returns immediately if timeout is not provided. If timeout is provided, operation waits until it is completed or timeout is reached. :param key: (object), key of the entry to be deleted. :param timeout: (int), operation timeout in seconds (optional). :return: (bool), ``true`` if the remove is successful, ``false`` otherwise.
def try_remove(self, key, timeout=0): """ Tries to remove the given key from this map and returns immediately if timeout is not provided. If timeout is provided, operation waits until it is completed or timeout is reached. :param key: (object), key of the entry to be deleted. :param timeout: (int), operation timeout in seconds (optional). :return: (bool), ``true`` if the remove is successful, ``false`` otherwise. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._try_remove_internal(key_data, timeout)
Releases the lock for the specified key. It never blocks and returns immediately. If the current thread is the holder of this lock, then the hold count is decremented. If the hold count is zero, then the lock is released. :param key: (object), the key to lock.
def unlock(self, key): """ Releases the lock for the specified key. It never blocks and returns immediately. If the current thread is the holder of this lock, then the hold count is decremented. If the hold count is zero, then the lock is released. :param key: (object), the key to lock. """ check_not_none(key, "key can't be None") key_data = self._to_data(key) return self._encode_invoke_on_key(map_unlock_codec, key_data, key=key_data, thread_id=thread_id(), reference_id=self.reference_id_generator.get_and_increment())
Returns a list clone of the values contained in this map or values of the entries which are filtered with the predicate if provided. **Warning: The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.** :param predicate: (Predicate), predicate to filter the entries (optional). :return: (Sequence), a list of clone of the values contained in this map. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates.
def values(self, predicate=None): """ Returns a list clone of the values contained in this map or values of the entries which are filtered with the predicate if provided. **Warning: The list is NOT backed by the map, so changes to the map are NOT reflected in the list, and vice-versa.** :param predicate: (Predicate), predicate to filter the entries (optional). :return: (Sequence), a list of clone of the values contained in this map. .. seealso:: :class:`~hazelcast.serialization.predicate.Predicate` for more info about predicates. """ if predicate: predicate_data = self._to_data(predicate) return self._encode_invoke(map_values_with_predicate_codec, predicate=predicate_data) else: return self._encode_invoke(map_values_codec)
Creates a Transaction object with given timeout, durability and transaction type. :param timeout: (long), the timeout in seconds determines the maximum lifespan of a transaction. :param durability: (int), the durability is the number of machines that can take over if a member fails during a transaction commit or rollback :param transaction_type: (Transaction Type), the transaction type which can be :const:`~hazelcast.transaction.TWO_PHASE` or :const:`~hazelcast.transaction.ONE_PHASE` :return: (:class:`~hazelcast.transaction.Transaction`), new created Transaction.
def new_transaction(self, timeout, durability, transaction_type): """ Creates a Transaction object with given timeout, durability and transaction type. :param timeout: (long), the timeout in seconds determines the maximum lifespan of a transaction. :param durability: (int), the durability is the number of machines that can take over if a member fails during a transaction commit or rollback :param transaction_type: (Transaction Type), the transaction type which can be :const:`~hazelcast.transaction.TWO_PHASE` or :const:`~hazelcast.transaction.ONE_PHASE` :return: (:class:`~hazelcast.transaction.Transaction`), new created Transaction. """ connection = self._connect() return Transaction(self._client, connection, timeout, durability, transaction_type)
Begins this transaction.
def begin(self): """ Begins this transaction. """ if hasattr(self._locals, 'transaction_exists') and self._locals.transaction_exists: raise TransactionError("Nested transactions are not allowed.") if self.state != _STATE_NOT_STARTED: raise TransactionError("Transaction has already been started.") self._locals.transaction_exists = True self.start_time = time.time() self.thread_id = thread_id() try: request = transaction_create_codec.encode_request(timeout=int(self.timeout * 1000), durability=self.durability, transaction_type=self.transaction_type, thread_id=self.thread_id) response = self.client.invoker.invoke_on_connection(request, self.connection).result() self.id = transaction_create_codec.decode_response(response)["response"] self.state = _STATE_ACTIVE except: self._locals.transaction_exists = False raise
Commits this transaction.
def commit(self): """ Commits this transaction. """ self._check_thread() if self.state != _STATE_ACTIVE: raise TransactionError("Transaction is not active.") try: self._check_timeout() request = transaction_commit_codec.encode_request(self.id, self.thread_id) self.client.invoker.invoke_on_connection(request, self.connection).result() self.state = _STATE_COMMITTED except: self.state = _STATE_PARTIAL_COMMIT raise finally: self._locals.transaction_exists = False
Rollback of this current transaction.
def rollback(self): """ Rollback of this current transaction. """ self._check_thread() if self.state not in (_STATE_ACTIVE, _STATE_PARTIAL_COMMIT): raise TransactionError("Transaction is not active.") try: if self.state != _STATE_PARTIAL_COMMIT: request = transaction_rollback_codec.encode_request(self.id, self.thread_id) self.client.invoker.invoke_on_connection(request, self.connection).result() self.state = _STATE_ROLLED_BACK finally: self._locals.transaction_exists = False
Calculates the request payload size
def calculate_size(transaction_id, thread_id): """ Calculates the request payload size""" data_size = 0 data_size += calculate_size_str(transaction_id) data_size += LONG_SIZE_IN_BYTES return data_size
Loads member addresses from Hazelcast.cloud endpoint. :return: (Sequence), The possible member addresses to connect to.
def load_addresses(self): """ Loads member addresses from Hazelcast.cloud endpoint. :return: (Sequence), The possible member addresses to connect to. """ try: return list(self.cloud_discovery.discover_nodes().keys()) except Exception as ex: self.logger.warning("Failed to load addresses from Hazelcast.cloud: {}".format(ex.args[0]), extra=self._logger_extras) return []