예제 #1
0
    def wait_for_any(self,
                     promise: HaLinkMessagePromise,
                     timeout_sec: float = 30.0):
        """
        Blocks the current thread until at least one 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

        with condition:
            logging.debug('Blocking until %s is confirmed', promise)
            condition.wait(timeout=timeout_sec)
        with self.lock:
            del self.waiting_clients[promise]
            if promise not in self.recently_delivered:
                raise NotDelivered('None of message tags =' + str(promise) +
                                   '  were delivered to Motr within ' +
                                   str(timeout_sec) + ' seconds timeout')
            logging.debug('Thread unblocked - %s has just been received',
                          self.recently_delivered[promise])
            del self.recently_delivered[promise]
예제 #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
예제 #3
0
    def _verify_delivered(self, promise: HaLinkMessagePromise,
                          timeout_sec: float):
        """
        Verify if any message in promise._ids are reported by Motr
        as delivered. Calling function should hold the self.lock.
        """

        del self.waiting_clients[promise]
        if promise not in self.recently_delivered:
            raise NotDelivered('None of message tags =' + str(promise) +
                               '  were delivered to Motr within ' +
                               str(timeout_sec) + ' seconds timeout')
        confirmed_msgs = self.recently_delivered.pop(promise)
        LOG.log(TRACE, 'Thread unblocked - %s just received', confirmed_msgs)
        promise.exclude_ids(confirmed_msgs)