Skip to main content

asteroid_mq/protocol/node/raft/cluster/
static.rs

1use std::collections::BTreeMap;
2
3use futures_util::future::pending;
4
5use crate::prelude::NodeId;
6
7use super::ClusterProvider;
8
9#[derive(Clone)]
10pub struct StaticClusterProvider {
11    nodes: BTreeMap<NodeId, String>,
12}
13
14impl StaticClusterProvider {
15    pub fn new(nodes: BTreeMap<NodeId, String>) -> Self {
16        Self { nodes }
17    }
18    pub fn singleton(id: NodeId, socket_addr: String) -> Self {
19        let mut nodes = BTreeMap::new();
20        nodes.insert(id, socket_addr);
21        Self { nodes }
22    }
23}
24impl ClusterProvider for StaticClusterProvider {
25    fn name(&self) -> std::borrow::Cow<'static, str> {
26        "static".into()
27    }
28    async fn next_update(&mut self) -> crate::Result<BTreeMap<NodeId, String>> {
29        pending().await
30    }
31    async fn pristine_nodes(&mut self) -> crate::Result<BTreeMap<NodeId, String>> {
32        Ok(self.nodes.clone())
33    }
34}