Skip to main content

Producer

Struct Producer 

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

Announces broadcasts to consumers over the network.

Implementations§

Source§

impl Producer

Source

pub fn new(info: Info) -> Self

Build a producer from an Info (identity + cache pool) with no scoped prefix and no pre-existing broadcasts. Prefer Info::produce / Origin::produce.

Source

pub fn with_stats(self, session: Session) -> Self

Attach an ingress stats context: broadcasts created through this handle (and any handle derived from it) are attributed to session on the subscriber (ingress) side. Pass stats::Session::default to opt out.

Source

pub fn with_linger(self, linger: Duration) -> Self

Set the linger (see Info::linger) for broadcasts created through this handle and any handle derived from it.

A broadcast adopts the window of the handle whose source created it (the first source at the path), so set this before handing the producer to whatever attaches sources through it (e.g. a session). Lets one supplier declare its own recovery promise, like a reconnecting client lingering for as long as its retry loop keeps trying, without reconfiguring the origin.

Source

pub fn info(&self) -> Info

This origin’s Info (identity + cache pool), the parent handle a broadcast created under this origin carries (see broadcast::Info::origin).

Source

pub fn create_broadcast( &self, path: impl AsPath, route: Route, ) -> Result<Producer, Error>

Create a broadcast at path, fed through the returned producer.

This is the sole way content enters an origin. The returned broadcast::Producer is a route source: the origin owns the broadcast consumers actually see, and splices its tracks across every source created at the same path (other local publishers, or sessions attaching announces from the network), always serving from the best broadcast::Route (live first, then lowest cost, then shortest hops with a deterministic tie-break). When the best source changes, tracks resume from the replacement at the first missing group; consumers never observe the swap.

route is the source’s initial metadata; update it with broadcast::Producer::set_route. The broadcast::Route::announce flag controls whether the path is announced: a non-live broadcast is invisible to Consumer::announced but stays reachable by exact path for subscribes and fetches (e.g. serving cached or on-demand content), so toggling live announces or unannounces without touching the broadcast.

The broadcast becomes visible to consumers asynchronously, shortly after this returns. Create tracks and register a broadcast::Producer::dynamic handler before awaiting, so the first consumer finds them.

End the broadcast with broadcast::Producer::finish; dropping it without finishing also works, but logs a warning. A finish closes and unannounces the path immediately once it was the last source. An unfinished drop is treated as an outage: the path survives for the origin’s Info::linger (zero by default), so a replacement source attaching within that window splices in without consumers noticing.

Fails with Error::Unauthorized if path is outside the prefixes this producer may publish under (after scope / with_root), or Error::BoundsExceeded if the full rooted path exceeds Path::MAX_PARTS. Must be called with a runtime available (it spawns the broadcast’s lifecycle task). Callers must not use a route whose hop chain contains this origin’s id (it would form a routing loop); relays filter such reflections before they reach here, checked by a debug_assert.

Source

pub fn scope(&self, prefixes: &[Path<'_>]) -> Option<Producer>

Returns a new Producer restricted to publishing under one of prefixes.

Returns None if there are no legal prefixes (the requested prefixes are disjoint from this producer’s current scope).

Source

pub fn dynamic(&self) -> Dynamic

Create a dynamic handler that picks up Consumer::request_broadcast calls for paths that are not announced.

This is the origin-level analogue of broadcast::Producer::dynamic: it serves broadcasts on demand rather than tracks. Crucially the served broadcasts are not announced, so Consumer::announced never sees them; they exist only as a fallback for a consumer that asks for an exact path with no live announcement. Drop the handler (and every clone) to reject pending requests.

Source

pub fn consume(&self) -> Consumer

Cheap read handle over this origin’s broadcast tree.

Use Consumer::announced to register interest and start receiving announcement events; the consumer itself does not allocate any channels.

Source

pub fn announces(&self) -> AnnounceProducer

Handle to the announcement stream for this producer’s subtree.

Symmetric counterpart to Self::consume; call AnnounceProducer::consume to get an AnnounceConsumer that receives announce / unannounce events.

Source

pub fn with_root(&self, prefix: impl AsPath) -> Option<Self>

Returns a new Producer that automatically strips out the provided prefix.

Returns None if the provided root is not authorized; when Self::scope was already used without a wildcard.

Source

pub fn root(&self) -> &Path<'_>

Returns the root that is automatically stripped from all paths.

Source

pub fn allowed(&self) -> impl Iterator<Item = &Path<'_>>

Iterate over the path prefixes this handle is permitted to publish or subscribe under.

Source

pub fn absolute(&self, path: impl AsPath) -> Path<'_>

Converts a relative path to an absolute path.

Trait Implementations§

Source§

impl Clone for Producer

Source§

fn clone(&self) -> Producer

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.
Source§

impl Deref for Producer

Source§

type Target = Origin

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

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> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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