Skip to main content

HeartbeatTracker

Struct HeartbeatTracker 

Source
pub struct HeartbeatTracker { /* private fields */ }
Expand description

多连接心跳跟踪器

Implementations§

Source§

impl HeartbeatTracker

Source

pub fn new(config: HeartbeatConfig) -> Self

Source

pub fn config(&self) -> &HeartbeatConfig

获取配置

Source

pub async fn register(&self, connection_id: impl Into<String>)

注册一个连接(若已存在则保留原状态)

Source

pub async fn register_new(&self, connection_id: impl Into<String>)

注册一个连接(确保新建状态)

Source

pub async fn unregister(&self, connection_id: &str) -> Option<HeartbeatState>

注销连接

Source

pub async fn record_ping(&self, connection_id: &str, now_ms: i64) -> bool

记录发送 Ping

Source

pub async fn record_pong(&self, connection_id: &str, now_ms: i64) -> bool

记录收到 Pong

Source

pub async fn check_timeouts(&self, now_ms: i64) -> (Vec<String>, Vec<String>)

检查所有连接的超时状态,返回 (本次新增超时的连接列表, 本次被判定为失活的连接列表)

Source

pub async fn state(&self, connection_id: &str) -> Option<HeartbeatState>

获取指定连接的心跳状态

Source

pub async fn count(&self) -> usize

当前跟踪的连接数

Source

pub async fn dead_connections(&self) -> Vec<String>

获取所有失活连接的 ID

Source

pub async fn purge_dead(&self) -> usize

清理所有失活连接,返回被清理的数量

Source

pub async fn rtts(&self) -> Vec<(String, i64)>

获取所有连接的 RTT(毫秒),仅返回有有效 RTT 的

Trait Implementations§

Source§

impl Debug for HeartbeatTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.