예제 #1
0
 def process_outgoing_messsages(self, message: Message):
     """Process only the outgoing messages"""
     # Check sender is not in list of destroyed threads
     if len(message.sender) > 1:
         # Append name to front of sender and pass up
         message.sender = [self.owner, *message.sender]
         self.output_queue.put(message)
     else:
         self.logger.error(
             f"Sender {message.sender} does not have enough information")
예제 #2
0
    def _message_handle(self, message: Message):
        """Takes a slightly different approach to messages as it needs to handle
        different situations"""

        # Run garbage collection
        self.garbage_collect()

        self.logger.debug(
            f"MESSAGE Sender: {message.sender}, Command {message.command}, Package: {message.package}"
        )

        # Addressed to self
        if message.receiver == [self.name]:
            # Process as normal
            super()._message_handle(message)
        # Addressed to child thread
        elif self.name in message.receiver:
            # Strip name off front and pass on
            message.receiver = message.receiver[1:]
            # Send to appropriate thread input queue
            if message.receiver[0] in self.active_threads.keys():
                self.active_threads[message.receiver[0]].input_queue.put(
                    message)
        else:
            # Check sender is not in list of destroyed threads
            if len(message.sender) > 1:
                if message.sender[1] not in self.destroyed_threads:
                    # Append name to front of sender and pass up
                    message.sender = [self.owner, *message.sender]
                    self.output_queue.put(message)
                else:
                    self.logger.error(
                        f"Sender {message.sender[1]} is a destroyed thread")
            else:
                self.logger.error(
                    f"Sender {message.sender} does not have enough information"
                )

        # Run garbage collection
        self.garbage_collect()