aws_smithy_runtime/client/http/body/minimum_throughput/
options.rs1use super::Throughput;
7use aws_smithy_runtime_api::client::stalled_stream_protection::{
8 StalledStreamProtectionConfig, DEFAULT_GRACE_PERIOD,
9};
10use std::time::Duration;
11
12#[derive(Debug, Clone)]
14pub struct MinimumThroughputBodyOptions {
15 minimum_throughput: Throughput,
17
18 grace_period: Duration,
29
30 check_window: Duration,
34}
35
36impl MinimumThroughputBodyOptions {
37 pub fn builder() -> MinimumThroughputBodyOptionsBuilder {
39 Default::default()
40 }
41
42 pub fn to_builder(self) -> MinimumThroughputBodyOptionsBuilder {
44 MinimumThroughputBodyOptionsBuilder::new()
45 .minimum_throughput(self.minimum_throughput)
46 .grace_period(self.grace_period)
47 }
48
49 pub fn grace_period(&self) -> Duration {
55 self.grace_period
56 }
57
58 pub fn minimum_throughput(&self) -> Throughput {
60 self.minimum_throughput
61 }
62
63 pub(crate) fn check_window(&self) -> Duration {
64 self.check_window
65 }
66
67 #[deprecated(note = "No longer used. Always returns Duration::from_millis(500)")]
69 pub fn check_interval(&self) -> Duration {
70 Duration::from_millis(500)
71 }
72}
73
74const DEFAULT_MINIMUM_THROUGHPUT: Throughput = Throughput {
75 bytes_read: 1,
76 per_time_elapsed: Duration::from_secs(1),
77};
78
79const DEFAULT_CHECK_WINDOW: Duration = Duration::from_secs(1);
80
81impl Default for MinimumThroughputBodyOptions {
82 fn default() -> Self {
83 Self {
84 minimum_throughput: DEFAULT_MINIMUM_THROUGHPUT,
85 grace_period: DEFAULT_GRACE_PERIOD,
86 check_window: DEFAULT_CHECK_WINDOW,
87 }
88 }
89}
90
91#[derive(Debug, Default, Clone)]
93pub struct MinimumThroughputBodyOptionsBuilder {
94 minimum_throughput: Option<Throughput>,
95 check_window: Option<Duration>,
96 grace_period: Option<Duration>,
97}
98
99impl MinimumThroughputBodyOptionsBuilder {
100 pub fn new() -> Self {
102 Default::default()
103 }
104
105 pub fn grace_period(mut self, grace_period: Duration) -> Self {
109 self.set_grace_period(Some(grace_period));
110 self
111 }
112
113 pub fn set_grace_period(&mut self, grace_period: Option<Duration>) -> &mut Self {
117 self.grace_period = grace_period;
118 self
119 }
120
121 pub fn minimum_throughput(mut self, minimum_throughput: Throughput) -> Self {
123 self.set_minimum_throughput(Some(minimum_throughput));
124 self
125 }
126
127 pub fn set_minimum_throughput(&mut self, minimum_throughput: Option<Throughput>) -> &mut Self {
129 self.minimum_throughput = minimum_throughput;
130 self
131 }
132
133 #[deprecated(
135 note = "No longer used. The check interval is now based on the check window (not currently configurable). Open an issue if you need to configure the check window."
136 )]
137 pub fn check_interval(self, _check_interval: Duration) -> Self {
138 self
139 }
140
141 #[deprecated(
143 note = "No longer used. The check interval is now based on the check window (not currently configurable). Open an issue if you need to configure the check window."
144 )]
145 pub fn set_check_interval(&mut self, _check_interval: Option<Duration>) -> &mut Self {
146 self
147 }
148
149 #[allow(unused)]
150 pub(crate) fn check_window(mut self, check_window: Duration) -> Self {
151 self.set_check_window(Some(check_window));
152 self
153 }
154 #[allow(unused)]
155 pub(crate) fn set_check_window(&mut self, check_window: Option<Duration>) -> &mut Self {
156 self.check_window = check_window;
157 self
158 }
159
160 pub fn build(self) -> MinimumThroughputBodyOptions {
164 MinimumThroughputBodyOptions {
165 grace_period: self.grace_period.unwrap_or(DEFAULT_GRACE_PERIOD),
166 minimum_throughput: self
167 .minimum_throughput
168 .unwrap_or(DEFAULT_MINIMUM_THROUGHPUT),
169 check_window: self.check_window.unwrap_or(DEFAULT_CHECK_WINDOW),
170 }
171 }
172}
173
174impl From<StalledStreamProtectionConfig> for MinimumThroughputBodyOptions {
175 fn from(value: StalledStreamProtectionConfig) -> Self {
176 MinimumThroughputBodyOptions {
177 grace_period: value.grace_period(),
178 minimum_throughput: DEFAULT_MINIMUM_THROUGHPUT,
179 check_window: DEFAULT_CHECK_WINDOW,
180 }
181 }
182}