nerve/integration/
plugin_traits.rs

1//! Plugin-Compatible Component Traits
2//!
3//! Provides simplified, dyn-compatible versions of component traits for use
4//! in the plugin integration system.
5
6use nerve_core_traits::NerveComponent;
7
8/// Simplified memory component interface for plugin system
9pub trait PluginMemoryComponent: NerveComponent {
10    /// Get current memory usage in bytes
11    fn memory_usage(&self) -> u64;
12
13    /// Get memory utilization percentage
14    fn memory_utilization(&self) -> f64;
15
16    /// Check if memory is critically low
17    fn is_memory_critical(&self) -> bool;
18}
19
20/// Simplified thread component interface for plugin system
21pub trait PluginThreadComponent: NerveComponent {
22    /// Get current thread count
23    fn thread_count(&self) -> usize;
24
25    /// Get maximum allowed threads
26    fn max_threads(&self) -> usize;
27
28    /// Get thread utilization percentage
29    fn thread_utilization(&self) -> f64;
30}
31
32/// Simplified node component interface for plugin system
33pub trait PluginNodeComponent: NerveComponent {
34    /// Get total node count
35    fn node_count(&self) -> usize;
36
37    /// Get node count by type
38    fn node_count_by_type(&self, node_type: nerve_core_types::NodeType) -> usize;
39
40    /// Get node health summary
41    fn node_health_summary(&self) -> PluginNodeHealthSummary;
42}
43
44/// Simplified communication component interface for plugin system
45pub trait PluginCommunicationComponent: NerveComponent {
46    /// Get message throughput (messages per second)
47    fn message_throughput(&self) -> f64;
48
49    /// Get error rate percentage
50    fn error_rate(&self) -> f64;
51}
52
53/// Plugin-compatible node health summary
54#[derive(Debug, Clone)]
55pub struct PluginNodeHealthSummary {
56    /// Overall health
57    pub overall_health: PluginNodeHealth,
58    /// Health by node type
59    pub health_by_type: std::collections::HashMap<nerve_core_types::NodeType, PluginNodeStatistics>,
60}
61
62/// Plugin-compatible node health status
63#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64pub enum PluginNodeHealth {
65    /// Node is healthy
66    Healthy,
67    /// Node has warnings
68    Warning,
69    /// Node is unhealthy
70    Unhealthy,
71}
72
73/// Plugin-compatible node statistics
74#[derive(Debug, Clone, Default)]
75pub struct PluginNodeStatistics {
76    /// Total node count
77    pub total_nodes: usize,
78    /// Healthy node count
79    pub healthy_nodes: usize,
80    /// Warning node count
81    pub warning_nodes: usize,
82    /// Unhealthy node count
83    pub unhealthy_nodes: usize,
84}
85
86impl Default for PluginNodeHealthSummary {
87    fn default() -> Self {
88        Self {
89            overall_health: PluginNodeHealth::Healthy,
90            health_by_type: std::collections::HashMap::new(),
91        }
92    }
93}