Esempio n. 1
0
    def remove_if_same(self, key, value):
        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)
Esempio n. 2
0
 def put(self, key, value, ttl=0):
     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))
Esempio n. 3
0
 def retain_all(self, items):
     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(set_compare_and_retain_all_codec, values=data_items)
Esempio n. 4
0
 def remove(self, key, value):
     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(multi_map_remove_entry_codec, key_data, key=key_data,
                                       value=value_data, thread_id=thread_id())
Esempio n. 5
0
 def add_all(self, items):
     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(set_add_all_codec, value_list=data_items)
Esempio n. 6
0
    def try_remove(self, key, timeout=0):
        check_not_none(key, "key can't be None")

        key_data = self._to_data(key)

        return self._encode_invoke_on_key(map_try_remove_codec, key_data, key=key_data,
                                          thread_id=thread_id(), timeout=to_millis(timeout))
Esempio n. 7
0
    def unlock(self, key):
        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())
Esempio n. 8
0
 def put_all(self, map):
     entries = {}
     for key, value in map.iteritems():
         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)
Esempio n. 9
0
 def contains_all(self, items):
     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)
Esempio n. 10
0
    def get_all(self, keys):
        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].append(key_data)
            except KeyError:
                partition_to_keys[partition_id] = [key_data]

        futures = []
        for partition_id, key_list in partition_to_keys.iteritems():
            future = self._encode_invoke_on_partition(map_get_all_codec, partition_id, keys=key_list)
            futures.append(future)

        def merge(f):
            return dict(itertools.chain(*f.result()))

        return combine_futures(*futures).continue_with(merge)
Esempio n. 11
0
 def remove_all(self, items):
     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(queue_compare_and_remove_all_codec, data_list=data_items)
Esempio n. 12
0
    def put_transient(self, key, value, ttl=-1):
        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)
Esempio n. 13
0
    def execute_on_keys(self, keys, entry_processor):
        key_list = []
        for key in keys:
            check_not_none(key, "key can't be None")
            key_list.append(self._to_data(key))

        return self._encode_invoke(map_execute_on_keys_codec, entry_processor=self._to_data(entry_processor),
                                   keys=key_list)
Esempio n. 14
0
 def get(self, key):
     """
     :param key:
     :return:
     """
     check_not_none(key, "key can't be None")
     key_data = self._to_data(key)
     return self._encode_invoke_on_key(map_get_codec, key_data, key=key_data, thread_id=thread_id())
Esempio n. 15
0
    def try_put(self, key, value, timeout=0):
        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)
Esempio n. 16
0
 def get(self, key):
     """
     :param key:
     :return:
     """
     check_not_none(key, "key can't be None")
     key_data = self._to_data(key)
     return self._get_internal(key_data)
Esempio n. 17
0
    def put_transient(self, key, value, ttl=-1):
        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._encode_invoke_on_key(map_put_transient_codec, key_data, key=key_data,
                                          value=value_data, thread_id=thread_id(), ttl=to_millis(ttl))
Esempio n. 18
0
 def contains_key(self, key):
     """
     :param key:
     :return:
     """
     check_not_none(key, "key can't be None")
     key_data = self._to_data(key)
     return self._contains_key_internal(key_data)
Esempio n. 19
0
    def execute_on_key_owner(self, key, task):
        check_not_none(key, "key can't be None")
        key_data = self._to_data(key)
        partition_id = self._client.partition_service.get_partition_id(key_data)

        uuid = self._get_uuid()
        return self._encode_invoke_on_partition(executor_service_submit_to_partition_codec, partition_id,
                                                uuid=uuid, callable=self._to_data(task),
                                                partition_id=partition_id)
    def add_all(self, items, overflow_policy=OVERFLOW_POLICY_OVERWRITE):
        check_not_empty(items, "items can't be empty")
        if len(items) > MAX_BATCH_SIZE:
            raise AssertionError("Batch size can't be greater than %d" % MAX_BATCH_SIZE)
        for item in items:
            check_not_none(item, "item can't be None")

        item_list = [self._to_data(x) for x in items]
        return self._encode_invoke(ringbuffer_add_all_codec, value_list=item_list, overflow_policy=overflow_policy)
