use std::sync::atomic::Ordering;
use super::SubscriptionManager;
use crate::subscription::{SubscriptionConfig, SubscriptionId, SubscriptionMetrics};
impl SubscriptionManager {
pub fn subscription_count(&self) -> usize {
self.subscriptions.len()
}
pub fn watched_tables(&self) -> Vec<(String, usize)> {
self.table_index.iter().map(|entry| (entry.key().clone(), entry.value().len())).collect()
}
pub fn config(&self) -> &SubscriptionConfig {
&self.config
}
pub fn limit_exceeded_count(&self) -> usize {
self.limit_exceeded_count.load(Ordering::Relaxed)
}
pub fn result_set_exceeded_count(&self) -> usize {
self.result_set_exceeded_count.load(Ordering::Relaxed)
}
pub fn get_subscription_metrics(&self, id: SubscriptionId) -> Option<SubscriptionMetrics> {
self.subscriptions.get(&id).map(|sub| SubscriptionMetrics {
subscription_id: Some(sub.id),
updates_sent: sub.updates_sent,
updates_dropped: sub.updates_dropped,
channel_buffer_size: sub.channel_buffer_size,
channel_capacity: sub.notify_tx.capacity(),
slow_consumer_threshold_percent: sub.slow_consumer_threshold_percent,
})
}
pub fn get_all_metrics(&self) -> Vec<SubscriptionMetrics> {
self.subscriptions
.iter()
.map(|entry| {
let sub = entry.value();
SubscriptionMetrics {
subscription_id: Some(sub.id),
updates_sent: sub.updates_sent,
updates_dropped: sub.updates_dropped,
channel_buffer_size: sub.channel_buffer_size,
channel_capacity: sub.notify_tx.capacity(),
slow_consumer_threshold_percent: sub.slow_consumer_threshold_percent,
}
})
.collect()
}
}