Skip to main content

Producer

Struct Producer 

Source
pub struct Producer { /* private fields */ }
Expand description

A producer for a track, used to create new groups.

Implementations§

Source§

impl Producer

Source

pub fn name(&self) -> &str

The track’s name, unique within its broadcast.

Source

pub fn broadcast(&self) -> &Info

The parent broadcast this track belongs to.

Source

pub fn info(&self) -> &Info

The properties this track was created with.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_closed(&self) -> bool

Return true if the track has been closed.

Source

pub fn largest(&self) -> Option<Position>

The track’s largest location: its newest group at the newest frame (0 while empty), None before any.

Source

pub fn is_clone(&self, other: &Self) -> bool

Return true if this is the same track.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn requests(&self) -> Requests

Create a Requests handle that serves on-demand fetches of uncached (old) groups. Most producers never need this; a relay creates one to fetch past groups from upstream.

Trait Implementations§

Source§

impl Clone for Producer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Consume<Consumer> for Producer

Source§

fn consume(&self) -> Consumer

Derive a read view (a consumer) from this handle.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more