reactive_graph_plugin_service_impl/
plugin_context_factory_impl.rs1use std::sync::Arc;
2use std::sync::RwLock;
3
4use async_trait::async_trait;
5use springtime_di::Component;
6use springtime_di::component_alias;
7
8use reactive_graph_behaviour_service_api::EntityBehaviourManager;
9use reactive_graph_behaviour_service_api::EntityBehaviourRegistry;
10use reactive_graph_behaviour_service_api::EntityComponentBehaviourManager;
11use reactive_graph_behaviour_service_api::EntityComponentBehaviourRegistry;
12use reactive_graph_behaviour_service_api::RelationBehaviourManager;
13use reactive_graph_behaviour_service_api::RelationBehaviourRegistry;
14use reactive_graph_behaviour_service_api::RelationComponentBehaviourManager;
15use reactive_graph_behaviour_service_api::RelationComponentBehaviourRegistry;
16use reactive_graph_command_api::CommandManager;
17use reactive_graph_config_api::ConfigManager;
18use reactive_graph_graphql_api::GraphQLQueryService;
19use reactive_graph_lifecycle::Lifecycle;
20use reactive_graph_plugin_api::PluginContext;
21use reactive_graph_plugin_delegates::CommandManagerDelegate;
22use reactive_graph_plugin_delegates::ComponentImportExportManagerDelegate;
23use reactive_graph_plugin_delegates::ComponentManagerDelegate;
24use reactive_graph_plugin_delegates::ComponentProviderRegistryDelegate;
25use reactive_graph_plugin_delegates::ConfigManagerDelegate;
26use reactive_graph_plugin_delegates::EntityBehaviourRegistryDelegate;
27use reactive_graph_plugin_delegates::EntityComponentBehaviourRegistryDelegate;
28use reactive_graph_plugin_delegates::EntityInstanceManagerDelegate;
29use reactive_graph_plugin_delegates::EntityTypeImportExportManagerDelegate;
30use reactive_graph_plugin_delegates::EntityTypeManagerDelegate;
31use reactive_graph_plugin_delegates::EntityTypeProviderRegistryDelegate;
32use reactive_graph_plugin_delegates::FlowInstanceManagerDelegate;
33use reactive_graph_plugin_delegates::FlowTypeImportExportManagerDelegate;
34use reactive_graph_plugin_delegates::FlowTypeManagerDelegate;
35use reactive_graph_plugin_delegates::FlowTypeProviderRegistryDelegate;
36use reactive_graph_plugin_delegates::GraphQLQueryServiceDelegate;
37use reactive_graph_plugin_delegates::RelationBehaviourRegistryDelegate;
38use reactive_graph_plugin_delegates::RelationComponentBehaviourRegistryDelegate;
39use reactive_graph_plugin_delegates::RelationInstanceManagerDelegate;
40use reactive_graph_plugin_delegates::RelationTypeImportExportManagerDelegate;
41use reactive_graph_plugin_delegates::RelationTypeManagerDelegate;
42use reactive_graph_plugin_delegates::RelationTypeProviderRegistryDelegate;
43use reactive_graph_plugin_delegates::TypeSystemEventManagerDelegate;
44use reactive_graph_plugin_delegates::WebResourceManagerDelegate;
45use reactive_graph_plugin_service_api::PluginContextFactory;
46use reactive_graph_reactive_service_api::ReactiveEntityManager;
47use reactive_graph_reactive_service_api::ReactiveFlowManager;
48use reactive_graph_reactive_service_api::ReactiveRelationManager;
49use reactive_graph_runtime_web_api::WebResourceManager;
50use reactive_graph_type_system_api::ComponentImportExportManager;
51use reactive_graph_type_system_api::ComponentManager;
52use reactive_graph_type_system_api::ComponentProviderRegistry;
53use reactive_graph_type_system_api::EntityTypeImportExportManager;
54use reactive_graph_type_system_api::EntityTypeManager;
55use reactive_graph_type_system_api::EntityTypeProviderRegistry;
56use reactive_graph_type_system_api::FlowTypeImportExportManager;
57use reactive_graph_type_system_api::FlowTypeManager;
58use reactive_graph_type_system_api::FlowTypeProviderRegistry;
59use reactive_graph_type_system_api::RelationTypeImportExportManager;
60use reactive_graph_type_system_api::RelationTypeManager;
61use reactive_graph_type_system_api::RelationTypeProviderRegistry;
62use reactive_graph_type_system_api::TypeSystemEventManager;
63
64use crate::PluginContextImpl;
65
66pub type PluginContextStorage = RwLock<Option<Arc<dyn PluginContext + Send + Sync>>>;
67
68fn create_plugin_context_storage() -> PluginContextStorage {
69 RwLock::new(None)
70}
71
72#[derive(Component)]
73pub struct PluginContextFactoryImpl {
74 component_manager: Arc<dyn ComponentManager + Send + Sync>,
76 component_import_export_manager: Arc<dyn ComponentImportExportManager + Send + Sync>,
77 component_provider_registry: Arc<dyn ComponentProviderRegistry + Send + Sync>,
78 entity_type_manager: Arc<dyn EntityTypeManager + Send + Sync>,
79 entity_type_import_export_manager: Arc<dyn EntityTypeImportExportManager + Send + Sync>,
80 entity_type_provider_registry: Arc<dyn EntityTypeProviderRegistry + Send + Sync>,
81 relation_type_manager: Arc<dyn RelationTypeManager + Send + Sync>,
82 relation_type_import_export_manager: Arc<dyn RelationTypeImportExportManager + Send + Sync>,
83 relation_type_provider_registry: Arc<dyn RelationTypeProviderRegistry + Send + Sync>,
84 flow_type_manager: Arc<dyn FlowTypeManager + Send + Sync>,
85 flow_type_import_export_manager: Arc<dyn FlowTypeImportExportManager + Send + Sync>,
86 flow_type_provider_registry: Arc<dyn FlowTypeProviderRegistry + Send + Sync>,
87 type_system_event_manager: Arc<dyn TypeSystemEventManager + Send + Sync>,
88 reactive_entity_manager: Arc<dyn ReactiveEntityManager + Send + Sync>,
90 reactive_relation_manager: Arc<dyn ReactiveRelationManager + Send + Sync>,
91 reactive_flow_manager: Arc<dyn ReactiveFlowManager + Send + Sync>,
92 entity_behaviour_manager: Arc<dyn EntityBehaviourManager + Send + Sync>,
94 entity_component_behaviour_manager: Arc<dyn EntityComponentBehaviourManager + Send + Sync>,
95 relation_behaviour_manager: Arc<dyn RelationBehaviourManager + Send + Sync>,
96 relation_component_behaviour_manager: Arc<dyn RelationComponentBehaviourManager + Send + Sync>,
97 entity_behaviour_registry: Arc<dyn EntityBehaviourRegistry + Send + Sync>,
99 entity_component_behaviour_registry: Arc<dyn EntityComponentBehaviourRegistry + Send + Sync>,
100 relation_behaviour_registry: Arc<dyn RelationBehaviourRegistry + Send + Sync>,
101 relation_component_behaviour_registry: Arc<dyn RelationComponentBehaviourRegistry + Send + Sync>,
102 graphql_query_service: Arc<dyn GraphQLQueryService + Send + Sync>,
104 web_resource_manager: Arc<dyn WebResourceManager + Send + Sync>,
105 config_manager: Arc<dyn ConfigManager + Send + Sync>,
107 command_manager: Arc<dyn CommandManager + Send + Sync>,
108
109 #[component(default = "create_plugin_context_storage")]
111 pub plugin_context: PluginContextStorage,
112}
113
114#[async_trait]
115#[component_alias]
116impl PluginContextFactory for PluginContextFactoryImpl {
117 fn construct_plugin_context(&self) {
118 let component_manager = ComponentManagerDelegate::new(self.component_manager.clone());
120 let component_import_export_manager = ComponentImportExportManagerDelegate::new(self.component_import_export_manager.clone());
121 let component_provider_registry = ComponentProviderRegistryDelegate::new(&self.component_provider_registry);
122 let entity_type_manager = EntityTypeManagerDelegate::new(self.entity_type_manager.clone());
123 let entity_type_import_export_manager = EntityTypeImportExportManagerDelegate::new(self.entity_type_import_export_manager.clone());
124 let entity_type_provider_registry = EntityTypeProviderRegistryDelegate::new(&self.entity_type_provider_registry);
125 let relation_type_manager = RelationTypeManagerDelegate::new(self.relation_type_manager.clone());
126 let relation_type_import_export_manager = RelationTypeImportExportManagerDelegate::new(self.relation_type_import_export_manager.clone());
127 let relation_type_provider_registry = RelationTypeProviderRegistryDelegate::new(&self.relation_type_provider_registry);
128 let flow_type_manager = FlowTypeManagerDelegate::new(self.flow_type_manager.clone());
129 let flow_type_import_export_manager = FlowTypeImportExportManagerDelegate::new(self.flow_type_import_export_manager.clone());
130 let flow_type_provider_registry = FlowTypeProviderRegistryDelegate::new(&self.flow_type_provider_registry);
131 let entity_instance_manager =
133 EntityInstanceManagerDelegate::new(self.component_manager.clone(), self.entity_type_manager.clone(), self.reactive_entity_manager.clone());
134 let relation_instance_manager =
135 RelationInstanceManagerDelegate::new(self.component_manager.clone(), self.relation_type_manager.clone(), self.reactive_relation_manager.clone());
136 let flow_instance_manager = FlowInstanceManagerDelegate::new(self.reactive_flow_manager.clone());
137 let entity_behaviour_registry = EntityBehaviourRegistryDelegate::new(
139 self.entity_behaviour_manager.clone(),
140 self.entity_behaviour_registry.clone(),
141 self.reactive_entity_manager.clone(),
142 );
143 let entity_component_behaviour_registry = EntityComponentBehaviourRegistryDelegate::new(
144 self.entity_component_behaviour_manager.clone(),
145 self.entity_component_behaviour_registry.clone(),
146 self.reactive_entity_manager.clone(),
147 );
148 let relation_behaviour_registry = RelationBehaviourRegistryDelegate::new(
149 self.relation_behaviour_manager.clone(),
150 self.relation_behaviour_registry.clone(),
151 self.reactive_relation_manager.clone(),
152 );
153 let relation_component_behaviour_registry = RelationComponentBehaviourRegistryDelegate::new(
154 self.relation_component_behaviour_manager.clone(),
155 self.relation_component_behaviour_registry.clone(),
156 self.reactive_relation_manager.clone(),
157 );
158 let graphql_query_service = GraphQLQueryServiceDelegate::new(self.graphql_query_service.clone());
160 let web_resource_manager = WebResourceManagerDelegate::new(self.web_resource_manager.clone());
161 let config_manager = ConfigManagerDelegate::new(self.config_manager.clone());
163 let type_system_event_manager = TypeSystemEventManagerDelegate::new(self.type_system_event_manager.clone());
164 let command_manager = CommandManagerDelegate::new(self.command_manager.clone());
165 let plugin_context = PluginContextImpl::new(
166 Arc::new(component_manager),
167 Arc::new(component_import_export_manager),
168 Arc::new(component_provider_registry),
169 Arc::new(entity_type_manager),
170 Arc::new(entity_type_import_export_manager),
171 Arc::new(entity_type_provider_registry),
172 Arc::new(relation_type_manager),
173 Arc::new(relation_type_import_export_manager),
174 Arc::new(relation_type_provider_registry),
175 Arc::new(flow_type_manager),
176 Arc::new(flow_type_import_export_manager),
177 Arc::new(flow_type_provider_registry),
178 Arc::new(type_system_event_manager),
179 Arc::new(entity_instance_manager),
180 Arc::new(relation_instance_manager),
181 Arc::new(flow_instance_manager),
182 Arc::new(entity_behaviour_registry),
183 Arc::new(entity_component_behaviour_registry),
184 Arc::new(relation_behaviour_registry),
185 Arc::new(relation_component_behaviour_registry),
186 Arc::new(config_manager),
187 Arc::new(graphql_query_service),
188 Arc::new(web_resource_manager),
189 Arc::new(command_manager),
190 );
191 let plugin_context = Arc::new(plugin_context);
192 let mut writer = self.plugin_context.write().unwrap();
193 let _ = writer.insert(plugin_context);
194 }
195
196 fn get(&self) -> Option<Arc<dyn PluginContext + Send + Sync>> {
197 let reader = self.plugin_context.read().unwrap();
198 if let Some(plugin_context) = reader.as_ref() {
199 return Some(plugin_context.clone());
200 }
201 None
202 }
203}
204
205#[async_trait]
206impl Lifecycle for PluginContextFactoryImpl {
207 async fn init(&self) {
208 self.construct_plugin_context();
209 }
210
211 async fn shutdown(&self) {}
212}