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
def check_if_delivered_locked( self, promise: HaLinkMessagePromise) -> HaLinkMessagePromise: if not self.lock.locked(): raise RuntimeError('DeliveryHerald.lock not acquired') if promise in self.recently_delivered: confirmed_msgs = self.recently_delivered.pop(promise) LOG.debug('Thread unblocked - %s just received', confirmed_msgs) del self.waiting_clients[promise] promise.exclude_ids(confirmed_msgs) return promise
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)