-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
runtime_system.rs
39 lines (32 loc) · 1.05 KB
/
runtime_system.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::runtime_manager::FaultRecovery;
use crate::supervisor::Supervisor;
use ego_tree::Tree;
use std::any::Any;
use std::sync::Arc;
use std::sync::Mutex;
use tokio::runtime::{Builder, Runtime};
pub struct RuntimeSystem {
pub runtime: Runtime,
pub registry: Arc<Mutex<Tree<Supervisor>>>,
}
impl RuntimeSystem {
pub fn start() -> Self {
let runtime: Runtime = Builder::new()
.panic_handler(|err| RuntimeSystem::panic_dispatcher(err))
.before_stop(|| {
debug!("System is stopping...");
})
.build()
.unwrap(); // Builder panic isn't a problem since we haven't started.
let root_supervisor = Supervisor::default().props("root".into(), "root".into());
let tree = ego_tree::Tree::new(root_supervisor);
let registry_tree = Arc::new(Mutex::new(tree));
RuntimeSystem {
runtime,
registry: registry_tree,
}
}
}
impl FaultRecovery for RuntimeSystem {
fn panic_dispatcher(_failure: Box<dyn Any + Send>) {}
}