pub struct SessionWindowProcessor<T: Clone> { /* private fields */ }Expand description
Stateful processor that groups a time-ordered event stream into session windows.
Call Self::process for each incoming event (events must arrive in
non-decreasing timestamp order). Call Self::flush at end-of-stream to close
any pending session. Completed windows are collected via Self::drain_sessions.
Implementations§
Source§impl<T: Clone> SessionWindowProcessor<T>
impl<T: Clone> SessionWindowProcessor<T>
Sourcepub fn new(config: SessionWindowConfig) -> Self
pub fn new(config: SessionWindowConfig) -> Self
Create a new processor with the given configuration.
Sourcepub fn process(&mut self, event: StreamEvent<T>) -> Result<(), StreamingError>
pub fn process(&mut self, event: StreamEvent<T>) -> Result<(), StreamingError>
Process an incoming event.
A new session is started if:
- There is no open session, or
- The gap since the previous event exceeds
gap_duration, or - The current session has exceeded
max_session_duration.
Sourcepub fn flush(&mut self)
pub fn flush(&mut self)
Force-close the currently open session (call at end of stream).
After flushing, any sessions that meet the min_events threshold are
available via Self::drain_sessions.
Sourcepub fn drain_sessions(&mut self) -> Vec<SessionWindow<T>>
pub fn drain_sessions(&mut self) -> Vec<SessionWindow<T>>
Drain and return all completed session windows.
The internal buffer is cleared; subsequent calls return an empty Vec
until more sessions are closed.
Sourcepub fn pending_event_count(&self) -> usize
pub fn pending_event_count(&self) -> usize
Number of events buffered in the currently open (not yet closed) session.
Sourcepub fn total_sessions_closed(&self) -> u64
pub fn total_sessions_closed(&self) -> u64
Total number of sessions that have been closed (includes discarded ones).