Esempio n. 21
0
    def try_put(self, key, value, timeout=0):
        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._encode_invoke_on_key(map_try_put_codec, key_data, key=key_data, value=value_data,
                                          thread_id=thread_id(), timeout=to_millis(timeout))
Esempio n. 22
0
    def get(self, key):
        """
        :param key:
        :return:
        """
        check_not_none(key, "key can't be None")

        key_data = self._to_data(key)
        request = map_get_codec.encode_request(self.name, key_data, thread_id=thread_id())
        response = self._invoke_on_key(request, key_data)
        result_data = map_get_codec.decode_response(response)["response"]
        return self._to_object(result_data)
Esempio n. 23
0
 def set(self, key, value, ttl=-1):
     """
     :param key:
     :param value:
     :param ttl:
     :return:
     """
     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)
Esempio n. 24
0
 def set(self, key, value, ttl=-1):
     """
     :param key:
     :param value:
     :param ttl:
     :return:
     """
     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._encode_invoke_on_key(map_set_codec, key_data, key=key_data, value=value_data,
                                       thread_id=thread_id(),
                                       ttl=to_millis(ttl))
Esempio n. 25
0
    def put(self, key, value, ttl=-1):
        """
        :param key:
        :param value:
        :param ttl:
        :return:
        """
        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)

        request = map_put_codec.encode_request(self.name, key_data, value_data, thread_id=thread_id(), ttl=ttl)
        response = self._invoke_on_key(request, key_data)
        result_data = map_put_codec.decode_response(response)["response"]
        return self._to_object(result_data)
Esempio n. 26
0
    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))

        request = list_compare_and_retain_all_codec.encode_request(
            self.name, data_items)
        return self._invoke(request,
                            list_compare_and_retain_all_codec.decode_response)
Esempio n. 27
0
    def contains(self, item: ItemType) -> Future[bool]:
        """Determines whether this queue contains the specified item or not.

        Args:
            item: The specified item to be searched.

        Returns:
            ``True`` if the specified item exists in this queue, ``False``
            otherwise.
        """
        check_not_none(item, "Item can't be None")
        try:
            item_data = self._to_data(item)
        except SchemaNotReplicatedError as e:
            return self._send_schema_and_retry(e, self.contains, item)

        request = queue_contains_codec.encode_request(self.name, item_data)
        return self._invoke(request, queue_contains_codec.decode_response)
    def remove_if_same(self, key, value):
        """
        Transactional implementation of :func:`Map.remove_if_same(key, value)
        <hazelcast.proxy.map.Map.remove_if_same>`

        The object to be removed will be removed from only the current transaction context until the transaction is
        committed.

        :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, ``false`` otherwise.
        """

        check_not_none(key, "key can't be none")
        check_not_none(value, "value can't be none")
        return self._encode_invoke(transactional_map_remove_if_same_codec,
                                   key=self._to_data(key),
                                   value=self._to_data(value))
Esempio n. 29
0
    def get(self, key):
        """
        Transactional implementation of :func:`MultiMap.get(key) <hazelcast.proxy.multi_map.MultiMap.get>`

        :param key: (object), the key whose associated values are returned.
        :return: (Sequence), the collection of the values associated with the key.
        """
        check_not_none(key, "key can't be none")

        def handler(message):
            return ImmutableLazyDataList(
                transactional_multi_map_get_codec.decode_response(message),
                self._to_object)

        key_data = self._to_data(key)
        request = transactional_multi_map_get_codec.encode_request(
            self.name, self.transaction.id, thread_id(), key_data)
        return self._invoke(request, handler)
