Skip to main content

PluginRegistry

Struct PluginRegistry 

Source
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:

  1. Outer lock (self.plugins): A tokio::sync::Mutex<HashMap<...>> that guards the plugin map itself (registration, removal, iteration).
  2. Inner lock (each PluginEntry::plugin): A per-plugin Arc<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

Source

pub fn new( allow_list: Vec<String>, deny_list: Vec<String>, permission_policy: PermissionPolicy, ) -> Self

Source

pub fn is_allowed(&self, name: &str) -> bool

Source

pub async fn register(&self, plugin: Box<dyn Plugin>) -> Result<()>

Source

pub async fn init_all(&self) -> Vec<String>

Source

pub async fn execute_tool( &self, tool_name: &str, input: &Value, ) -> Result<ToolResult>

Source

pub async fn shutdown_all(&self)

Source

pub async fn find_tool(&self, tool_name: &str) -> Option<(String, ToolDef)>

Source

pub async fn list_plugins(&self) -> Vec<PluginInfo>

Source

pub async fn list_all_tools(&self) -> Vec<(String, ToolDef)>

Source

pub async fn disable_plugin(&self, name: &str) -> Result<()>

Source

pub async fn enable_plugin(&self, name: &str) -> Result<()>

Source

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).

Source

pub async fn plugin_count(&self) -> usize

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more