pub struct PluginRegistry { /* private fields */ }Expand description
Central registry that owns all loaded plugin instances.
§Lock acquisition pattern
This registry uses a two-level locking scheme:
- Outer lock (
self.plugins): Atokio::sync::Mutex<HashMap<...>>that guards the plugin map itself (registration, removal, iteration). - Inner lock (each
PluginEntry::plugin): A per-pluginArc<tokio::sync::Mutex<Box<dyn Plugin>>>that guards access to individual plugin instances.
Several methods (e.g., execute_tool, find_tool, list_plugins,
list_all_tools) acquire the outer lock and then, while still holding it,
acquire one or more inner plugin locks. This nested acquisition is safe from
deadlocks because the inner locks are never held when attempting to acquire
the outer lock. However, it means that a slow plugin init() or
execute_tool() call can block all other registry operations for the
duration.
tools() on the Plugin trait is expected to be non-blocking (it returns a
Vec<ToolDef> synchronously) so the inner lock contention during tool
lookups should be negligible. If plugin execution latency becomes a concern,
consider cloning the Arc outside the outer lock and releasing the outer
lock before awaiting the inner one (as execute_tool already does).
Implementations§
Source§impl PluginRegistry
impl PluginRegistry
pub fn new( allow_list: Vec<String>, deny_list: Vec<String>, permission_policy: PermissionPolicy, ) -> Self
pub fn is_allowed(&self, name: &str) -> bool
pub async fn register(&self, plugin: Box<dyn Plugin>) -> Result<()>
pub async fn init_all(&self) -> Vec<String>
pub async fn execute_tool( &self, tool_name: &str, input: &Value, ) -> Result<ToolResult>
pub async fn shutdown_all(&self)
pub async fn find_tool(&self, tool_name: &str) -> Option<(String, ToolDef)>
pub async fn list_plugins(&self) -> Vec<PluginInfo>
pub async fn list_all_tools(&self) -> Vec<(String, ToolDef)>
pub async fn disable_plugin(&self, name: &str) -> Result<()>
pub async fn enable_plugin(&self, name: &str) -> Result<()>
Sourcepub async fn unregister(&self, name: &str) -> Result<()>
pub async fn unregister(&self, name: &str) -> Result<()>
Removes a plugin from the registry entirely, shutting it down first.
Unlike disable_plugin (which keeps the entry around so it can be
re-enabled), unregister drops the plugin and frees all associated
resources. This should be used when a plugin is permanently removed
(e.g., uninstalled or revoked by policy).