reactive_graph_behaviour_service_api/
entity_behaviour_registry.rs

1use std::sync::Arc;
2
3use async_trait::async_trait;
4use springtime_di::injectable;
5use uuid::Uuid;
6
7use reactive_graph_behaviour_model_api::prelude::*;
8use reactive_graph_graph::EntityTypeId;
9use reactive_graph_lifecycle::Lifecycle;
10use reactive_graph_reactive_model_impl::ReactiveEntity;
11
12#[injectable]
13#[async_trait]
14pub trait EntityBehaviourRegistry: Send + Sync + Lifecycle {
15    /// Registers a factory for creating entity behaviours.
16    fn register(&self, entity_behaviour_ty: EntityBehaviourTypeId, factory: Arc<dyn BehaviourFactory<Uuid, ReactiveEntity> + Send + Sync>);
17
18    /// Unregisters a factory for creating entity behaviours.
19    fn unregister(&self, entity_behaviour_ty: &EntityBehaviourTypeId);
20
21    /// Returns all entity behaviours.
22    fn get_all(&self) -> Vec<EntityBehaviourTypeId>;
23
24    /// Returns the entity behaviour factories for the given entity type.
25    fn get(&self, entity_ty: &EntityTypeId) -> Vec<Arc<dyn BehaviourFactory<Uuid, ReactiveEntity> + Send + Sync>>;
26
27    /// Returns the entity behaviour for the given behaviour type if the entity behaviour exists.
28    fn get_factory_by_behaviour_type(&self, behaviour_ty: &BehaviourTypeId) -> Option<Arc<dyn BehaviourFactory<Uuid, ReactiveEntity> + Send + Sync>>;
29
30    /// Returns the entity behaviours for the given entity type.
31    fn get_behaviour_types(&self, entity_ty: &EntityTypeId) -> Vec<EntityBehaviourTypeId>;
32
33    /// Returns the entity behaviour for the given behaviour type if the entity behaviour exists.
34    fn get_by_behaviour_type(&self, behaviour_ty: &BehaviourTypeId) -> Option<EntityBehaviourTypeId>;
35
36    /// Returns the count of entity behaviours.
37    fn count(&self) -> usize;
38}