def _prepare_start(self) -> None: log_queue = self.context.boot_kwargs['log_queue'] level = self.context.boot_kwargs.get('log_level', logging.INFO) setup_queue_logging(log_queue, level) self.event_bus.connect_no_wait() self.event_bus.broadcast(PluginStartedEvent(type(self))) self.do_start()
def broadcast(self, event: BaseEvent, exclude: BasePlugin = None) -> None: """ Notify every registered :class:`~trinity.extensibility.plugin.BasePlugin` about an event and check whether the plugin wants to start based on that event. If a plugin gets started it will cause a :class:`~trinity.extensibility.events.PluginStartedEvent` to get broadcasted to all other plugins, giving them the chance to start based on that. """ for plugin in self._plugin_store: if plugin is exclude: continue plugin.handle_event(event) if plugin in self._started_plugins: continue if not plugin.should_start(): continue plugin.start(None) self._started_plugins.append(plugin) self._logger.info("Plugin started: {}".format(plugin.name)) self.broadcast(PluginStartedEvent(plugin), plugin)
def _prepare_start(self) -> None: log_queue = self.context.boot_kwargs['log_queue'] level = self.context.boot_kwargs.get('log_level', logging.INFO) setup_queue_logging(log_queue, level) self.event_bus.connect_no_wait() self.event_bus.broadcast(PluginStartedEvent(type(self))) with self.context.trinity_config.process_id_file(self.normalized_name): self.do_start()
def start(self) -> None: """ Prepare the plugin to get started and eventually cause ``start`` to get called. """ self.running = True self._start() self.event_bus.broadcast( PluginStartedEvent(type(self)) ) self.logger.info("Plugin started: %s", self.name)
def start(self) -> None: """ Delegate to :meth:`~trinity.extensibility.plugin.BasePlugin._start` and set ``running`` to ``True``. Broadcast a :class:`~trinity.extensibility.events.PluginStartedEvent` on the :class:`~lahja.eventbus.EventBus` and hence allow other plugins to act accordingly. """ self.running = True self._start() self.event_bus.broadcast( PluginStartedEvent(type(self)) ) self.logger.info("Plugin started: %s", self.name)
async def _prepare_start(self) -> None: # prevent circular import from trinity.event_bus import AsyncioEventBusService self._event_bus_service = AsyncioEventBusService( self.boot_info.trinity_config, self.normalized_name, ) asyncio.ensure_future(self._event_bus_service.run()) await self._event_bus_service.wait_event_bus_available() self._event_bus = self._event_bus_service.get_event_bus() await self.event_bus.broadcast(PluginStartedEvent(type(self))) self.do_start()
def start(self) -> None: """ Delegate to :meth:`~trinity.extensibility.plugin.BasePlugin.do_start` and set ``running`` to ``True``. Broadcast a :class:`~trinity.extensibility.events.PluginStartedEvent` on the event bus and hence allow other plugins to act accordingly. """ if self._status in INVALID_START_STATUS: raise InvalidPluginStatus( f"Can not start plugin when the plugin status is {self.status}" ) self._status = PluginStatus.STARTED self.do_start() self.event_bus.broadcast_nowait(PluginStartedEvent(type(self))) self.logger.info("Plugin started: %s", self.name)
async def _prepare_start(self) -> None: connection_config = ConnectionConfig.from_name( self.normalized_name, self.boot_info.trinity_config.ipc_dir) await self.event_bus.start_serving(connection_config) await self.event_bus.connect_to_endpoints( ConnectionConfig.from_name(MAIN_EVENTBUS_ENDPOINT, self.boot_info.trinity_config.ipc_dir)) # This makes the `main` process aware of this Endpoint which will then propagate the info # so that every other Endpoint can connect directly to the plugin Endpoint await self.event_bus.announce_endpoint() await self.event_bus.broadcast(PluginStartedEvent(type(self))) # Whenever new EventBus Endpoints come up the `main` process broadcasts this event # and we connect to every Endpoint directly self.event_bus.auto_connect_new_announced_endpoints() self.do_start()
async def monitoring(normalized_name: str, trinity_config: TrinityConfig) -> None: event_bus = TrinityEventBusEndpoint("monitoring_ui") connection_config = ConnectionConfig.from_name( normalized_name, trinity_config.ipc_dir, ) await event_bus.start() await event_bus.start_server(connection_config.path) await event_bus.connect_to_endpoints( ConnectionConfig.from_name(MAIN_EVENTBUS_ENDPOINT, trinity_config.ipc_dir)) await event_bus.announce_endpoint() await event_bus.broadcast(PluginStartedEvent(type(MonitoringPlugin))) asyncio.ensure_future(event_bus.auto_connect_new_announced_endpoints()) event_bus.subscribe(NewBlockHashesEvent, lambda event: logging.info(event.msg))
def _prepare_start(self) -> None: log_queue = self.context.boot_kwargs['log_queue'] level = self.context.boot_kwargs.get('log_level', logging.INFO) setup_queue_logging(log_queue, level) connection_config = ConnectionConfig.from_name( self.normalized_name, self.context.trinity_config.ipc_dir) self.event_bus.start_serving_nowait(connection_config) self.event_bus.connect_to_endpoints_blocking( ConnectionConfig.from_name(MAIN_EVENTBUS_ENDPOINT, self.context.trinity_config.ipc_dir)) # This makes the `main` process aware of this Endpoint which will then propagate the info # so that every other Endpoint can connect directly to the plugin Endpoint self.event_bus.announce_endpoint() self.event_bus.broadcast(PluginStartedEvent(type(self))) # Whenever new EventBus Endpoints come up the `main` process broadcasts this event # and we connect to every Endpoint directly self.event_bus.auto_connect_new_announced_endpoints() with self.context.trinity_config.process_id_file(self.normalized_name): self.do_start()