acts_next/
builder.rs

1use std::sync::Arc;
2
3use crate::{Config, Engine, StoreAdapter};
4
5pub struct Builder {
6    config: Config,
7    store: Option<Arc<dyn StoreAdapter>>,
8}
9
10impl Default for Builder {
11    fn default() -> Self {
12        Self::new()
13    }
14}
15
16impl Builder {
17    pub fn new() -> Self {
18        Self {
19            config: Config::default(),
20            store: None,
21        }
22    }
23
24    pub fn set_config(&mut self, config: &Config) {
25        self.config = config.clone();
26    }
27
28    pub fn log_dir(mut self, log_dir: &str) -> Self {
29        self.config.log_dir = log_dir.to_string();
30        self
31    }
32
33    pub fn log_level(mut self, level: &str) -> Self {
34        self.config.log_level = level.to_string();
35        self
36    }
37
38    pub fn cache_size(mut self, size: usize) -> Self {
39        self.config.cache_cap = size;
40        self
41    }
42
43    pub fn data_dir(mut self, data_dir: &str) -> Self {
44        self.config.data_dir = data_dir.to_string();
45        self
46    }
47
48    pub fn db_name(mut self, db_name: &str) -> Self {
49        self.config.db_name = db_name.to_string();
50        self
51    }
52
53    pub fn tick_interval_secs(mut self, secs: u64) -> Self {
54        self.config.tick_interval_secs = secs;
55        self
56    }
57
58    pub fn max_message_retry_times(mut self, retry_times: i32) -> Self {
59        self.config.max_message_retry_times = retry_times;
60        self
61    }
62
63    pub fn store<STORE: StoreAdapter + Clone + 'static>(mut self, store: &STORE) -> Self {
64        self.store = Some(Arc::new(store.clone()));
65        self
66    }
67
68    pub fn build(&self) -> Engine {
69        Engine::new_with_config(&self.config, self.store.clone())
70    }
71}