Esempio n. 30
0
    def delete(self, key):
        """Transactional implementation of :func:`Map.delete(key) <hazelcast.proxy.map.Map.delete>`
        
        The object to be deleted will be removed from only the current transaction context until the transaction is
        committed.

        Args:
            key: Key of the mapping to be deleted.

        Returns:
            hazelcast.future.Future[None]:
        """
        check_not_none(key, "key can't be none")

        key_data = self._to_data(key)
        request = transactional_map_delete_codec.encode_request(
            self.name, self.transaction.id, thread_id(), key_data)
        return self._invoke(request)
    def put(self, key, value, ttl=-1):
        """
        Transactional implementation of :func:`Map.put(key, value, ttl) <hazelcast.proxy.map.Map.put>`

        The object to be put will be accessible only in the current transaction context till the transaction is
        committed.

        :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 (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")
        return self._encode_invoke(transactional_map_put_codec,
                                   key=self._to_data(key),
                                   value=self._to_data(value),
                                   ttl=to_millis(ttl))
Esempio n. 32
0
    def get_all(self, keys):
        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)
Esempio n. 33
0
    def put(self, key, value):
        """
        Transactional implementation of :func:`MultiMap.put(key, value) <hazelcast.proxy.multi_map.MultiMap.put>`

        :param key: (object), the key to be stored.
        :param value: (object), the value to be stored.
        :return: (bool), ``true`` if the size of the multimap is increased, ``false`` if the multimap already contains
            the key-value tuple.
        """
        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)
        request = transactional_multi_map_put_codec.encode_request(
            self.name, self.transaction.id, thread_id(), key_data, value_data)
        return self._invoke(request,
                            transactional_multi_map_put_codec.decode_response)
Esempio n. 34
0
    def set_at(self, index, item):
        """Replaces the specified element with the element at the specified position in this list.

        Args:
            index (int): Index of the item to be replaced.
            item: Item to be stored.

        Returns:
            hazelcast.future.Future[any]: the previous item in the specified index. 
        """
        check_not_none(item, "Value can't be None")
        element_data = self._to_data(item)

        def handler(message):
            return self._to_object(list_set_codec.decode_response(message))

        request = list_set_codec.encode_request(self.name, index, element_data)
        return self._invoke(request, handler)
Esempio n. 35
0
    def get_all(self, keys):
        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)
Esempio n. 36
0
    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)
Esempio n. 37
0
    def remove(self, item: ItemType) -> Future[bool]:
        """Removes the specified element from the queue if it exists.

        Args:
            item: The specified element to be removed.

        Returns:
            ``True`` if the specified element exists in this queue, ``False``
            otherwise.
        """
        check_not_none(item, "Value can't be None")
        try:
            item_data = self._to_data(item)
        except SchemaNotReplicatedError as e:
            return self._send_schema_and_retry(e, self.remove, item)

        request = queue_remove_codec.encode_request(self.name, item_data)
        return self._invoke(request, queue_remove_codec.decode_response)
Esempio n. 38
0
    def set(self, key, value):
        """
        Transactional implementation of :func:`Map.set(key, value) <hazelcast.proxy.map.Map.set>`

        The object to be set will be accessible only in the current transaction context till the transaction is
        committed.

        :param key: (object), key of the entry.
        :param value: (object), 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)
        request = transactional_map_set_codec.encode_request(
            self.name, self.transaction.id, thread_id(), key_data, value_data)
        return self._invoke(request)
    def put_if_absent(self, key, value):
        """
        Transactional implementation of :func:`Map.put_if_absent(key, value)
        <hazelcast.proxy.map.Map.put_if_absent>`

        The object to be put will be accessible only in the current transaction context till the transaction is
        committed.

        :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 (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")
        return self._encode_invoke(transactional_map_put_if_absent_codec,
                                   key=self._to_data(key),
                                   value=self._to_data(value))
    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.

        Args:
            key: The specified key.

        Returns:
            hazelcast.future.Future[bool]: ``True`` if this map contains an entry for the specified key, 
            ``False`` otherwise.
        """
        check_not_none(key, "key can't be None")
        key_data = self._to_data(key)
        request = replicated_map_contains_key_codec.encode_request(self.name, key_data)
        return self._invoke_on_key(request, key_data, replicated_map_contains_key_codec.decode_response)
