def transaction_process(self, event): """ transactionally receive a message, process reporting and control options :param event: reactor event :type event: proton.Event """ self.transaction.accept(event.delivery) self.current_batch += 1 self.received += 1 if self.opts.log_stats == 'endpoints': utils.dump_event(event) self.print_message(event.message) if self.opts.duration != 0 and self.opts.duration_mode == 'after-receive': utils.sleep4next(self.start_tm, self.msg_expected_cnt, self.opts.duration, self.msg_processed_cnt + self.current_batch) if not self.opts.link_at_most_once and not self.opts.reactor_auto_accept: if (self.msg_processed_cnt + self.current_batch) % self.opts.action_size == 0: self.do_message_action(event.delivery) if self.opts.duration != 0 and self.opts.duration_mode == 'after-receive-action': utils.sleep4next(self.start_tm, self.msg_expected_cnt, self.opts.duration, self.msg_processed_cnt + self.current_batch) if self.opts.process_reply_to: self.process_reply_to(event) self.transaction_finish(event)
def transaction_process(self, event): """ transactionally send a message, process reporting and control options :param event: reactor event :type event: proton.Event """ msg = self.prepare_message() if self.msg_content_fmt: msg_content = msg.body while event.transaction and self.sender.credit and ( self.msg_processed_cnt + self.current_batch) < self.msg_total_cnt: if self.msg_content_fmt: msg.body = msg_content % (self.msg_processed_cnt + self.current_batch) if self.opts.duration != 0 and self.opts.duration_mode == 'before-send': utils.sleep4next(self.start_tm, self.msg_total_cnt, self.opts.duration, self.msg_processed_cnt + self.current_batch + 1) event.transaction.send(self.sender, msg) self.current_batch += 1 if self.opts.log_stats == 'endpoints': utils.dump_event(event) self.print_message(msg) if self.opts.duration != 0 and self.opts.duration_mode == 'after-send': utils.sleep4next(self.start_tm, self.msg_total_cnt, self.opts.duration, self.msg_processed_cnt + self.current_batch) self.transaction_finish(event)
def send_message(self): """ sends a message """ # close the connection if nothing to send if self.msg_total_cnt == 0: self.event.connection.close() if self.msg_content_fmt: self.msg.body = self.msg_content % self.msg_sent_cnt self.event.sender.send(self.msg) self.msg_sent_cnt += 1 self.print_message(self.msg) if self.opts.log_stats == 'endpoints': utils.dump_event(self.event) if self.opts.link_at_most_once and self.msg_sent_cnt == self.msg_total_cnt: self.tear_down(self.event)
def on_message(self, event): """ called when a message is received :param event: reactor event :type event: proton.Event """ if self.msg_expected_cnt == 0 or self.msg_received_cnt < self.msg_expected_cnt: self.msg_received_cnt += 1 if self.opts.log_stats == 'endpoints': utils.dump_event(event) self.print_message(event.message) if self.opts.duration != 0 and self.opts.duration_mode == 'after-receive' \ or self.opts.duration_mode == 'after-receive-tx-action': utils.sleep4next(self.start_tm, self.msg_expected_cnt, self.opts.duration, self.msg_received_cnt) if not self.opts.link_at_most_once and not self.opts.reactor_auto_accept: if self.msg_received_cnt % self.opts.action_size == 0: self.do_message_action(event.delivery) if self.opts.duration != 0 and self.opts.duration_mode == 'after-receive-action': utils.sleep4next(self.start_tm, self.msg_expected_cnt, self.opts.duration, self.msg_received_cnt) if self.opts.process_reply_to: self.process_reply_to(event) if self.msg_received_cnt == self.msg_expected_cnt: self.tear_down(event) self.check_empty(event) # timeout if there is nothing to read if self.receiver and self.receiver.queued == 0 and self.opts.timeout: self.timeout.cancel() if self.msg_received_cnt != self.msg_expected_cnt: self.timeout = event.reactor.schedule(self.opts.timeout, Timeout(self, event))
def send_message(self): """ sends a message """ # close the connection if nothing to send if self.msg_total_cnt == 0: self.event.connection.close() if self.msg_content_fmt: self.msg.body = self.msg_content % self.msg_sent_cnt self.event.sender.send(self.msg) self.msg_sent_cnt += 1 self.print_message(self.msg) # set up a new timeout (if one provided) self.schedule_timeout(self.event) if self.opts.log_stats == 'endpoints': utils.dump_event(self.event) if self.opts.link_at_most_once and self.msg_sent_cnt - self.msg_released_cnt == self.msg_total_cnt: self.tear_down(self.event)
def tear_down(self, event, settled=False): """ tears down and closes the connection :param event: reactor event :type event: proton.Event :param settled: indicates whether all messages has been explicitly settled :type settled: bool """ if self.auto_settle or settled: if self.next_task is not None: self.next_task.cancel() if self.timeout is not None: self.timeout.cancel() if self.opts.log_stats == 'endpoints': utils.dump_event(event) self.tearing_down = True time.sleep(self.opts.close_sleep) if event.receiver: event.receiver.close() if event.sender: event.sender.close() if event.connection: event.connection.close()