예제 #1
0
    def transaction_finish(self, event):
        """
        finish transaction, do tranaction action, process reporting and control options

        :param event: reactor event
        :type event: proton.Event
        """
        if self.current_batch == self.opts.tx_size:
            if self.opts.tx_action == 'commit':
                self.transaction.commit()
            elif self.opts.tx_action == 'rollback':
                self.transaction.abort()

            if self.opts.tx_action == 'none':
                if self.msg_processed_cnt + self.current_batch == self.msg_expected_cnt:
                    self.tear_down(event)
                else:
                    self.msg_processed_cnt += self.current_batch
                    self.current_batch = 0
                    event.reactor.declare_transaction(event.connection,
                                                      handler=self)

            if self.opts.duration != 0 and self.opts.duration_mode == 'after-receive-tx-action':
                utils.sleep4next(self.start_tm, self.msg_expected_cnt,
                                 self.opts.duration,
                                 self.msg_processed_cnt + self.current_batch)
        elif ((self.msg_expected_cnt and self.msg_processed_cnt +
               self.current_batch == self.msg_expected_cnt)
              or (not self.msg_expected_cnt and self.is_empty(event))):
            if self.opts.tx_endloop_action == 'commit':
                self.transaction.commit()
            elif self.opts.tx_endloop_action == 'rollback':
                self.transaction.abort()
            else:
                self.tear_down(event)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    def on_delivery(self, event):
        """
        called when a message is delivered

        :param event: reactor event
        :type event: proton.Event
        """
        if self.opts.duration != 0 and self.opts.duration_mode == 'before-receive':
            utils.sleep4next(self.start_tm, self.msg_expected_cnt,
                             self.opts.duration, self.msg_processed_cnt + self.current_batch + 1)
예제 #5
0
    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))