Esempio n. 41
0
    def contains_all(self, items):
        """Determines whether this list contains all of the items in specified collection or not.

        Args:
          items (list): The specified collection which includes the items to be searched.

        Returns:
            hazelcast.future.Future[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))

        request = list_contains_all_codec.encode_request(self.name, data_items)
        return self._invoke(request, list_contains_all_codec.decode_response)
Esempio n. 42
0
    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))
    def offer(self, item, timeout=0):
        """Transactional implementation of :func:`Queue.offer(item, timeout) <hazelcast.proxy.queue.Queue.offer>`

        Args:
            item: The item to be added.
            timeout (int): Maximum time in seconds to wait for addition.

        Returns:
            hazelcast.future.Future[bool]: ``True`` if the element was added to this queue, ``False`` otherwise.
        """
        check_not_none(item, "item can't be none")

        item_data = self._to_data(item)
        request = transactional_queue_offer_codec.encode_request(
            self.name, self.transaction.id, thread_id(), item_data,
            to_millis(timeout))
        return self._invoke(request,
                            transactional_queue_offer_codec.decode_response)
    def add_listener(self, listener):
        """Subscribes to this reliable topic.

        It can be either a simple function or an instance of an
        :class:`ReliableMessageListener`. When a function is passed, a
        :class:`ReliableMessageListener` is created out of that with
        sensible default values.

        When a message is published, the,
        :func:`ReliableMessageListener.on_message` method of the given
        listener (or the function passed) is called.

        More than one message listener can be added on one instance.

        Args:
            listener (function or ReliableMessageListener): Listener to add.

        Returns:
            hazelcast.future.Future[str]: The registration id.
        """
        check_not_none(listener, "None listener is not allowed")

        registration_id = str(uuid4())
        reliable_message_listener = self._to_reliable_message_listener(
            listener)

        runner = _MessageRunner(
            registration_id,
            reliable_message_listener,
            self._ringbuffer,
            self.name,
            self._config.read_batch_size,
            self._to_object,
            self._runners,
        )

        def continuation(future):
            future.result()
            # If the runner started successfully, register it.
            self._runners[registration_id] = runner
            runner.next_batch()
            return registration_id

        return runner.start().continue_with(continuation)
    def remove_listener(self, registration_id):
        """Stops receiving messages for the given message listener.

        If the given listener already removed, this method does nothing.

        Args:
            registration_id (str): ID of listener registration.

        Returns:
            hazelcast.future.Future[bool]: ``True`` if registration is
            removed, ``False`` otherwise.
        """
        check_not_none(registration_id, "Registration id cannot be None")
        runner = self._runners.get(registration_id, None)
        if not runner:
            return ImmediateFuture(False)

        runner.cancel()
        return ImmediateFuture(True)
Esempio n. 46
0
    def get(self, key):
        """
        Returns the list of values associated with the key. ``None`` if this map does not contain this key.

        **Warning:
        This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode
        and equals defined in the key's class.**

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

        :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(multi_map_get_codec, key_data, key=key_data,
                                          thread_id=thread_id())
    def get(self, key):
        """Transactional implementation of :func:`Map.get(key) <hazelcast.proxy.map.Map.get>`

        Args:
            key: The specified key.

        Returns:
            hazelcast.future.Future[any]: The value for the specified key.
        """
        check_not_none(key, "key can't be none")

        def handler(message):
            return self._to_object(transactional_map_get_codec.decode_response(message))

        key_data = self._to_data(key)
        request = transactional_map_get_codec.encode_request(
            self.name, self.transaction.id, thread_id(), key_data
        )
        return self._invoke(request, handler)
Esempio n. 48
0
    def contains_value(self, value: ValueType) -> Future[bool]:
        """Determines whether this map contains one or more keys for the
        specified value.

        Args:
            value: The specified value.

        Returns:
            ``True`` if this multimap contains an entry for the specified
            value, ``False`` otherwise.
        """
        check_not_none(value, "value can't be None")
        try:
            value_data = self._to_data(value)
        except SchemaNotReplicatedError as e:
            return self._send_schema_and_retry(e, self.contains_value, value)

        request = multi_map_contains_value_codec.encode_request(self.name, value_data)
        return self._invoke(request, multi_map_contains_value_codec.decode_response)
    def unlock(self, key):
        """Releases the lock for the specified key. It never blocks and returns immediately.

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

        Args:
            key: The key to lock.

        Returns:
            hazelcast.future.Future[None]:
        """
        check_not_none(key, "key can't be None")
        key_data = self._to_data(key)
        request = multi_map_unlock_codec.encode_request(
            self.name, key_data, thread_id(), self._reference_id_generator.get_and_increment()
        )
        return self._invoke_on_key(request, key_data)
