reactive_graph_remotes_api/
remotes_manager.rs

1use std::collections::HashSet;
2
3use async_trait::async_trait;
4use springtime_di::injectable;
5
6use reactive_graph_lifecycle::Lifecycle;
7use reactive_graph_remotes_model::InstanceAddress;
8use reactive_graph_remotes_model::InstanceInfo;
9
10use crate::FailedToAddInstance;
11use crate::FailedToFetchRemoteInstances;
12use crate::FailedToUpdateInstance;
13
14/// Manages the list of remote instances.
15#[injectable]
16#[async_trait]
17pub trait RemotesManager: Send + Sync + Lifecycle {
18    /// Returns the remote instances.
19    fn get_all(&self) -> Vec<InstanceInfo>;
20
21    /// Returns the instance info with the given address.
22    fn get(&self, address: &InstanceAddress) -> Option<InstanceInfo>;
23
24    /// Returns true if the given address is registered.
25    fn has(&self, address: &InstanceAddress) -> bool;
26
27    /// Returns a list of the addresses of the remote instances.
28    fn get_all_addresses(&self) -> HashSet<InstanceAddress>;
29
30    /// Adds a remote instance.
31    async fn add(&self, address: &InstanceAddress) -> Result<InstanceInfo, FailedToAddInstance>;
32
33    /// Removes a remote instance.
34    fn remove(&self, address: &InstanceAddress) -> bool;
35
36    /// Removes all remote instances.
37    fn remove_all(&self);
38
39    /// Updates a remote instance.
40    async fn update(&self, address: &InstanceAddress) -> Result<InstanceInfo, FailedToUpdateInstance>;
41
42    /// Removes all remote instances.
43    async fn update_all(&self) -> Vec<InstanceInfo>;
44
45    /// Fetches and adds all remote instances of the given remote instance.
46    async fn fetch_and_add_remotes_from_remote(&self, address: &InstanceAddress) -> Result<Vec<InstanceInfo>, FailedToFetchRemoteInstances>;
47
48    /// Fetches and adds all remote instances of all remote instances.
49    async fn fetch_and_add_remotes_from_all_remotes(&self) -> Vec<InstanceInfo>;
50}