Exemplo n.º 1
0
    def add(self, plugin):
        """Register a plugin.

        The plugin's C{register} method will be called with this registry as
        its argument.

        If the plugin has a C{plugin_name} attribute, it will be possible to
        look up the plugin later with L{get_plugin}.
        """
        info("Registering plugin %s.", format_object(plugin))
        self._plugins.append(plugin)
        if hasattr(plugin, "plugin_name"):
            self._plugin_names[plugin.plugin_name] = plugin
        plugin.register(self)
Exemplo n.º 2
0
    def send_message(self, urgent):
        message = self.get_message()
        if message is not None:
            info("Queueing a message with updated data watcher info "
                 "for %s.", format_object(self))
            result = self.registry.broker.send_message(
                message, self._session_id, urgent=urgent)

            def persist_data(message_id):
                self.persist_data()

            result.addCallback(persist_data)
            result.addErrback(log_failure)
            return result
        return succeed(None)
Exemplo n.º 3
0
    def fire(self, event_type, *args, **kwargs):
        """Fire an event of a given type.

        Call all handlers registered for the given C{event_type}, in order
        of priority.

        @param event_type: The name of the event type to fire.
        @param args: Positional arguments to pass to the registered handlers.
        @param kwargs: Keyword arguments to pass to the registered handlers.
        """
        logging.debug("Started firing %s.", event_type)
        results = []
        # Make a copy of the handlers that are registered at this point in
        # time, so we have a stable list in case handlers are cancelled
        # dynamically by executing the handlers themselves.
        handlers = list(self._event_handlers.get(event_type, ()))
        for handler, priority in handlers:
            try:
                logging.debug("Calling %s for %s with priority %d.",
                              format_object(handler), event_type, priority)
                results.append(handler(*args, **kwargs))
            except KeyboardInterrupt:
                logging.exception(
                    "Keyboard interrupt while running event "
                    "handler %s for event type %r with "
                    "args %r %r.", format_object(handler), event_type, args,
                    kwargs)
                self.stop()
                raise
            except:
                logging.exception(
                    "Error running event handler %s for "
                    "event type %r with args %r %r.", format_object(handler),
                    event_type, args, kwargs)
        logging.debug("Finished firing %s.", event_type)
        return results
Exemplo n.º 4
0
 def failure(failure):
     text = "%s: %s" % (failure.type.__name__, failure.value)
     msg = ("Error occured running message handler %s with "
            "args %r %r.", format_object(callable), args, kwargs)
     log_failure(failure, msg=msg)
     return FAILED, text