Utility Plugin
The Utility Plugin is intended for any functionality
that does not fall into the domain of other plugins but still needs access to pntOS
resources.
This plugin can be used for a wide variety of purposes. A few examples could include:
Watching a registry group and recording values to a file for later analysis.
Monitoring system resources.
Publishing diagnostic information to the registry or out through the transport.
Calculating filter performance metrics upon shutdown.
Utility Plugin API
Like all plugin types, the Utility Plugin inherits from
CommonPlugin, and thus is required to implement the
init_plugin() and
shutdown_plugin() methods.
Unlike most other plugin types, the utility plugin API does not include any additional methods. This is because the functionality of a utility plugin will be specific to a particular implementation. While the API does not require additional methods, a utility plugin implementation can of course include internal methods supporting the operation of the plugin.
Important
As a reminder, plugins should only directly interact with each other through the API. Implementation-specific methods are not part of the API and must not be invoked by other plugins. Since the utility plugin API does not include unique methods, internal communication between a utility plugin and other plugins should occur via the registry.
Utility Plugin Implementations
Cobra currently includes a single utility plugin, the
DiagnosticLogPlugin. Upon initialization, this plugin
registers a callback to a particular registry group, as seen below:
def init_plugin(
self,
plugin_resources_location: str | None = None,
mediator: Mediator | None = None,
) -> None:
if mediator is None:
print('ERROR: DiagnosticLogPlugin requires a mediator.')
return
self.mediator: Mediator = mediator
kv = self.mediator.registry.batch_start(GROUP_TO_WATCH)
kv.request_notify(None, self._callback)
kv.batch_end()
Whenever a key in this registry group is added or modified, the _callback method saves it off.
Upon shutdown, the series of values associated with each key are recorded to a file in
HDF5 format via save_to_hdf5_file().
Note
In most cases, a utility plugin must spin up a thread inside init_plugin so that the plugin can
continually operate until it is eventually terminated by a call to shutdown_plugin. However, this
plugin does not have to actively monitor the registry group in a separate thread. Instead, the
callback will be executed by whichever thread updates the values in
the group.