Esempio n. 50
0
    def remove(self, key, value):
        """
        Transactional implementation of :func:`MultiMap.remove(key, value)
        <hazelcast.proxy.multi_map.MultiMap.remove>`

        :param key: (object), the key of the entry to remove.
        :param value: (object), the value of the entry to remove.
        :return: (bool), True if the item is removed, 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)
        request = transactional_multi_map_remove_entry_codec.encode_request(
            self.name, self.transaction.id, thread_id(), key_data, value_data)
        return self._invoke(
            request,
            transactional_multi_map_remove_entry_codec.decode_response)
Esempio n. 51
0
    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.

        Args:
            items (list): Collections which includes the elements to be retained in this list.

        Returns:
            hazelcast.future.Future[bool]: ``True`` if this list changed as a result of the call, ``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))

        request = list_compare_and_retain_all_codec.encode_request(self.name, data_items)
        return self._invoke(request, list_compare_and_retain_all_codec.decode_response)
    def remove(self, key, value):
        """
        Removes the given key-value tuple from the multimap.

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

        :param key: (object),  the key of the entry to remove.
        :param value: (object), the value of the entry to remove.
        :return: (bool), ``true`` if the size of the multimap changed after the remove operation, ``false`` otherwise.
        """
        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)
        request = multi_map_remove_entry_codec.encode_request(
            self.name, key_data, value_data, thread_id())
        return self._invoke_on_key(
            request, key_data, multi_map_remove_entry_codec.decode_response)
Esempio n. 53
0
    def deregister_listener(self, user_registration_id):
        check_not_none(user_registration_id,
                       "None user_registration_id is not allowed!")

        with self._registration_lock:
            listener_registration = self._active_registrations.pop(
                user_registration_id, None)
            if not listener_registration:
                return ImmediateFuture(False)

            for connection, event_registration in six.iteritems(
                    listener_registration.connection_registrations):
                # Remove local handler
                self.remove_event_handler(event_registration.correlation_id)
                # The rest is for deleting the remote registration
                server_registration_id = event_registration.server_registration_id
                deregister_request = listener_registration.encode_deregister_request(
                    server_registration_id)
                if deregister_request is None:
                    # None means no remote registration (e.g. for backup acks)
                    continue

                invocation = Invocation(deregister_request,
                                        connection=connection,
                                        timeout=six.MAXSIZE,
                                        urgent=True)
                self._invocation_service.invoke(invocation)

                def handler(f, connection=connection):
                    e = f.exception()
                    if e:
                        if isinstance(e, (HazelcastClientNotActiveError,
                                          IOError, TargetDisconnectedError)):
                            return

                        _logger.warning(
                            "Deregistration of listener with ID %s has failed for address %s",
                            user_registration_id, connection.remote_address)

                invocation.future.add_done_callback(handler)

            listener_registration.connection_registrations.clear()
            return ImmediateFuture(True)
Esempio n. 54
0
    def remove_all(self, items):
        """Removes all of the elements that is present in the specified collection from this list.

        Args:
            items (list): The specified collection.

        Returns:
            hazelcast.future.Future[bool]: ``True`` if this list changed as a result of the call, ``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))

        request = list_compare_and_remove_all_codec.encode_request(
            self.name, data_items)
        return self._invoke(request,
                            list_compare_and_remove_all_codec.decode_response)
Esempio n. 55
0
    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.

        Args:
            items (list): The specified collection which includes the elements to be added to list.

        Returns:
            hazelcast.future.Future[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))

        request = list_add_all_codec.encode_request(self.name, data_items)
        return self._invoke(request, list_add_all_codec.decode_response)
    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: (object), the value associated with the specified key.
        """
        check_not_none(key, "key can't be None")

        def handler(message):
            return self._to_object(
                replicated_map_get_codec.decode_response(message))

        key_data = self._to_data(key)
        request = replicated_map_get_codec.encode_request(self.name, key_data)
        return self._invoke_on_key(request, key_data, handler)
Esempio n. 57
0
    def put_all(self, 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 map.iteritems():
            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 partition_map.iteritems():
            future = self._encode_invoke_on_partition(map_put_all_codec, partition_id,
                                                      entries=dict(entry_list))
            futures.append(future)

        return combine_futures(*futures)
Esempio n. 58
0
    def replace_if_same(self, key, old_value, new_value):
        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)
Esempio n. 59
0
    def replace_if_same(self, key, old_value, new_value):
        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._encode_invoke_on_key(map_replace_if_same_codec, key_data, key=key_data,
                                          test_value=old_value_data,
                                          value=new_value_data, thread_id=thread_id())
Esempio n. 60
0
 def remove(self, 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)