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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use super::FdfsClient;
use crate::Result;
use crate::Version;
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct ClientOptions {
/// List of tracker server addresses in format "host:port"
pub tracker_addrs: Vec<String>,
/// Maximum number of connections per tracker server
pub max_connections: usize,
/// Timeout for establishing connections
pub connect_timeout: Duration,
/// Timeout for network I/O operations
pub network_timeout: Duration,
/// Timeout for validate connections in the pool
pub test_timeout: Duration,
/// Sets the duration to sleep between runs of the idle object evictor thread.
pub time_between_eviction_runs: Duration,
/// Sets the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor
pub min_evictable_idle_duration: Duration,
/// Set the maximum lifetime of individual connections.
pub max_lifetime: Duration,
/// Timeout for idle connections in the pool
pub idle_timeout: Duration,
/// Number of retries for failed operations
pub retry_count: usize,
/// Version for FastDFS server
pub version: Version,
}
impl Default for ClientOptions {
fn default() -> Self {
Self {
tracker_addrs: Default::default(),
max_connections: 10,
connect_timeout: Duration::from_secs(5),
network_timeout: Duration::from_secs(30),
test_timeout: Duration::from_secs(5),
time_between_eviction_runs: Duration::from_secs(120),
min_evictable_idle_duration: Duration::from_secs(10),
max_lifetime: Duration::from_secs(120 * 60),
idle_timeout: Duration::from_secs(60),
retry_count: 3,
version: Version::latest(),
}
}
}
impl ClientOptions {
/// Creates a new client configuration with tracker addresses
pub fn new<S: AsRef<str>>(tracker_addrs: Vec<S>) -> Self {
let tracker_addrs = tracker_addrs
.into_iter()
.map(|s| s.as_ref().to_string())
.collect();
Self {
tracker_addrs,
..Default::default()
}
}
/// Sets the maximum number of connections per server
pub fn max_connections(mut self, n: usize) -> Self {
self.max_connections = n;
self
}
/// Sets the connection timeout
pub fn connect_timeout(mut self, timeout: Duration) -> Self {
self.connect_timeout = timeout;
self
}
/// Sets the network timeout
pub fn network_timeout(mut self, timeout: Duration) -> Self {
self.network_timeout = timeout;
self
}
/// Timeout for validate connections in the pool
pub fn test_timeout(mut self, timeout: Duration) -> Self {
self.test_timeout = timeout;
self
}
/// Sets the duration to sleep between runs of the idle object evictor thread.
pub fn time_between_eviction_runs(mut self, duration: Duration) -> Self {
self.time_between_eviction_runs = duration;
self
}
/// Sets the minimum amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object evictor
pub fn min_evictable_idle_duration(mut self, duration: Duration) -> Self {
self.min_evictable_idle_duration = duration;
self
}
/// Set the maximum lifetime of individual connections.
pub fn max_lifetime(mut self, duration: Duration) -> Self {
self.max_lifetime = duration;
self
}
/// Sets the idle timeout
pub fn idle_timeout(mut self, timeout: Duration) -> Self {
self.idle_timeout = timeout;
self
}
/// Sets the retry count
pub fn retry_count(mut self, n: usize) -> Self {
self.retry_count = n;
self
}
/// Sets the server version
pub fn version(mut self, v: Version) -> Self {
self.version = v;
self
}
pub fn build(self) -> Result<FdfsClient> {
FdfsClient::new(self)
}
}