use super::Throughput;
use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct MinimumThroughputBodyOptions {
minimum_throughput: Throughput,
grace_period: Duration,
check_interval: Duration,
check_window: Duration,
}
impl MinimumThroughputBodyOptions {
pub fn builder() -> MinimumThroughputBodyOptionsBuilder {
Default::default()
}
pub fn to_builder(self) -> MinimumThroughputBodyOptionsBuilder {
MinimumThroughputBodyOptionsBuilder::new()
.minimum_throughput(self.minimum_throughput)
.grace_period(self.grace_period)
.check_interval(self.check_interval)
}
pub fn grace_period(&self) -> Duration {
self.grace_period
}
pub fn minimum_throughput(&self) -> Throughput {
self.minimum_throughput
}
pub(crate) fn check_window(&self) -> Duration {
self.check_window
}
pub fn check_interval(&self) -> Duration {
self.check_interval
}
}
impl Default for MinimumThroughputBodyOptions {
fn default() -> Self {
Self {
minimum_throughput: DEFAULT_MINIMUM_THROUGHPUT,
grace_period: DEFAULT_GRACE_PERIOD,
check_interval: DEFAULT_CHECK_INTERVAL,
check_window: DEFAULT_CHECK_WINDOW,
}
}
}
#[derive(Debug, Default, Clone)]
pub struct MinimumThroughputBodyOptionsBuilder {
minimum_throughput: Option<Throughput>,
check_interval: Option<Duration>,
grace_period: Option<Duration>,
}
const DEFAULT_CHECK_INTERVAL: Duration = Duration::from_millis(500);
const DEFAULT_GRACE_PERIOD: Duration = Duration::from_secs(0);
const DEFAULT_MINIMUM_THROUGHPUT: Throughput = Throughput {
bytes_read: 1,
per_time_elapsed: Duration::from_secs(1),
};
const DEFAULT_CHECK_WINDOW: Duration = Duration::from_secs(1);
impl MinimumThroughputBodyOptionsBuilder {
pub fn new() -> Self {
Default::default()
}
pub fn grace_period(mut self, grace_period: Duration) -> Self {
self.set_grace_period(Some(grace_period));
self
}
pub fn set_grace_period(&mut self, grace_period: Option<Duration>) -> &mut Self {
self.grace_period = grace_period;
self
}
pub fn minimum_throughput(mut self, minimum_throughput: Throughput) -> Self {
self.set_minimum_throughput(Some(minimum_throughput));
self
}
pub fn set_minimum_throughput(&mut self, minimum_throughput: Option<Throughput>) -> &mut Self {
self.minimum_throughput = minimum_throughput;
self
}
pub fn check_interval(mut self, check_interval: Duration) -> Self {
self.set_check_interval(Some(check_interval));
self
}
pub fn set_check_interval(&mut self, check_interval: Option<Duration>) -> &mut Self {
self.check_interval = check_interval;
self
}
pub fn build(self) -> MinimumThroughputBodyOptions {
MinimumThroughputBodyOptions {
grace_period: self.grace_period.unwrap_or(DEFAULT_GRACE_PERIOD),
minimum_throughput: self
.minimum_throughput
.unwrap_or(DEFAULT_MINIMUM_THROUGHPUT),
check_interval: self.check_interval.unwrap_or(DEFAULT_CHECK_INTERVAL),
check_window: DEFAULT_CHECK_WINDOW,
}
}
}
impl From<StalledStreamProtectionConfig> for MinimumThroughputBodyOptions {
fn from(value: StalledStreamProtectionConfig) -> Self {
MinimumThroughputBodyOptions {
grace_period: value.grace_period(),
minimum_throughput: DEFAULT_MINIMUM_THROUGHPUT,
check_interval: DEFAULT_CHECK_INTERVAL,
check_window: DEFAULT_CHECK_WINDOW,
}
}
}