Exemplo n.º 1
0
    def wait_for_all(self,
                     promise: HaLinkMessagePromise,
                     timeout_sec: float = 30.0):
        """
        Blocks the current thread until all of the messages in
        promise._ids are reported by Motr as delivered.

        Raises NotDelivered exception when timeout_sec exceeds.
        """

        condition = Condition()
        skip_await = False

        with self.lock:
            self.groom_unsorted(promise)
            self.waiting_clients[promise] = condition
            skip_await = promise in self.recently_delivered

        while not promise.is_empty():
            if skip_await:
                LOG.log(
                    TRACE, 'Promise %s has been confirmed before, '
                    'no need to block', promise)
                skip_await = False
            else:
                with condition:
                    LOG.log(TRACE, 'Blocking until %s is confirmed', promise)
                    condition.wait(timeout=timeout_sec)
            with self.lock:
                self._verify_delivered(promise, timeout_sec)
                if not promise.is_empty():
                    self.waiting_clients[promise] = condition
Exemplo n.º 2
0
    def wait_for_all(self,
                     promise: HaLinkMessagePromise,
                     timeout_sec: float = 30.0):
        """
        Blocks the current thread until all of the messages in
        promise._ids are reported by Motr as delivered.

        Raises NotDelivered exception when timeout_sec exceeds.
        """

        condition = Condition()
        with self.lock:
            self.waiting_clients[promise] = condition
            LOG.log(TRACE, 'waiting clients %s', self.waiting_clients)

        while not promise.is_empty():
            with condition:
                LOG.log(TRACE, 'Blocking until %s is confirmed', promise)
                condition.wait(timeout=timeout_sec)
            with self.lock:
                if promise not in self.recently_delivered:
                    raise NotDelivered('None of message tags =' +
                                       str(promise) +
                                       '  were delivered to Motr')
                confirmed_msgs = self.recently_delivered.pop(promise)
                LOG.log(TRACE, 'Thread unblocked - %s just received',
                        confirmed_msgs)
                del self.waiting_clients[promise]
                promise.exclude_ids(confirmed_msgs)
                if not promise.is_empty():
                    self.waiting_clients[promise] = condition
Exemplo n.º 3
0
    def wait_for_all(self,
                     promise: HaLinkMessagePromise,
                     timeout_sec: float = 30.0):
        """
        Blocks the current thread until all of the messages in
        promise._ids are reported by Motr as delivered.

        Raises NotDelivered exception when timeout_sec exceeds.
        """

        condition = Condition()
        with self.lock:
            self.waiting_clients[promise] = condition
            LOG.log(TRACE, 'waiting clients %s', self.waiting_clients)

        while not promise.is_empty():
            with condition:
                LOG.log(TRACE, 'Blocking until %s is confirmed', promise)
                condition.wait(timeout=timeout_sec)
            with self.lock:
                self._verify_delivered(promise, timeout_sec)
                if not promise.is_empty():
                    self.waiting_clients[promise] = condition