pub struct ServerStat {
pub host: String,
pub last_error_time: Option<SystemTime>,
pub last_error_code: Option<u16>,
pub consecutive_failures: u32,
/* private fields */
}Fields§
§host: String§last_error_time: Option<SystemTime>§last_error_code: Option<u16>§consecutive_failures: u32Implementations§
Source§impl ServerStat
impl ServerStat
pub fn new(host: &str) -> Self
pub fn update_speed(&self, speed: u64, is_multi: bool)
pub fn get_download_speed(&self) -> u64
pub fn get_single_avg_speed(&self) -> u64
pub fn get_multi_avg_speed(&self) -> u64
pub fn get_avg_speed(&self) -> u64
pub fn is_ok(&self) -> bool
pub fn set_error(&self)
pub fn reset_status(&self)
pub fn increment_counter(&self) -> u32
pub fn get_counter(&self) -> u32
pub fn reset_counter(&self)
pub fn is_fresh(&self, duration_secs: u64) -> bool
Sourcepub fn get_last_updated(&self) -> u64
pub fn get_last_updated(&self) -> u64
Get the last update timestamp as unix timestamp (0 if never updated).
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Check if server is available (not in cooldown due to consecutive failures)
Sourcepub fn get_last_error_time(&self) -> u64
pub fn get_last_error_time(&self) -> u64
Get the last error time as unix timestamp (0 if never failed)
Sourcepub fn get_last_error_code(&self) -> u16
pub fn get_last_error_code(&self) -> u16
Get the last error code (0 if never failed)
Sourcepub fn get_consecutive_failures(&self) -> u32
pub fn get_consecutive_failures(&self) -> u32
Get consecutive failure count
Sourcepub fn set_failure_info(&mut self, error_code: u16)
pub fn set_failure_info(&mut self, error_code: u16)
Set error tracking fields (for use by ServerStatMan::mark_failure) Note: Requires &mut self because these fields are not atomic
Sourcepub fn to_snapshot(&self) -> ServerStatSnapshot
pub fn to_snapshot(&self) -> ServerStatSnapshot
Convert to a serializable snapshot for persistence.
Extracts all atomic values into a plain struct suitable for JSON serialization. The snapshot captures the current state of all performance metrics and error tracking.
§Example
use aria2_core::selector::server_stat::ServerStat;
let stat = ServerStat::new("fast.mirror.com");
stat.update_speed(10000, false);
stat.increment_counter();
let snapshot = stat.to_snapshot();
assert_eq!(snapshot.host, "fast.mirror.com");
assert_eq!(snapshot.counter, 1);Sourcepub fn from_snapshot(snapshot: &ServerStatSnapshot) -> Self
pub fn from_snapshot(snapshot: &ServerStatSnapshot) -> Self
Restore from a serialized snapshot.
Creates a new ServerStat instance with all fields initialized from the snapshot data. Atomic fields are set to the snapshot values.
§Arguments
snapshot- The serialized server statistics to restore from
§Example
use aria2_core::selector::server_stat::{ServerStat, ServerStatSnapshot};
let snapshot = ServerStatSnapshot {
host: "restored.mirror.com".to_string(),
download_speed: 5000,
single_connection_avg_speed: 4500,
multi_connection_avg_speed: 8000,
last_updated: 1700000000,
status: 0,
counter: 10,
last_error_time: None,
last_error_code: 0,
consecutive_failures: 0,
};
let stat = ServerStat::from_snapshot(&snapshot);
assert_eq!(stat.host, "restored.mirror.com");
assert_eq!(stat.get_counter(), 10);Trait Implementations§
Source§impl Clone for ServerStat
impl Clone for ServerStat
Auto Trait Implementations§
impl !Freeze for ServerStat
impl RefUnwindSafe for ServerStat
impl Send for ServerStat
impl Sync for ServerStat
impl Unpin for ServerStat
impl UnsafeUnpin for ServerStat
impl UnwindSafe for ServerStat
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more