Example #1
0
    def get_distributed_objects(self):
        """
        Returns all distributed objects such as; queue, map, set, list, topic, lock, multimap.
        Also, as a side effect, it clears the local instances of the destroyed proxies.
        :return:(Sequence), List of instances created by Hazelcast.
        """
        request = client_get_distributed_objects_codec.encode_request()
        to_object = self.serialization_service.to_object
        future = self.invoker.invoke_on_random_target(request)
        response = client_get_distributed_objects_codec.decode_response(
            future.result(), to_object)["response"]

        distributed_objects = self.proxy.get_distributed_objects()
        local_distributed_object_infos = set()
        for dist_obj in distributed_objects:
            local_distributed_object_infos.add(
                DistributedObjectInfo(dist_obj.name, dist_obj.service_name))

        for dist_obj_info in response:
            local_distributed_object_infos.discard(dist_obj_info)
            self.proxy.get_or_create(dist_obj_info.service_name,
                                     dist_obj_info.name,
                                     create_on_remote=False)

        for dist_obj_info in local_distributed_object_infos:
            self.proxy.destroy_proxy(dist_obj_info.service_name,
                                     dist_obj_info.name,
                                     destroy_on_remote=False)

        return self.proxy.get_distributed_objects()
    def get_distributed_objects(self):
        """Returns all distributed objects such as; queue, map, set, list, topic, lock, multimap.

        Also, as a side effect, it clears the local instances of the destroyed proxies.

        Returns:
            list[hazelcast.proxy.base.Proxy]: List of instances created by Hazelcast.
        """
        request = client_get_distributed_objects_codec.encode_request()
        invocation = Invocation(request, response_handler=lambda m: m)
        self._invocation_service.invoke(invocation)

        local_distributed_object_infos = {
            DistributedObjectInfo(dist_obj.service_name, dist_obj.name)
            for dist_obj in self._proxy_manager.get_distributed_objects()
        }

        response = client_get_distributed_objects_codec.decode_response(
            invocation.future.result())
        for dist_obj_info in response:
            local_distributed_object_infos.discard(dist_obj_info)
            self._proxy_manager.get_or_create(dist_obj_info.service_name,
                                              dist_obj_info.name,
                                              create_on_remote=False)

        for dist_obj_info in local_distributed_object_infos:
            self._proxy_manager.destroy_proxy(dist_obj_info.service_name,
                                              dist_obj_info.name,
                                              destroy_on_remote=False)

        return self._proxy_manager.get_distributed_objects()