PluginManager

Struct PluginManager 

Source
pub struct PluginManager { /* private fields */ }
Expand description

Plugin manager

Manages the lifecycle of all plugins in the system. This includes:

  • Registering new plugins
  • Initializing plugins on startup
  • Enabling/disabling plugins at runtime
  • Executing plugin hooks
  • Shutting down plugins gracefully

§Thread Safety

The PluginManager is not thread-safe by itself. It should be wrapped in Arc<RwLock<PluginManager>> for concurrent access.

§Example

use llm_memory_graph::plugin::PluginManager;
use std::sync::Arc;
use tokio::sync::RwLock;

let mut manager = PluginManager::new();
// Register plugins...
manager.init_all().await?;

// Wrap for concurrent access
let manager = Arc::new(RwLock::new(manager));

Implementations§

Source§

impl PluginManager

Source

pub fn new() -> Self

Create a new plugin manager

Source

pub fn with_api_version(api_version: impl Into<String>) -> Self

Create a plugin manager with a specific API version

Source

pub fn register(&mut self, plugin: Arc<dyn Plugin>) -> Result<(), PluginError>

Register a plugin

Registers a new plugin with the manager. The plugin must not already be registered. After registration, the plugin is in the Registered state and must be initialized before it can be used.

§Errors

Returns an error if:

  • The plugin is already registered
  • The plugin’s API version is incompatible
Source

pub fn unregister(&mut self, name: &str) -> Result<(), PluginError>

Unregister a plugin

Removes a plugin from the manager. The plugin must be disabled before it can be unregistered.

§Errors

Returns an error if:

  • The plugin is not found
  • The plugin is still enabled
Source

pub async fn initialize(&mut self, name: &str) -> Result<(), PluginError>

Initialize a specific plugin

Initializes a registered plugin, calling its init() method. After successful initialization, the plugin is in the Initialized state.

Source

pub fn enable(&mut self, name: &str) -> Result<(), PluginError>

Enable a plugin

Enables an initialized plugin, making it active and ready to execute hooks.

§Errors

Returns an error if:

  • The plugin is not found
  • The plugin is not initialized
Source

pub fn disable(&mut self, name: &str) -> Result<(), PluginError>

Disable a plugin

Disables an enabled plugin, preventing it from executing hooks.

§Errors

Returns an error if the plugin is not found

Source

pub fn active_plugins(&self) -> Vec<Arc<dyn Plugin>>

Get active plugins

Returns a list of all enabled plugins that are ready to execute.

Source

pub fn all_plugins(&self) -> Vec<(PluginMetadata, PluginState)>

Get all plugins regardless of state

Source

pub fn get_state(&self, name: &str) -> Option<PluginState>

Get plugin state

Source

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

Check if a plugin is enabled

Source

pub async fn init_all(&mut self) -> Result<(), PluginError>

Initialize all registered plugins

Initializes all plugins that are in the Registered state. Continues even if some plugins fail to initialize.

§Errors

Returns an error if any plugin fails to initialize. The error contains information about the first failure encountered.

Source

pub fn enable_all(&mut self) -> Result<(), PluginError>

Enable all initialized plugins

Source

pub fn disable_all(&mut self) -> Result<(), PluginError>

Disable all plugins

Source

pub async fn shutdown_all(&mut self) -> Result<(), PluginError>

Shutdown all plugins

Calls shutdown() on all plugins and removes them from the manager.

Source

pub async fn execute_before_hooks( &self, hook_name: &str, context: &PluginContext, ) -> Result<(), PluginError>

Execute before hooks for all active plugins

Executes the specified hook on all enabled plugins in registration order. If any plugin returns an error, execution stops and the error is returned.

Source

pub async fn execute_after_hooks( &self, hook_name: &str, context: &PluginContext, ) -> Result<(), PluginError>

Execute after hooks for all active plugins

Executes the specified hook on all enabled plugins in registration order. Unlike before hooks, errors in after hooks are logged but don’t stop execution.

Source

pub fn load_from_directory( &mut self, _path: impl AsRef<Path>, ) -> Result<(), PluginError>

Load plugins from directory (dynamic loading - future)

This is a placeholder for future dynamic plugin loading functionality. Currently, plugins must be compiled into the application.

Source

pub fn list_plugins(&self) -> Vec<(PluginMetadata, PluginState)>

List all plugins with their metadata and state

Source

pub fn count_by_state(&self) -> HashMap<PluginState, usize>

Get plugin count by state

Trait Implementations§

Source§

impl Default for PluginManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<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