aws_smithy_runtime/client/http/body/minimum_throughput/
options.rsuse 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_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)
}
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
}
#[deprecated(note = "No longer used. Always returns Duration::from_millis(500)")]
pub fn check_interval(&self) -> Duration {
Duration::from_millis(500)
}
}
impl Default for MinimumThroughputBodyOptions {
fn default() -> Self {
Self {
minimum_throughput: DEFAULT_MINIMUM_THROUGHPUT,
grace_period: DEFAULT_GRACE_PERIOD,
check_window: DEFAULT_CHECK_WINDOW,
}
}
}
#[derive(Debug, Default, Clone)]
pub struct MinimumThroughputBodyOptionsBuilder {
minimum_throughput: Option<Throughput>,
check_window: Option<Duration>,
grace_period: Option<Duration>,
}
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
}
#[deprecated(
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."
)]
pub fn check_interval(self, _check_interval: Duration) -> Self {
self
}
#[deprecated(
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."
)]
pub fn set_check_interval(&mut self, _check_interval: Option<Duration>) -> &mut Self {
self
}
#[allow(unused)]
pub(crate) fn check_window(mut self, check_window: Duration) -> Self {
self.set_check_window(Some(check_window));
self
}
#[allow(unused)]
pub(crate) fn set_check_window(&mut self, check_window: Option<Duration>) -> &mut Self {
self.check_window = check_window;
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_window: self.check_window.unwrap_or(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_window: DEFAULT_CHECK_WINDOW,
}
}
}