Plugin¶
PluginContext¶
-
class
trinity.extensibility.plugin.PluginContext(endpoint: trinity.endpoint.TrinityEventBusEndpoint, boot_info: trinity.extensibility.plugin.TrinityBootInfo)¶ The
PluginContextholds valuable contextual information and APIs to be used by a plugin. This includes the parsed arguments that were used to launchTrinityas well as anEndpointthat the plugin can use to connect to the event bus.The
PluginContextis set during startup and is guaranteed to exist by the time that a plugin receives itson_ready()call.-
args¶ Return the parsed arguments that were used to launch the application
-
event_bus¶ Return the
Endpointthat the plugin uses to connect to the event bus
-
trinity_config¶ Return the
TrinityConfig
-
BasePlugin¶
-
class
trinity.extensibility.plugin.BasePlugin¶ -
configure_parser(arg_parser: argparse.ArgumentParser, subparser: argparse._SubParsersAction) → None¶ Give the plugin a chance to amend the Trinity CLI argument parser. This hook is called before
on_ready()
-
do_start() → None¶ Perform the actual plugin start routine. In the case of a BaseIsolatedPlugin this method will be called in a separate process.
This method should usually be overwritten by subclasses with the exception of plugins that set
funcon theArgumentParserto redefine the entire host program.
-
event_bus¶ Get the
Endpointthat this plugin uses to connect to the event bus
-
name¶ Describe the name of the plugin.
-
normalized_name¶ The normalized (computer readable) name of the plugin
-
on_ready(manager_eventbus: trinity.endpoint.TrinityEventBusEndpoint) → None¶ Notify the plugin that it is ready to bootstrap itself. Plugins can rely on the
PluginContextto be set after this method has been called. Themanager_eventbusrefers to the instance of theEndpointthat thePluginManageruses which may or may not be the sameEndpointas the plugin uses depending on the type of the plugin. The plugin should use thisEndpointinstance to listen for events before the plugin has started.
-
ready(manager_eventbus: trinity.endpoint.TrinityEventBusEndpoint) → None¶ Set the
statustoPluginStatus.READYand delegate toon_ready()
-
running¶ Return
Trueif thestatusisPluginStatus.STARTED, otherwise returnFalse.
-
set_context(context: trinity.extensibility.plugin.PluginContext) → None¶ Set the
PluginContextfor this plugin.
-
start() → None¶ Delegate to
do_start()and setrunningtoTrue. Broadcast aPluginStartedEventon the event bus and hence allow other plugins to act accordingly.
-
status¶ Return the current
PluginStatusof the plugin.
-
BaseAsyncStopPlugin¶
-
class
trinity.extensibility.plugin.BaseAsyncStopPlugin¶ A
BaseAsyncStopPluginunwinds asynchronoulsy, hence needs to be awaited.-
coroutine
do_stop() → None¶ Asynchronously stop the plugin. Should be overwritten by subclasses.
-
coroutine
BaseMainProcessPlugin¶
-
class
trinity.extensibility.plugin.BaseMainProcessPlugin¶ A
BaseMainProcessPluginovertakes the whole main process early before any of the subsystems started. In that sense it redefines the whole meaning of thetrinitycommand.
BaseIsolatedPlugin¶
-
class
trinity.extensibility.plugin.BaseIsolatedPlugin¶ A
BaseIsolatedPluginruns in an isolated process and hence provides security and flexibility by not making assumptions about its internal operations.Such plugins are free to use non-blocking asyncio as well as synchronous calls. When an isolated plugin is stopped it does first receive a SIGINT followed by a SIGTERM soon after. It is up to the plugin to handle these signals accordingly.
-
process¶ Return the
Processcreated by the isolated plugin.
-
start() → None¶ Prepare the plugin to get started and eventually call
do_startin a separate process.
-
stop() → None¶ Set the
statusto STOPPED` but rely on thePluginManagerto tear down the process. This allows isolated plugins to be taken down concurrently without depending on a running event loop.
-