Beispiel #1
0
    def __notify(self, frame_type, headers=None, body=None):
        """
        Utility function for notifying listeners of incoming and outgoing messages
        
        \param frame_type the type of message
        
        \param headers the map of headers associated with the message
        
        \param body the content of the message
        """
        for listener in self.__listeners.values():
            if not hasattr(listener, 'on_%s' % frame_type):
                log.debug('listener %s has no method on_%s' %
                          (listener, frame_type))
                continue

            if frame_type == 'connecting':
                listener.on_connecting(self.__current_host_and_port)
                continue

            notify_func = getattr(listener, 'on_%s' % frame_type)
            params = backward.get_func_argcount(notify_func)
            if params >= 3:
                notify_func(headers, body)
            elif params == 2:
                notify_func(headers)
            else:
                notify_func()
Beispiel #2
0
    def __notify(self, frame_type, headers=None, body=None):
        """
        Utility function for notifying listeners of incoming and outgoing messages
        
        \param frame_type the type of message
        
        \param headers the map of headers associated with the message
        
        \param body the content of the message
        """
        for listener in self.__listeners.values():
            if not hasattr(listener, 'on_%s' % frame_type):
                log.debug('listener %s has no method on_%s' % (listener, frame_type))
                continue

            if frame_type == 'connecting':
                listener.on_connecting(self.__current_host_and_port)
                continue

            notify_func = getattr(listener, 'on_%s' % frame_type)
            params = backward.get_func_argcount(notify_func)
            if params >= 3:
                notify_func(headers, body)
            elif params == 2:
                notify_func(headers)
            else:
                notify_func()
Beispiel #3
0
    def __notify(self, frame_type, headers=None, body=None):
        """
        Utility function for notifying listeners of incoming and outgoing messages
        
        \param frame_type the type of message
        
        \param headers the map of headers associated with the message
        
        \param body the content of the message
        """
        if frame_type == 'receipt':
            # logic for wait-on-receipt notification
            self.__send_wait_condition.acquire()
            self.__receipts[headers['receipt-id']] = None
            self.__send_wait_condition.notify()
            self.__send_wait_condition.release()

        for listener in self.__listeners.values():
            if not hasattr(listener, 'on_%s' % frame_type):
                log.debug('listener %s has no method on_%s' % (listener, frame_type))
                continue

            if frame_type == 'connecting':
                listener.on_connecting(self.__current_host_and_port)
                continue

            notify_func = getattr(listener, 'on_%s' % frame_type)
            params = backward.get_func_argcount(notify_func)
            if params >= 3:
                notify_func(headers, body)
            elif params == 2:
                notify_func(headers)
            else:
                notify_func()
Beispiel #4
0
    def __notify(self, frame_type, headers=None, body=None):
        """
        Utility function for notifying listeners of incoming and outgoing messages
        
        \param frame_type the type of message
        
        \param headers the map of headers associated with the message
        
        \param body the content of the message
        """
        if frame_type == 'receipt':
            # logic for wait-on-receipt notification
            self.__send_wait_condition.acquire()
            self.__receipts[headers['receipt-id']] = None
            self.__send_wait_condition.notify()
            self.__send_wait_condition.release()

        for listener in self.__listeners.values():
            if not hasattr(listener, 'on_%s' % frame_type):
                log.debug('listener %s has no method on_%s' %
                          (listener, frame_type))
                continue

            if frame_type == 'connecting':
                listener.on_connecting(self.__current_host_and_port)
                continue

            notify_func = getattr(listener, 'on_%s' % frame_type)
            params = backward.get_func_argcount(notify_func)
            if params >= 3:
                notify_func(headers, body)
            elif params == 2:
                notify_func(headers)
            else:
                notify_func()
Beispiel #5
0
    def __notify(self, frame_type, headers=None, body=None):
        """
        Utility function for notifying listeners of incoming and outgoing messages
        
        \param frame_type
            the type of message
        
        \param headers
            the map of headers associated with the message
        
        \param body
            the content of the message
        """
        if frame_type == 'receipt':
            # logic for wait-on-receipt notification
            self.__send_wait_condition.acquire()
            self.__send_wait_condition.notify()
            self.__send_wait_condition.release()

            receipt = headers['receipt-id']
            self.__receipts[receipt] = None

            # received a stomp 1.1 disconnect receipt
            if receipt == self.__disconnect_receipt:
                self.disconnect_socket()

        if frame_type == 'connected':
            self.connected = True
            self.__connect_wait_condition.acquire()
            self.__connect_wait_condition.notify()
            self.__connect_wait_condition.release()
            if 'version' not in headers.keys():
                if self.version >= 1.1:
                    log.warn('Downgraded STOMP protocol version to 1.0')
                self.version = 1.0
            if 'heart-beat' in headers.keys():
                self.heartbeats = utils.calculate_heartbeats(
                    headers['heart-beat'].replace(' ', '').split(','),
                    self.heartbeats)
                if self.heartbeats != (0, 0):
                    default_create_thread(self.__heartbeat_loop)

        for listener in self.__listeners.values():
            if not listener: continue
            if not hasattr(listener, 'on_%s' % frame_type):
                log.debug('listener %s has no method on_%s' %
                          (listener, frame_type))
                continue

            if frame_type == 'connecting':
                listener.on_connecting(self.__current_host_and_port)
                continue
            elif frame_type == 'disconnected':
                self.connected = False
                listener.on_disconnected()
                continue

            notify_func = getattr(listener, 'on_%s' % frame_type)
            notify_func(headers, body)
