def create_plugin_context(self, plugin: BasePlugin, args: Namespace, trinity_config: TrinityConfig, boot_kwargs: Dict[str, Any]) -> PluginContext: # Plugins that run in a shared process all share the endpoint of the plugin manager context = PluginContext(self.endpoint) context.args = args context.trinity_config = trinity_config context.boot_kwargs = boot_kwargs return context
def create_plugin_context(self, plugin: BasePlugin, args: Namespace, trinity_config: TrinityConfig, boot_kwargs: Dict[str, Any]) -> PluginContext: if isinstance(plugin, BaseIsolatedPlugin): # Isolated plugins get an entirely new endpoint to be passed into that new process context = PluginContext(self.event_bus.create_endpoint( plugin.name)) context.args = args context.trinity_config = trinity_config context.boot_kwargs = boot_kwargs return context # A plugin that overtakes the main process never gets far enough to even get a context. # For now it should be safe to just return `None`. Maybe reconsider in the future. return None
def _create_context_for_plugin( self, plugin: BasePlugin, args: Namespace, chain_config: ChainConfig, boot_kwargs: Dict[str, Any]) -> PluginContext: context: PluginContext = None if plugin.process_scope in self.MAIN_ANS_SHARED_SCOPES: # A plugin that runs in a shared process as well as a plugin that overtakes the main # process uses the endpoint of the PluginManager which will either be the main # endpoint or the networking endpoint in the case of Trinity context = PluginContext(self._scope.endpoint) elif plugin.process_scope is PluginProcessScope.ISOLATED: # A plugin that runs in it's own process gets a new endpoint created to get # passed into that new process # mypy doesn't know it can only be that scope at this point. The `isinstance` # check avoids adding an ignore if isinstance(self._scope, MainAndIsolatedProcessScope): endpoint = self._scope.event_bus.create_endpoint(plugin.name) context = PluginContext(endpoint) else: Exception("Invariant: unreachable code path") context.args = args context.chain_config = chain_config context.boot_kwargs = boot_kwargs return context
def create_plugin_context(self, plugin: BasePlugin, boot_info: TrinityBootInfo) -> None: """ Create a :class:`~trinity.extensibility.plugin.PluginContext` that uses the :class:`~lahja.endpoint.Endpoint` of the :class:`~trinity.extensibility.plugin_manager.PluginManager` as the event bus that enables application wide, event-driven communication even across process boundaries. """ # Plugins that run in a shared process all share the endpoint of the plugin manager plugin.set_context(PluginContext(self.endpoint, boot_info))
def create_plugin_context(self, plugin: BasePlugin, boot_info: TrinityBootInfo) -> None: """ Create a :class:`~trinity.extensibility.plugin.PluginContext` that holds a reference to a dedicated new :class:`~lahja.endpoint.Endpoint` to enable plugins which run in their own isolated processes to connect to the central :class:`~lahja.endpoint.EventBus` that Trinity uses to enable application wide event-driven communication even across process boundaries. """ if isinstance(plugin, BaseIsolatedPlugin): # Isolated plugins get an entirely new endpoint to be passed into that new process plugin.set_context( PluginContext( self.event_bus.create_endpoint(plugin.name), boot_info, ))
def create_plugin_context(self, plugin: BasePlugin, boot_info: TrinityBootInfo) -> None: """ Create a :class:`~trinity.extensibility.plugin.PluginContext` that creates a new :class:`~lahja.endpoint.Endpoint` dedicated to the isolated plugin that runs in its own process. The :class:`~lahja.endpoint.Endpoint` enable application wide event-driven communication even across process boundaries. """ if isinstance(plugin, BaseIsolatedPlugin): # Isolated plugins use their own Endpoint that lives in the new process. It is only # created here for API symmetry. Endpoints are pickleable *before* they are connected, # which means, this Endpoint will be pickled and transferred into the new process # together with the rest of the `PluginContext`. plugin.set_context( PluginContext( TrinityEventBusEndpoint(), boot_info, ))