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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::sync::*;
use std::thread;
use super::Run;
use primitives::input::{RunInput, NoOp};
pub struct Topology {
inputs: Vec<Box<RunInput>>,
runners: Vec<Box<Run>>,
}
impl Topology {
pub fn new(inputs: Vec<Box<RunInput>>, runners: Vec<Box<Run>>) -> Self {
Topology { inputs: inputs, runners: runners }
}
pub fn run(self) -> TopologyHandle {
info!("----> TOPOLOGY STARTING");
let Topology {inputs, runners} = self;
for runner in runners.into_iter() {
thread::spawn(move || {
runner.run();
});
}
let no_ops = Arc::new(Mutex::new(inputs.iter().map(|i| i.boxed_no_op()).collect::<Vec<Box<NoOp>>>()));
let term_txs = inputs.iter().map(|i| i.boxed_no_op()).collect::<Vec<Box<NoOp>>>();
for (idx, input) in inputs.into_iter().enumerate() {
let no_ops_i = no_ops.clone();
thread::spawn(move || {
input.run(idx, no_ops_i);
});
}
info!("----> TOPOLOGY RUNNING...");
TopologyHandle {
term_txs: term_txs,
}
}
}
pub struct TopologyHandle {
term_txs: Vec<Box<NoOp>>,
}
impl TopologyHandle {
pub fn stop(&mut self) {
for tx in self.term_txs.iter() {
tx.send_exit();
}
debug!("----> TOPOLOGY DROPPED");
}
}