Skip to main content

Producer

Struct Producer 

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

Publishes broadcasts and announces routes into an origin.

Implementations§

Source§

impl Producer

Source

pub fn new(config: Config) -> (Self, Driver)

Build a producer from a Config (identity + cache pool) with no scoped prefix and no pre-existing broadcasts, paired with the Driver that runs the origin’s lifecycle work.

Poll the driver with caller-supplied time for the origin to make progress. moq_tokio::origin::spawn wraps this for tokio callers.

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 peer(self) -> Self

Mark this handle (and any handle derived from it) as a cluster peer’s: every route it announces reports Source::Peer, and Consumer::local hides it.

Hand it to a session with another relay, so this origin can tell what entered here from what a peer forwarded. The hop chain cannot: a client and a peer each append one hop.

Source

pub fn config(&self) -> Config

This origin’s construction config.

Source

pub fn hop(&self) -> Hop

This origin’s hop identity.

Source

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

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

This is how local content enters an origin. The returned broadcast::Producer is a source: the origin owns the broadcast consumers actually see, and splices its tracks across every source created at the same path, preferring the newest. When the serving source changes, tracks resume from the replacement at the first missing group; consumers never observe the swap.

The broadcast exists for nobody until broadcast::Producer::announce: until then no announce cursor lists it and a request for its path fails with Error::Unroutable, for a consumer of this origin exactly as for a peer. Announce once the tracks a subscriber needs first exist. To serve paths on demand without publishing each one, use Self::dynamic.

Announcing is visible to local consumers before it returns; only lifecycle work (track serving, teardown) waits for the Driver to be polled. Register a broadcast::Producer::dynamic handler before announcing, so the first consumer finds the tracks it serves.

End the broadcast with broadcast::Producer::finish; dropping it without finishing also works, but logs a warning. Either way the path closes once it was the last source; an unfinished drop additionally aborts the spliced tracks with an error, so consumers observe a failure rather than a clean end.

Fails with Error::Unauthorized if path is outside the prefixes this producer may publish under (after scope), Error::BoundsExceeded if the full rooted path exceeds Path::MAX_PARTS, Error::InvalidPath if it holds a segment no pattern can spell (* or **), or Error::Closed once the origin’s Driver has been dropped.

Source

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

Create and advertise a broadcast in one call.

Source

pub fn dynamic( &self, prefix: impl AsPath, route: Route, ) -> Result<Dynamic, Error>

Advertise a route over prefix and serve the requests beneath it.

A route is always a prefix: it claims prefix and every path beneath it (the empty prefix claims every path). A service that only serves some of them, say pid/*.hang, advertises the covering prefix and refuses the rest as they are requested; consumers narrow with a Pattern locally. This is the one shape every wire carries, so a route means the same thing on every hop.

The advertisement is visible to Consumer::announced and forwarded by sessions for as long as the returned Dynamic (and every clone) lives. A consumer resolving a path under it through this route is handed to the handler as a Request to materialize on demand. This is how a service answers a whole subtree without publishing each path, and how sessions land the routes a peer announces to them; a publisher that knows its broadcasts advertises each one’s exact path with broadcast::Producer::announce instead, so subscribers can enumerate them.

The prefix must overlap this producer’s pattern scope. Individual requests remain authoritative and are refused when they do not match the scope.

Source

pub fn scope( &self, root: impl AsPath, patterns: &Patterns, ) -> Result<Producer, Error>

Returns a producer rooted at root and restricted to matching patterns.

root is relative to this producer’s root, and patterns are relative to the new root. Returns Error::Unauthorized when the requested scope has no overlap with this producer’s scope, or Error::BoundsExceeded when rooting the patterns would exceed the path limit.

Source

pub fn consume(&self) -> Consumer

Cheap read handle over this origin’s route table.

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

Source

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

Returns the root that is automatically stripped from all paths.

Source

pub fn allowed(&self) -> Patterns

The patterns this producer may publish under, relative to its root.

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

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

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