reactive_graph_std_connector/
plugin.rs

1use crate::behaviour::component::PropagationCounterFactory;
2use reactive_graph_plugin_api::RelationBehaviourRegistry;
3use reactive_graph_plugin_api::RelationComponentBehaviourRegistry;
4use reactive_graph_plugin_api::prelude::plugin::*;
5use reactive_graph_plugin_api::prelude::providers::*;
6use reactive_graph_std_connector_model::BEHAVIOUR_PROPAGATION_COUNTER;
7use reactive_graph_std_connector_model::COMPONENT_BEHAVIOUR_PROPAGATION_COUNTER;
8
9use crate::behaviour::relation::complex_connector::COMPLEX_CONNECTOR_BEHAVIOURS;
10use crate::behaviour::relation::connector::CONNECTOR_BEHAVIOURS;
11
12export_plugin!({
13    "dependencies": [
14        { "name": "reactive-graph-std-base", "version": ">=0.10.0, <0.11.0" }
15    ]
16});
17
18#[injectable]
19pub trait ValuePlugin: Plugin + Send + Sync {}
20
21#[derive(Component)]
22pub struct ValuePluginImpl {
23    component_provider: Arc<dyn TypeProvider<Components> + Send + Sync>,
24
25    #[component(default = "component_provider_registry")]
26    component_provider_registry: Arc<dyn ComponentProviderRegistry + Send + Sync>,
27
28    relation_types_provider: Arc<dyn TypeProvider<RelationTypes> + Send + Sync>,
29
30    #[component(default = "relation_types_provider_registry")]
31    relation_type_provider_registry: Arc<dyn RelationTypeProviderRegistry + Send + Sync>,
32
33    #[component(default = "relation_behaviour_registry")]
34    relation_behaviour_registry: Arc<dyn RelationBehaviourRegistry + Send + Sync>,
35
36    #[component(default = "relation_component_behaviour_registry")]
37    relation_component_behaviour_registry: Arc<dyn RelationComponentBehaviourRegistry + Send + Sync>,
38}
39
40#[async_trait]
41#[component_alias]
42impl Plugin for ValuePluginImpl {
43    async fn activate(&self) -> Result<(), PluginActivationError> {
44        self.component_provider_registry.register_provider(self.component_provider.clone()).await;
45        self.relation_type_provider_registry
46            .register_provider(self.relation_types_provider.clone())
47            .await;
48
49        // Connector
50        self.relation_behaviour_registry.register_all(&CONNECTOR_BEHAVIOURS.get_factories()).await;
51
52        // Complex Connector
53        self.relation_behaviour_registry
54            .register_all(&COMPLEX_CONNECTOR_BEHAVIOURS.get_factories())
55            .await;
56
57        // PropagationCounter
58        let factory = Arc::new(PropagationCounterFactory::new(BEHAVIOUR_PROPAGATION_COUNTER.clone()));
59        self.relation_component_behaviour_registry
60            .register(COMPONENT_BEHAVIOUR_PROPAGATION_COUNTER.clone(), factory)
61            .await;
62
63        Ok(())
64    }
65
66    async fn deactivate(&self) -> Result<(), PluginDeactivationError> {
67        self.relation_component_behaviour_registry
68            .unregister(&COMPONENT_BEHAVIOUR_PROPAGATION_COUNTER)
69            .await;
70
71        self.relation_behaviour_registry
72            .unregister_all(&COMPLEX_CONNECTOR_BEHAVIOURS.to_relation_behaviour_tys())
73            .await;
74
75        self.relation_behaviour_registry
76            .unregister_all(&CONNECTOR_BEHAVIOURS.to_relation_behaviour_tys())
77            .await;
78
79        self.relation_type_provider_registry
80            .unregister_provider(self.relation_types_provider.id())
81            .await;
82        self.component_provider_registry.unregister_provider(self.component_provider.id()).await;
83        Ok(())
84    }
85}