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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
use std::time::Duration;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Configuration {
pub thread_stack_size: usize,
pub middleware_thread_stack_size: usize,
pub stream_sender_timeout: u64,
pub track_causal_stability: bool,
pub batching: Batching,
}
impl Configuration {
pub fn get_stream_sender_timeout(&self) -> Duration {
Duration::from_micros(self.stream_sender_timeout)
}
}
pub fn read_configuration_file(
configuration_file_path: String,
) -> Result<Configuration, Box<dyn Error>> {
let mut configuration_string = String::new();
let mut file = File::open(configuration_file_path)?;
file.read_to_string(&mut configuration_string)?;
let configuration: Configuration = toml::from_str(&configuration_string)?;
Ok(configuration)
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Batching {
pub size: u64,
pub message_number: usize,
pub lower_timeout: u64,
pub upper_timeout: u64,
}
impl Batching {
pub fn get_lower_timeout(&self) -> Duration {
Duration::from_micros(self.lower_timeout)
}
pub fn get_upper_timeout(&self) -> Duration {
Duration::from_micros(self.upper_timeout)
}
}