nerve/integration/
plugin_adapters.rs1use crate::integration::plugin_traits::{
7 PluginCommunicationComponent, PluginMemoryComponent, PluginNodeComponent, PluginThreadComponent,
8};
9use nerve_core_errors::NerveResult;
10use nerve_core_traits::{CommunicationComponent, MemoryComponent, NerveComponent, NodeComponent, ThreadComponent};
11use nerve_core_types::{ComponentId, ComponentType, SystemStatistics};
12use nerve_memory::MemoryManager;
13use nerve_thread::ThreadManager;
14use nerve_node::NodeManager;
15use nerve_communication::CommunicationManager;
16use std::sync::Arc;
17
18pub struct MemoryComponentAdapter {
20 component: Arc<MemoryManager>,
21}
22
23impl MemoryComponentAdapter {
24 pub fn new(component: Arc<MemoryManager>) -> Self {
25 Self { component }
26 }
27}
28
29impl NerveComponent for MemoryComponentAdapter {
30 fn id(&self) -> &ComponentId {
31 self.component.id()
32 }
33
34 fn component_type(&self) -> ComponentType {
35 self.component.component_type()
36 }
37
38 fn is_healthy(&self) -> bool {
39 self.component.is_healthy()
40 }
41
42 fn get_statistics(&self) -> SystemStatistics {
43 self.component.get_statistics()
44 }
45
46 fn reset_statistics(&mut self) {
47 }
50
51 fn shutdown(&mut self) -> NerveResult<()> {
52 Ok(())
55 }
56}
57
58impl PluginMemoryComponent for MemoryComponentAdapter {
59 fn memory_usage(&self) -> u64 {
60 self.component.memory_usage()
61 }
62
63 fn memory_utilization(&self) -> f64 {
64 self.component.memory_utilization()
65 }
66
67 fn is_memory_critical(&self) -> bool {
68 self.component.is_memory_critical()
69 }
70}
71
72pub struct ThreadComponentAdapter {
74 component: Arc<ThreadManager>,
75}
76
77impl ThreadComponentAdapter {
78 pub fn new(component: Arc<ThreadManager>) -> Self {
79 Self { component }
80 }
81}
82
83impl NerveComponent for ThreadComponentAdapter {
84 fn id(&self) -> &ComponentId {
85 self.component.id()
86 }
87
88 fn component_type(&self) -> ComponentType {
89 self.component.component_type()
90 }
91
92 fn is_healthy(&self) -> bool {
93 self.component.is_healthy()
94 }
95
96 fn get_statistics(&self) -> SystemStatistics {
97 self.component.get_statistics()
98 }
99
100 fn reset_statistics(&mut self) {
101 }
103
104 fn shutdown(&mut self) -> NerveResult<()> {
105 Ok(())
107 }
108}
109
110impl PluginThreadComponent for ThreadComponentAdapter {
111 fn thread_count(&self) -> usize {
112 self.component.thread_count()
113 }
114
115 fn max_threads(&self) -> usize {
116 self.component.max_threads()
117 }
118
119 fn thread_utilization(&self) -> f64 {
120 self.component.thread_utilization()
121 }
122}
123
124pub struct NodeComponentAdapter {
126 component: Arc<NodeManager>,
127}
128
129impl NodeComponentAdapter {
130 pub fn new(component: Arc<NodeManager>) -> Self {
131 Self { component }
132 }
133}
134
135impl NerveComponent for NodeComponentAdapter {
136 fn id(&self) -> &ComponentId {
137 self.component.id()
138 }
139
140 fn component_type(&self) -> ComponentType {
141 self.component.component_type()
142 }
143
144 fn is_healthy(&self) -> bool {
145 self.component.is_healthy()
146 }
147
148 fn get_statistics(&self) -> SystemStatistics {
149 self.component.get_statistics()
150 }
151
152 fn reset_statistics(&mut self) {
153 }
155
156 fn shutdown(&mut self) -> NerveResult<()> {
157 Ok(())
159 }
160}
161
162impl PluginNodeComponent for NodeComponentAdapter {
163 fn node_count(&self) -> usize {
164 self.component.node_count()
165 }
166
167 fn node_count_by_type(&self, node_type: nerve_core_types::NodeType) -> usize {
168 self.component.node_count_by_type(node_type)
169 }
170
171 fn node_health_summary(&self) -> crate::integration::plugin_traits::PluginNodeHealthSummary {
172 let original_summary = self.component.node_health_summary();
174 crate::integration::plugin_traits::PluginNodeHealthSummary::default()
175 }
176}
177
178pub struct CommunicationComponentAdapter {
180 component: Arc<CommunicationManager>,
181}
182
183impl CommunicationComponentAdapter {
184 pub fn new(component: Arc<CommunicationManager>) -> Self {
185 Self { component }
186 }
187}
188
189impl NerveComponent for CommunicationComponentAdapter {
190 fn id(&self) -> &ComponentId {
191 self.component.id()
192 }
193
194 fn component_type(&self) -> ComponentType {
195 self.component.component_type()
196 }
197
198 fn is_healthy(&self) -> bool {
199 self.component.is_healthy()
200 }
201
202 fn get_statistics(&self) -> SystemStatistics {
203 self.component.get_statistics()
204 }
205
206 fn reset_statistics(&mut self) {
207 }
209
210 fn shutdown(&mut self) -> NerveResult<()> {
211 Ok(())
213 }
214}
215
216impl PluginCommunicationComponent for CommunicationComponentAdapter {
217 fn message_throughput(&self) -> f64 {
218 self.component.message_throughput()
219 }
220
221 fn error_rate(&self) -> f64 {
222 self.component.error_rate()
223 }
224}