pub struct Producer { /* private fields */ }Expand description
Announces broadcasts to consumers over the network.
Implementations§
Source§impl Producer
impl Producer
Sourcepub fn new(info: Info) -> Self
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.
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 with_linger(self, linger: Duration) -> Self
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.
Sourcepub fn info(&self) -> Info
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).
Sourcepub fn create_broadcast(
&self,
path: impl AsPath,
route: Route,
) -> Result<Producer, Error>
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.
Sourcepub fn scope(&self, prefixes: &[Path<'_>]) -> Option<Producer>
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).
Sourcepub fn dynamic(&self) -> Dynamic
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.
Sourcepub fn consume(&self) -> Consumer
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.
Sourcepub fn announces(&self) -> AnnounceProducer
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.
Sourcepub fn with_root(&self, prefix: impl AsPath) -> Option<Self>
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.
Sourcepub fn root(&self) -> &Path<'_>
pub fn root(&self) -> &Path<'_>
Returns the root that is automatically stripped from all paths.