pub struct ByteMerge { /* private fields */ }Expand description
The one bounded multi-input primitive in the byte layer: N byte sources
reduced to one output stream. See the module docs.
Implementations§
Source§impl ByteMerge
impl ByteMerge
Sourcepub fn new(policy: MergePolicy, num_sources: usize, max_queued: usize) -> Self
pub fn new(policy: MergePolicy, num_sources: usize, max_queued: usize) -> Self
Construct a merge for num_sources sources (0..num_sources),
applying policy, with its output queue bounded to max_queued
messages.
Panics if num_sources == 0, max_queued == 0, or (for
MergePolicy::Failover) primary/secondary are not both within
0..num_sources — all three are construction-time configuration
mistakes, not remote input, so they panic rather than returning a
Result a caller could ignore.
Sourcepub fn num_sources(&self) -> usize
pub fn num_sources(&self) -> usize
How many sources this merge accepts feed calls from.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Messages currently queued, awaiting ByteMerge::poll. Never
exceeds the max_queued bound this merge was constructed with.
Sourcepub fn feed(
&mut self,
source: SourceId,
msg: Bytes,
at: Timestamp,
) -> Result<(), MergeError>
pub fn feed( &mut self, source: SourceId, msg: Bytes, at: Timestamp, ) -> Result<(), MergeError>
Feed one discrete message from source, observed at at.
Whether it is forwarded to ByteMerge::poll depends on the policy:
every message is forwarded under MergePolicy::FirstArrival; under
MergePolicy::Failover only the currently-active source’s messages
are (see that variant’s docs for exactly when that is, and the
switch-back rule).
Returns MergeError::UnknownSource if source is out of range, or
MergeError::QueueFull if the output queue is already at its bound
— in both cases nothing from this call is buffered.
Sourcepub fn poll(&mut self) -> Option<(Bytes, Timestamp)>
pub fn poll(&mut self) -> Option<(Bytes, Timestamp)>
Pull the next merged message, in the order it was forwarded by
ByteMerge::feed.
Sourcepub fn next_deadline(&self) -> Option<Timestamp>
pub fn next_deadline(&self) -> Option<Timestamp>
When ByteMerge::on_deadline should next be called to check a
MergePolicy::Failover silence timeout.
None under MergePolicy::FirstArrival (arrival-driven, no clock
needed) and under Failover before primary has produced its first
message (see that variant’s docs).
Sourcepub fn on_deadline(&mut self, now: Timestamp)
pub fn on_deadline(&mut self, now: Timestamp)
Drive time-based transitions: under MergePolicy::Failover, switch
to secondary if primary has been silent for at least
silence_timeout as of now. A no-op under MergePolicy::FirstArrival.