pub struct PluginRegistry { /* private fields */ }Expand description
Thread-safe registry for custom forecast models and anomaly detectors.
Plugins register factory functions keyed by name. The factories are called at runtime to create model/detector instances with user-supplied config.
All registration and lookup operations are lock-free (DashMap-backed) and safe under concurrent access. Registration uses atomic entry-based insertion to prevent TOCTOU races.
Implementations§
Source§impl PluginRegistry
impl PluginRegistry
Sourcepub fn register_model(
&self,
name: impl Into<String>,
factory: ModelFactory,
) -> Result<(), PluginError>
pub fn register_model( &self, name: impl Into<String>, factory: ModelFactory, ) -> Result<(), PluginError>
Register a custom forecast model factory.
Returns an error if the name is invalid or a model with the same name is already registered. Uses atomic entry insertion to prevent TOCTOU races.
Sourcepub fn register_model_with_info(
&self,
info: PluginInfo,
factory: ModelFactory,
) -> Result<(), PluginError>
pub fn register_model_with_info( &self, info: PluginInfo, factory: ModelFactory, ) -> Result<(), PluginError>
Register a custom forecast model factory with explicit metadata.
Sourcepub fn replace_model(
&self,
name: impl Into<String>,
factory: ModelFactory,
) -> Result<Option<PluginInfo>, PluginError>
pub fn replace_model( &self, name: impl Into<String>, factory: ModelFactory, ) -> Result<Option<PluginInfo>, PluginError>
Atomically replace a model factory. Inserts if not present.
Returns the previous PluginInfo if there was an existing registration.
Sourcepub fn replace_model_with_info(
&self,
info: PluginInfo,
factory: ModelFactory,
) -> Result<Option<PluginInfo>, PluginError>
pub fn replace_model_with_info( &self, info: PluginInfo, factory: ModelFactory, ) -> Result<Option<PluginInfo>, PluginError>
Atomically replace a model factory with explicit metadata.
Sourcepub fn create_model(
&self,
name: &str,
config: &Value,
) -> Result<Box<dyn ForecastModel>, PluginError>
pub fn create_model( &self, name: &str, config: &Value, ) -> Result<Box<dyn ForecastModel>, PluginError>
Create a forecast model instance by plugin name.
Sourcepub fn create_model_default(
&self,
name: &str,
) -> Result<Box<dyn ForecastModel>, PluginError>
pub fn create_model_default( &self, name: &str, ) -> Result<Box<dyn ForecastModel>, PluginError>
Create a forecast model with default (null) configuration.
Sourcepub fn try_create_model(
&self,
name: &str,
config: &Value,
) -> Option<Result<Box<dyn ForecastModel>, PluginError>>
pub fn try_create_model( &self, name: &str, config: &Value, ) -> Option<Result<Box<dyn ForecastModel>, PluginError>>
Try to create a forecast model if the plugin is registered.
Returns None if no plugin with the given name exists.
Returns Some(Err(...)) if the plugin exists but the factory fails.
Single DashMap lookup — no TOCTOU.
Sourcepub fn try_create_model_default(
&self,
name: &str,
) -> Option<Result<Box<dyn ForecastModel>, PluginError>>
pub fn try_create_model_default( &self, name: &str, ) -> Option<Result<Box<dyn ForecastModel>, PluginError>>
Try to create a forecast model with default config (single lookup).
Sourcepub fn model_info(&self, name: &str) -> Option<PluginInfo>
pub fn model_info(&self, name: &str) -> Option<PluginInfo>
Get metadata for a registered model plugin.
Sourcepub fn list_models(&self) -> Vec<String>
pub fn list_models(&self) -> Vec<String>
List all registered model plugin names (sorted).
Sourcepub fn list_model_infos(&self) -> Vec<PluginInfo>
pub fn list_model_infos(&self) -> Vec<PluginInfo>
List all registered model plugins with their metadata (sorted by name).
Sourcepub fn unregister_model(&self, name: &str) -> Option<PluginInfo>
pub fn unregister_model(&self, name: &str) -> Option<PluginInfo>
Unregister a model plugin. Returns the PluginInfo if it existed.
Sourcepub fn model_count(&self) -> usize
pub fn model_count(&self) -> usize
Number of registered model plugins.
Sourcepub fn register_detector(
&self,
name: impl Into<String>,
factory: DetectorFactory,
) -> Result<(), PluginError>
pub fn register_detector( &self, name: impl Into<String>, factory: DetectorFactory, ) -> Result<(), PluginError>
Register a custom anomaly detector factory.
Returns an error if the name is invalid or a detector with the same name is already registered. Uses atomic entry insertion to prevent TOCTOU races.
Sourcepub fn register_detector_with_info(
&self,
info: PluginInfo,
factory: DetectorFactory,
) -> Result<(), PluginError>
pub fn register_detector_with_info( &self, info: PluginInfo, factory: DetectorFactory, ) -> Result<(), PluginError>
Register a custom anomaly detector factory with explicit metadata.
Sourcepub fn replace_detector(
&self,
name: impl Into<String>,
factory: DetectorFactory,
) -> Result<Option<PluginInfo>, PluginError>
pub fn replace_detector( &self, name: impl Into<String>, factory: DetectorFactory, ) -> Result<Option<PluginInfo>, PluginError>
Atomically replace a detector factory. Inserts if not present.
Returns the previous PluginInfo if there was an existing registration.
Sourcepub fn replace_detector_with_info(
&self,
info: PluginInfo,
factory: DetectorFactory,
) -> Result<Option<PluginInfo>, PluginError>
pub fn replace_detector_with_info( &self, info: PluginInfo, factory: DetectorFactory, ) -> Result<Option<PluginInfo>, PluginError>
Atomically replace a detector factory with explicit metadata.
Sourcepub fn create_detector(
&self,
name: &str,
config: &Value,
) -> Result<Box<dyn AnomalyDetector>, PluginError>
pub fn create_detector( &self, name: &str, config: &Value, ) -> Result<Box<dyn AnomalyDetector>, PluginError>
Create an anomaly detector instance by plugin name.
Sourcepub fn create_detector_default(
&self,
name: &str,
) -> Result<Box<dyn AnomalyDetector>, PluginError>
pub fn create_detector_default( &self, name: &str, ) -> Result<Box<dyn AnomalyDetector>, PluginError>
Create an anomaly detector with default (null) configuration.
Sourcepub fn try_create_detector(
&self,
name: &str,
config: &Value,
) -> Option<Result<Box<dyn AnomalyDetector>, PluginError>>
pub fn try_create_detector( &self, name: &str, config: &Value, ) -> Option<Result<Box<dyn AnomalyDetector>, PluginError>>
Try to create an anomaly detector if the plugin is registered.
Returns None if no plugin with the given name exists.
Returns Some(Err(...)) if the plugin exists but the factory fails.
Single DashMap lookup — no TOCTOU.
Sourcepub fn try_create_detector_default(
&self,
name: &str,
) -> Option<Result<Box<dyn AnomalyDetector>, PluginError>>
pub fn try_create_detector_default( &self, name: &str, ) -> Option<Result<Box<dyn AnomalyDetector>, PluginError>>
Try to create an anomaly detector with default config (single lookup).
Sourcepub fn has_detector(&self, name: &str) -> bool
pub fn has_detector(&self, name: &str) -> bool
Check if a detector plugin is registered.
Sourcepub fn detector_info(&self, name: &str) -> Option<PluginInfo>
pub fn detector_info(&self, name: &str) -> Option<PluginInfo>
Get metadata for a registered detector plugin.
Sourcepub fn list_detectors(&self) -> Vec<String>
pub fn list_detectors(&self) -> Vec<String>
List all registered detector plugin names (sorted).
Sourcepub fn list_detector_infos(&self) -> Vec<PluginInfo>
pub fn list_detector_infos(&self) -> Vec<PluginInfo>
List all registered detector plugins with their metadata (sorted by name).
Sourcepub fn unregister_detector(&self, name: &str) -> Option<PluginInfo>
pub fn unregister_detector(&self, name: &str) -> Option<PluginInfo>
Unregister a detector plugin. Returns the PluginInfo if it existed.
Sourcepub fn detector_count(&self) -> usize
pub fn detector_count(&self) -> usize
Number of registered detector plugins.
Sourcepub fn total_plugins(&self) -> usize
pub fn total_plugins(&self) -> usize
Total number of registered plugins (models + detectors).
Sourcepub fn set_model_allowlist(&self, hashes: impl IntoIterator<Item = String>)
pub fn set_model_allowlist(&self, hashes: impl IntoIterator<Item = String>)
Set the SHA-256 hash allowlist for model plugins.
When the allowlist is non-empty, only plugins whose
PluginInfo::sha256_hash is present in the list are accepted.
Hashes should be lowercase hex-encoded.
Sourcepub fn set_detector_allowlist(&self, hashes: impl IntoIterator<Item = String>)
pub fn set_detector_allowlist(&self, hashes: impl IntoIterator<Item = String>)
Set the SHA-256 hash allowlist for detector plugins.
Trait Implementations§
Source§impl Debug for PluginRegistry
impl Debug for PluginRegistry
Auto Trait Implementations§
impl !Freeze for PluginRegistry
impl !RefUnwindSafe for PluginRegistry
impl !UnwindSafe for PluginRegistry
impl Send for PluginRegistry
impl Sync for PluginRegistry
impl Unpin for PluginRegistry
impl UnsafeUnpin for PluginRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more