use std::collections::HashMap;
use std::sync::atomic::{AtomicU64, AtomicUsize};
use std::sync::Mutex;
use tokio::sync::{mpsc, watch};
use crate::http::events::TransportEvent;
use crate::http::server::handle::ServeToken;
use crate::http::server::ServeHandle;
use super::stats::PathInfo;
pub(in crate::endpoint) struct PathSubscriptions {
pub(in crate::endpoint) senders: Mutex<HashMap<u32, mpsc::UnboundedSender<PathInfo>>>,
}
pub(in crate::endpoint) struct SessionRuntime {
pub(in crate::endpoint) serve_handle: Mutex<Option<ServeHandle>>,
pub(in crate::endpoint) serve_started_gen: AtomicU64,
pub(in crate::endpoint) serve_stopped_gen: AtomicU64,
pub(in crate::endpoint) serve_done_rx: Mutex<Option<watch::Receiver<bool>>>,
pub(in crate::endpoint) closed_tx: watch::Sender<bool>,
pub(in crate::endpoint) closed_rx: watch::Receiver<bool>,
pub(in crate::endpoint) event_tx: mpsc::Sender<TransportEvent>,
pub(in crate::endpoint) event_rx: Mutex<Option<mpsc::Receiver<TransportEvent>>>,
pub(in crate::endpoint) path_subs: Mutex<HashMap<String, std::sync::Arc<PathSubscriptions>>>,
pub(in crate::endpoint) active_path_watchers: AtomicUsize,
}
impl SessionRuntime {
pub(in crate::endpoint) fn next_serve_token(&self) -> ServeToken {
let token = self
.serve_started_gen
.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
.wrapping_add(1);
ServeToken::new(token)
}
pub(in crate::endpoint) fn record_stopped_token(&self, token: ServeToken) {
self.serve_stopped_gen
.store(token.get(), std::sync::atomic::Ordering::Relaxed);
}
}