Beispiel #6
0
    def __notify(self, frame_type, headers=None, body=None):
        """
        Utility function for notifying listeners of incoming and outgoing messages
        
        \param frame_type
            the type of message
        
        \param headers
            the map of headers associated with the message
        
        \param body
            the content of the message
        """
        if frame_type == 'receipt':
            # logic for wait-on-receipt notification
            receipt = headers['receipt-id']
            self.__send_wait_condition.acquire()
            try:
                self.__receipts[receipt] = None
                self.__send_wait_condition.notify()
            finally:
                self.__send_wait_condition.release()
            
            # received a stomp 1.1 disconnect receipt
            if receipt == self.__disconnect_receipt:
                self.disconnect_socket()

        elif frame_type == 'connected':
            self.set_connected(True)

        elif frame_type == 'disconnected':
            self.set_connected(False)

        for listener in self.listeners.values():
            if not listener: continue
            if not hasattr(listener, 'on_%s' % frame_type):
                log.debug('listener %s has no method on_%s' % (listener, frame_type))
                continue
                
            if frame_type == 'connecting':
                listener.on_connecting(self.current_host_and_port)
                continue
            elif frame_type == 'disconnected':
                listener.on_disconnected()
                continue
            elif frame_type == 'heartbeat':
                listener.on_heartbeat()
                continue

            if frame_type == 'error' and self.connected == False:
                self.__connect_wait_condition.acquire()
                self.connection_error = True
                self.__connect_wait_condition.notify()
                self.__connect_wait_condition.release()

            notify_func = getattr(listener, 'on_%s' % frame_type)
            rtn = notify_func(headers, body)
            if rtn:
                return rtn
Beispiel #7
0
    def __notify(self, frame_type, headers=None, body=None):
        """
        Utility function for notifying listeners of incoming and outgoing messages
        
        \param frame_type
            the type of message
        
        \param headers
            the map of headers associated with the message
        
        \param body
            the content of the message
        """
        if frame_type == 'receipt':
            # logic for wait-on-receipt notification
            self.__send_wait_condition.acquire()
            self.__send_wait_condition.notify()
            self.__send_wait_condition.release()
            
            receipt = headers['receipt-id']
            self.__receipts[receipt] = None

            # received a stomp 1.1 disconnect receipt
            if receipt == self.__disconnect_receipt:
                self.disconnect_socket()

        if frame_type == 'connected':
            self.connected = True
            self.__connect_wait_condition.acquire()
            self.__connect_wait_condition.notify()
            self.__connect_wait_condition.release()
            if 'version' not in headers.keys():
                if self.version >= 1.1:
                    log.warn('Downgraded STOMP protocol version to 1.0')
                self.version = 1.0
            if 'heart-beat' in headers.keys():
                self.heartbeats = utils.calculate_heartbeats(headers['heart-beat'].replace(' ', '').split(','), self.heartbeats)
                if self.heartbeats != (0,0):
                    default_create_thread(self.__heartbeat_loop)

        for listener in self.__listeners.values():
            if not listener: continue
            if not hasattr(listener, 'on_%s' % frame_type):
                log.debug('listener %s has no method on_%s' % (listener, frame_type))
                continue

            if frame_type == 'connecting':
                listener.on_connecting(self.__current_host_and_port)
                continue
            elif frame_type == 'disconnected':
                self.connected = False
                listener.on_disconnected()
                continue

            notify_func = getattr(listener, 'on_%s' % frame_type)
            notify_func(headers, body)
Beispiel #8
0
    def notify(self, frame_type, headers=None, body=None):
        """
        Utility function for notifying listeners of incoming and outgoing messages
        
        \param frame_type
            the type of message
        
        \param headers
            the map of headers associated with the message
        
        \param body
            the content of the message
        """
        if frame_type == 'receipt':
            # logic for wait-on-receipt notification
            receipt = headers['receipt-id']
            self.__send_wait_condition.acquire()
            try:
                self.__receipts[receipt] = None
                self.__send_wait_condition.notify()
            finally:
                self.__send_wait_condition.release()

            # received a stomp 1.1+ disconnect receipt
            if receipt == self.__disconnect_receipt:
                self.disconnect_socket()

        elif frame_type == 'connected':
            self.set_connected(True)

        elif frame_type == 'disconnected':
            self.set_connected(False)

        rtn = None
        for listener in self.listeners.values():
            if not listener: continue
            if not hasattr(listener, 'on_%s' % frame_type):
                log.debug("listener %s has no method on_%s", listener,
                          frame_type)
                continue

            if frame_type == 'connecting':
                listener.on_connecting(self.current_host_and_port)
                continue
            elif frame_type == 'disconnected':
                listener.on_disconnected()
                continue
            elif frame_type == 'heartbeat':
                listener.on_heartbeat()
                continue

            if frame_type == 'error' and self.connected is False:
                self.__connect_wait_condition.acquire()
                self.connection_error = True
                self.__connect_wait_condition.notify()
                self.__connect_wait_condition.release()

            notify_func = getattr(listener, 'on_%s' % frame_type)
            rtn = notify_func(headers, body)
            if rtn:
                (headers, body) = rtn
        if rtn:
            return rtn