//! Distribution stats provider for the runtime dashboard. //! //! The application implements `DistributionStatsProvider` to let the dashboard //! read a single node's distribution state (SWIM membership, Kademlia routing, //! LRU cache, etc.) without reaching out to other nodes. use std::sync::{Arc, Mutex}; use distribution::snapshot::DistributionNodeSnapshot; /// Trait for providing distribution stats to the dashboard. /// /// Implementations capture a point-in-time snapshot of the local /// `DistributedNode`'s state. The dashboard polls this every ~200ms. pub trait DistributionStatsProvider: Send + Sync { fn snapshot(&self) -> Option; } /// Simple implementation wrapping an `Arc>` where T implements /// a `snapshot()` method (e.g. `DistributedNode`). pub struct DistributionCollector { inner: Arc>, } impl DistributionCollector { pub fn new(inner: Arc>) -> Self { Self { inner } } } impl DistributionStatsProvider for DistributionCollector { fn snapshot(&self) -> Option { self.inner.lock().ok().map(|node| node.snapshot()) } }