pub struct Producer { /* private fields */ }Expand description
A producer for a track, used to create new groups.
Implementations§
Source§impl Producer
impl Producer
Sourcepub fn create_group(&self, frame: Frame) -> Result<Producer>
pub fn create_group(&self, frame: Frame) -> Result<Producer>
Create a group whose first frame is frame, whose timestamp is where the group starts:
its key on the track, in the track’s timescale.
It says nothing about the starts around it: groups may be created out of order, and
an aborted or evicted start created again. A gap it leaves is skipped only once the
producer says it will not fill it, with Self::skip_groups or Self::append_group.
A start already skipped is refused with Error::Skipped, and a timestamp that
doesn’t match the track with Error::TimestampMismatch, as Self::write_frame says.
A start another group holds is replaced: the new group takes the slot, and readers
already draining the old one keep their own handle. The same broadcast, track, and
group start always name the same content, and nothing checks it, as with
Self::append_group. Two writers that may race to one start use
Self::claim_group instead.
Sourcepub fn claim_group(&self, frame: Frame) -> Result<Option<Producer>>
pub fn claim_group(&self, frame: Frame) -> Result<Option<Producer>>
Self::create_group, unless another live group already holds the start: then
None, and that group is left alone. The first writer of a start wins.
Sourcepub fn create_frame(&self, frame: Info) -> Result<Producer>
pub fn create_frame(&self, frame: Info) -> Result<Producer>
Self::create_group with its first frame streamed: the group exists once this
returns, and frame::Producer::finish hands it back to write the rest.
Sourcepub fn has_group(&self, start: u64) -> bool
pub fn has_group(&self, start: u64) -> bool
Whether a live group holds start, the key Self::claim_group would find taken: for
a writer that skips the work of producing a group another writer already holds.
Sourcepub fn append_group(&self, frame: Frame) -> Result<Producer>
pub fn append_group(&self, frame: Frame) -> Result<Producer>
Create the next group, after every group this track holds, whose first frame is frame,
whose timestamp is where the group starts.
A timed track converts that timestamp into its timescale, as Self::write_frame does; a
scale-less track takes Timestamp::unscaled at the group’s key. A timestamp that
doesn’t match the track, or that its scale can’t hold, is Error::TimestampMismatch.
Appending says the producer will not go back, so it skips every start below the new
group that it never produced, from just past its previous append (before the first,
from the lowest group it created, or from 0 when it creates the track’s first group), as
Self::skip_groups would, replacing any drop there: consecutive appends name the span
between their starts. Those starts are then final: creating one is refused. A start at
or before a group this track holds is Error::TimestampMismatch, like a rewound frame.
The same broadcast, track, and group start always name the same content, and nothing checks it: the broadcast remembers nothing of an earlier producer of the name. A recreated track, or a restarted publisher keeping its identity, keeps its starts moving forward, as its media time does, or uses a new track name or identity. Reusing a start only corrupts this broadcast for its readers. Datagram sequences name no cached content and are exempt.
Sourcepub fn append_frame(&self, frame: Info) -> Result<Producer>
pub fn append_frame(&self, frame: Info) -> Result<Producer>
Self::append_group with its first frame streamed: the group exists once this
returns, and frame::Producer::finish hands it back to write the rest.
Sourcepub fn write_frame(&mut self, frame: Frame) -> Result<()>
pub fn write_frame(&mut self, frame: Frame) -> Result<()>
Append a group holding only frame, whose timestamp is where the group starts.
The timestamp is converted into the track’s timescale. On a scale-less track it is
Timestamp::unscaled at the group’s key. The group finishes after its frame,
since nothing says where it ends (see group::Producer::finish).
Sourcepub fn finish(self) -> Result<Finished>
pub fn finish(self) -> Result<Finished>
End the track after its highest group, returning the Finished track: no group at
or above that end can be created, but an older group below it still can.
Other clones of this producer stay open handles, and refuse a group at or past the end
with Error::Closed. Fails with Error::Closed if the track already declared an
end, or with the abort error.
Sourcepub fn fail(self, err: Error) -> Result<Finished>
pub fn fail(self, err: Error) -> Result<Finished>
End the track with err after its highest group, returning the Finished track: the
errored counterpart of Self::finish.
Unlike Self::abort, the track keeps its history: readers and fills still get every
group below the end, and a reader reaching the end gets err instead of the end of
stream. Fails as Self::finish does.
Sourcepub fn finish_at(&mut self, end: Position) -> Result<()>
pub fn finish_at(&mut self, end: Position) -> Result<()>
Declare the track’s exclusive end, possibly ahead of the live edge.
end is the first position that will never be produced. Position::group
ends before a group, so a track whose last group is 89 finishes at
Position::group(90). A mid-group end such as { group: 89, frame: 5 } also
caps group 89 at frames 0 to 4. Passing an end beyond the live edge records a
known ending before the remaining groups arrive (e.g. learning a track ends at
group 89 while only 87 has been received).
Groups and frames below end may still be created afterwards; anything at or past
it is rejected (Error::Closed). An end that would orphan a group or frame that
already exists is Error::ProtocolViolation. Consumers only see end-of-stream
once the live edge reaches the end’s group. Use Self::finish to finish exactly
at the live edge.
Repeating the declared end is a no-op, and a mid-group end may refine the group
boundary it falls just before (a peer may name only the boundary first). Any other
second end is Error::ProtocolViolation.
On a copy a session received, groups below the end may still be in flight: readers wait for a missing one until a grace passes, the subscription’s max delay or one second without one, before ending at the boundary.
The end is clean; Self::fail ends the track with an error.
Sourcepub fn start_at(&mut self, key: impl Into<Option<u64>>) -> Result<()>
pub fn start_at(&mut self, key: impl Into<Option<u64>>) -> Result<()>
Declare the first group the live feed serves (the wire’s SUBSCRIBE_START,
or the start the subscription itself requested): groups below key
are not waited for, so a reader waiting for one fails over instead of
stalling. One may still arrive late, and a fetch can still retrieve them.
Scoped to the current subscription’s demand, so a later declaration
replaces this one in either direction: a re-subscription may start
earlier, and a narrowed subscription skips groups an earlier declaration
still promised. Pass None to clear it, for demand at the live edge:
its floor is unknown until the feed declares one.
Resolves a start a subscriber session left pending.
Sourcepub fn drop_groups(&self, groups: Range<u64>, err: StreamError)
pub fn drop_groups(&self, groups: Range<u64>, err: StreamError)
Record that the publisher gave up groups with err: none will arrive, so a reader
waiting on one moves past it, a group still arriving in them ends with err, the
declared end does not wait for them, and a relay serving this track forwards the drop.
For a producer that knows a group existed but cannot produce it, such as a replay whose
copy was pruned; one that never will produce it says so with Self::skip_groups.
Sourcepub fn skip_groups(&self, groups: Range<u64>)
pub fn skip_groups(&self, groups: Range<u64>)
Declare that this producer will never produce groups: none will arrive, so a reader
waiting on one moves past it, the declared end does not wait for them, and a relay
serving this track forwards the skip (a lite-07 SUBSCRIBE_SKIP). Unlike a drop,
it ends no reader.
This and Self::append_group are the only sources of a skip: a gap between created
groups says nothing, since groups may be created out of order, so only the producer
knows a key will never exist. A skip is final: creating a group at a skipped
key is refused with Error::Skipped, and a later drop of it is ignored.
A skip replaces any drop of the same keys, whatever its error: a reader the drop already ended stays ended, and every later reader and relay sees the skip. A group already cached keeps what it is, since it was produced after all.
Sourcepub fn finished(&self) -> Option<Position>
pub fn finished(&self) -> Option<Position>
The exclusive end, once Self::finish or Self::finish_at declared one.
None while the track is still open ended. Both methods reject a second end, so
callers that may have already declared one check here first.
Sourcepub fn abort(self, err: Error) -> Result<()>
pub fn abort(self, err: Error) -> Result<()>
Abort the track with the given error.
Consumes the handle, since nothing can be written to an aborted track. Consumers
still draining get the finished groups, then the abort error. Open groups, fetched
copies included, are aborted with the same error and leave the cache, so a consumer
that already pulled one ends with it too, and their writers fail. The pool’s idle expiry (see
cache::Config::with_expiry) reclaims the rest, the latest group included, so a
stale Consumer can’t pin them in memory forever.
If the declared end had settled (the final key from
finish_at was reached and every group below it finished),
consumers get that end instead of the error, as after finish.
finish is deliberately not terminal: it declares the final
key, and lower-numbered groups may still be written afterwards.
Sourcepub fn abandon(self)
pub fn abandon(self)
End the track as dropping its last producer does, except it is never asked for again: a
track nobody wants closes cleanly at its live edge, and one a reader still wants aborts
with Error::Dropped. A track whose end was declared (finish_at)
is sealed at that end instead of aborted, so its readers end cleanly.
For a producer whose content the track’s next producer could not continue, such as a log
riding one group, where dropping would hand a reader still wanting the track to that next
producer. Decided under the lock a reader joins the track under, so one joining after
Demand reported the track idle reads Dropped rather than the clean close. Ends the
track for every clone and Requests, like abort.
Sourcepub fn poll_closed(&self, waiter: &Waiter) -> Poll<Result<()>>
pub fn poll_closed(&self, waiter: &Waiter) -> Poll<Result<()>>
Resolves once the track’s outcome is final: Ok once its declared end is reached
(its error, if declared with one), or the abort error. Every producer leaving without
either ends it cleanly at its live edge while nobody wants it, and with
Error::Dropped while a reader does and no broadcast asks for it again.
Sourcepub async fn closed(&self) -> Result<()>
pub async fn closed(&self) -> Result<()>
Resolves once the track’s outcome is final: Ok once its declared end is reached
(its error, if declared with one), or the abort error. Every producer leaving without
either ends it cleanly at its live edge while nobody wants it, and with
Error::Dropped while a reader does and no broadcast asks for it again.
Awaits poll_closed.
Sourcepub fn largest(&self) -> Option<Position>
pub fn largest(&self) -> Option<Position>
The track’s largest location: its newest group at the newest frame (0 while empty), None before any.
Sourcepub fn abort_handle(&self) -> AbortHandle
pub fn abort_handle(&self) -> AbortHandle
A handle that aborts the track without keeping it open, for an owner that hands this producer out and must end the track on its own shutdown.
Sourcepub fn demand(&self) -> Demand
pub fn demand(&self) -> Demand
Create a Demand: a cloneable, watch-only handle to this track’s
subscriber demand.
Lets a publisher gate work (e.g. on-demand capture) on whether anyone is subscribed, without the ability to publish frames or close the track. The handle is weak, so holding one neither keeps the track alive nor pins its cached groups.
Sourcepub fn consume(&self) -> Consumer
pub fn consume(&self) -> Consumer
Get a consumer handle for this in-process track.
Unlike a wire subscription, the info is already known, so a subscription opened from this handle resolves immediately.
Sourcepub fn subscribe(
&self,
subscription: impl Into<Option<Subscription>>,
) -> Subscriber
pub fn subscribe( &self, subscription: impl Into<Option<Subscription>>, ) -> Subscriber
Subscribing to this in-process track, resolving synchronously.
The info is fixed at creation, so there’s nothing to wait for (no
SUBSCRIBE_OK round trip). Pass None for Subscription::default.
Reads only the groups the subscription’s ranges cover. A group reached only through
live joins is skipped once the widest of their max convicts it, so the default
Start::LATEST delivers only the latest group; a history range delivers every group
it covers.
Sourcepub fn subscription(&self) -> Option<Subscription>
pub fn subscription(&self) -> Option<Subscription>
A non-blocking snapshot of the current aggregate subscription, or None
when there are no live subscribers. Unlike Self::subscription, this
doesn’t wait for a change or advance the change cursor.
Each live join’s max in the aggregate is the subscribers’ own, capped only by
the local cache ceiling (broadcast::Info::cache_duration). The publisher
enforces its own Info::max_age, which each reader’s lateness budget also
applies, so the demand asked upstream is the same before and after the info lands.
Sourcepub fn poll_subscription_changed(
&mut self,
waiter: &Waiter,
) -> Poll<Result<Option<Subscription>>>
pub fn poll_subscription_changed( &mut self, waiter: &Waiter, ) -> Poll<Result<Option<Subscription>>>
The aggregate subscription once it changes: the most demanding request across all
live subscribers, or None once the last one drops. Errors once the track is aborted.
Used by relays to forward downstream demand upstream (e.g. SUBSCRIBE_UPDATE).
Sourcepub async fn subscription_changed(&mut self) -> Result<Option<Subscription>>
pub async fn subscription_changed(&mut self) -> Result<Option<Subscription>>
The aggregate subscription once it changes: the most demanding request across all
live subscribers, or None once the last one drops. Errors once the track is aborted.
Used by relays to forward downstream demand upstream (e.g. SUBSCRIBE_UPDATE).
Awaits poll_subscription_changed.