pub struct Producer { /* private fields */ }Expand description
Publishes broadcasts and announces routes into an origin.
Implementations§
Source§impl Producer
impl Producer
Sourcepub fn new(config: Config) -> (Self, Driver)
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.
Sourcepub fn with_stats(self, session: Session) -> Self
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.
Sourcepub fn peer(self) -> Self
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.
Sourcepub fn create_broadcast(&self, path: impl AsPath) -> Result<Producer, Error>
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.
Sourcepub fn publish(
&self,
path: impl AsPath,
route: Route,
) -> Result<Producer, Error>
pub fn publish( &self, path: impl AsPath, route: Route, ) -> Result<Producer, Error>
Create and advertise a broadcast in one call.
Sourcepub fn dynamic(
&self,
prefix: impl AsPath,
route: Route,
) -> Result<Dynamic, Error>
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.
Sourcepub fn scope(
&self,
root: impl AsPath,
patterns: &Patterns,
) -> Result<Producer, Error>
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.
Sourcepub fn consume(&self) -> Consumer
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.
Sourcepub fn root(&self) -> &Path<'_>
pub fn root(&self) -> &Path<'_>
Returns the root that is automatically stripped from all paths.