pub struct SessionStore { /* private fields */ }Expand description
Per-session ad-break records.
A BTreeMap keyed by session id: the records here are small (one
BreakState per session, per the module’s design decision), so there
is no per-peer media state to bound with a cursor count the way
media-plane’s Trunk must. The store is nonetheless bounded: it holds at
most SessionLimits::max_sessions sessions, and Self::begin_break for a new session id
past that is Error::SessionStoreFull, so a flood of distinct ids cannot
grow it forever. This crate has no clock of its own: the caller feeds the
time in with Self::advance and calls Self::expire_idle to drop
sessions nobody has touched for a while; Self::end evicts one directly.
Implementations§
Source§impl SessionStore
impl SessionStore
Sourcepub fn new(limits: SessionLimits) -> Self
pub fn new(limits: SessionLimits) -> Self
An empty store held to the caller’s limits.
Sourcepub fn advance(&mut self, now: Instant)
pub fn advance(&mut self, now: Instant)
Moves the store’s clock to now (the caller’s own monotonic clock, the
broadcast_core::stage::Instant every sans-IO engine takes; a value
earlier than the current one is ignored). Records touched from now on
carry this time.
Sourcepub fn expire_idle(&mut self, ttl: Duration) -> usize
pub fn expire_idle(&mut self, ttl: Duration) -> usize
Evicts every session last touched (by Self::begin_break or
Self::resume) more than ttl before the store’s clock; returns
how many were evicted.
Sourcepub fn begin_break(
&mut self,
session_id: impl Into<String>,
state: BreakState,
) -> Result<()>
pub fn begin_break( &mut self, session_id: impl Into<String>, state: BreakState, ) -> Result<()>
Start a break for session_id. Errors with
Error::BreakAlreadyActive if the session already has an
unresumed break — call Self::resume or Self::end first — and
with Error::SessionStoreFull if session_id is new and the store
is at its bound, and with Error::DecisionTooLarge if state’s
decision exceeds SessionLimits::max_decision_items or
SessionLimits::max_decision_text_bytes.
Sourcepub fn resume(
&mut self,
session_id: &str,
resumed_at: ConditionedSplicePoint,
) -> Result<()>
pub fn resume( &mut self, session_id: &str, resumed_at: ConditionedSplicePoint, ) -> Result<()>
Record the resumption point for session_id’s active break. Errors
with Error::NoActiveBreak if there is no record for the session and
with Error::BreakAlreadyResumed if its break was already resumed
(the first resumption point is kept).
Sourcepub fn get(&self, session_id: &str) -> Option<&BreakState>
pub fn get(&self, session_id: &str) -> Option<&BreakState>
The current break record for session_id, if any. A resumed record
stays until Self::end evicts it, so a caller can still render the
just-ended break’s EXT-X-DATERANGE for one more playlist reload.
Sourcepub fn end(&mut self, session_id: &str) -> Option<BreakState>
pub fn end(&mut self, session_id: &str) -> Option<BreakState>
Evict session_id’s record entirely (session ended, or its break has
aged out of the sliding window). Returns the evicted record, if any.