Exemple #1
0
    def receive(self, accept_ids, ignore_ids=[], ignore_types=(),
            timeout=DEFAULT_TIMEOUT, timeout_ticker=None):
        """
            like send_and_receive but without sending anything
        """
        if timeout_ticker is None: timeout_ticker = TimeoutTicker(timeout)

        while timeout_ticker.permit():
            mxmsg, connwrap = self.__receive_message(timeout=timeout_ticker())
            if mxmsg.type in ignore_types:
                continue

            if mxmsg.references in accept_ids:
                return (mxmsg, connwrap)

            if mxmsg.references not in ignore_ids:
                # unexpected message received
                log(WARNING, HIGHVERBOSITY,
                    text="message (id=%d, type=%d, from=%d, references=%d) "
                        "while waiting for reply for %r" % \
                            (mxmsg.id, mxmsg.type, mxmsg.from_,
                                mxmsg.references, accept_ids)
                    )
                self.handle_drop(mxmsg, connwrap)

        raise OperationTimedOut()
Exemple #2
0
    def receive(self,
                accept_ids,
                ignore_ids=[],
                ignore_types=(),
                timeout=DEFAULT_TIMEOUT,
                timeout_ticker=None):
        """
            like send_and_receive but without sending anything
        """
        if timeout_ticker is None: timeout_ticker = TimeoutTicker(timeout)

        while timeout_ticker.permit():
            mxmsg, connwrap = self.__receive_message(timeout=timeout_ticker())
            if mxmsg.type in ignore_types:
                continue

            if mxmsg.references in accept_ids:
                return (mxmsg, connwrap)

            if mxmsg.references not in ignore_ids:
                # unexpected message received
                log(WARNING, HIGHVERBOSITY,
                    text="message (id=%d, type=%d, from=%d, references=%d) "
                        "while waiting for reply for %r" % \
                            (mxmsg.id, mxmsg.type, mxmsg.from_,
                                mxmsg.references, accept_ids)
                    )
                self.handle_drop(mxmsg, connwrap)

        raise OperationTimedOut()
Exemple #3
0
 def handle_drop(self, mxmsg, connwrap=None):
     """overide in subclass if you want to get hold on every message
        dropped"""
     log(WARNING, HIGHVERBOSITY,
             text="dropping message %r" % dict(id=mxmsg.id, type=mxmsg.type,
                 to=mxmsg.to, from_=mxmsg.from_,
                 references=mxmsg.references, len=len(mxmsg.message))
         )
Exemple #4
0
 def handle_drop(self, mxmsg, connwrap=None):
     """overide in subclass if you want to get hold on every message
        dropped"""
     log(WARNING,
         HIGHVERBOSITY,
         text="dropping message %r" % dict(id=mxmsg.id,
                                           type=mxmsg.type,
                                           to=mxmsg.to,
                                           from_=mxmsg.from_,
                                           references=mxmsg.references,
                                           len=len(mxmsg.message)))