示例#1
0
    def treatMessage(cls, message):
        """Handles the receptions of a Message (called by the listener)
        For regular Actions, addTask is called after translation of the message
        For TesterMessages and TesteeMessages, treatTestMessage is called
        :param message: The Message instance to treat

        """
        cls.logger.debug("Treating message %s", message.__class__.__name__)
        assert isinstance(message, Message)
        # forwarding mechanism
        if message.targetId != Identification.PROBE_ID:
            if ProbeStorage.isKnownId(message.targetId):
                message.recipientId = message.targetId
            else:
                #if we already forwarded it before , stop here
                if message.hash in cls.forwardedMessages:
                    cls.logger.warning("Throwing message %s in forward because message was previously forwarded.", message.__class__.__name__)
                    return
                Scheduler.forward()
                message.recipientId = ProbeStorage.getOtherRandomId()
            cls.logger.info("Forwarding message %s for %s to id %s", message.__class__.__name__, message.targetId, message.recipientId)
            cls.forwardedMessages.append(message.hash)
            Client.send(message)
            return
        # handle special class of messages separately
        if isinstance(message, TestMessage):
            cls.treatTestMessage(message)
        elif isinstance(message, WatcherMessage):
            cls.treatWatcherMessage(message)
        elif isinstance(message, BroadCast):
            # broadcast = do required action first and continue broadcast
            cls.logger.ddebug("Handling Broadcast")
            try:
                ActionMan.addTask(MTA.toAction(message.getMessage()))
            except ActionError:
                pass
            # be sure to propagate broadcast if a reasonable error occurs
            ActionMan.addTask(MTA.toAction(message))
            # Client.broadcast(message)
        else:
            # handles everything else, including Do messages
            ActionMan.addTask(MTA.toAction(message))
示例#2
0
    def treatTestMessage(cls, message):
        """Treats a test message which can be Testee or Tester kind
        Testee are given to TesteeManager
        Tester are given to testResponder
        :param message: testMessage to treat

        """
        cls.logger.ddebug("Handling Tester or Testee message")
        assert isinstance(message, TestMessage)
        # if probe is in test mode, give the message right to the TestManager!
        if isinstance(message, TesteeAnswer):
            cls.logger.ddebug("Handling TesteeAnswer")
            TestManager.handleMessage(message)
        elif isinstance(message, TesterMessage):
            cls.logger.ddebug("Handling TesterMessage")
            TestResponder.handleMessage(message)
        elif isinstance(message, TestMessage):
            #Prepare are test messages
            ActionMan.addTask(MTA.toAction(message))