pub trait Relay: Send + Sync {
// Required methods
fn cursor(&self) -> Cursor;
fn resume(&self, from: Cursor, limit: usize) -> Resumed;
fn ingest(
&self,
origin: &Origin,
entry: RelayedEntry,
) -> Result<u64, IngestError>;
fn answer(&self, origin: &Origin, ask: RelayedAsk) -> RelayedAnswer;
fn add_authority(&self, authority: Authority);
}Expand description
A capability of a bus (Bus::relay), on top of
its Journal: what crosses a process boundary. The events of
relayable points served to another process from a cursor and taken
in from one as if published here; the asks of relayable request
points answered here for another process.
A point is relayable when its declaration gives it a codec
(PointDecl::relayable); only events
and requests cross. The transport (a socket, a pipe, an RPC, a
channel in the same process) is not part of the contract: a relay
reads, takes in and answers; something else moves the text. Whatever
moves it, the meaning is the one written here, so a listener cannot
tell whether the far side is in this process or another.
What an implementation promises:
- A bus that offers
RelayoffersJournal. Relay::resumereturns the relayable entries after the cursor, in number order, each written by its point’s codec with its point’s version, and the cursor to resume from. A cursor of another run returns the run’s entries from its start withLost::Restarted; a cursor whose next entries left the window returns the kept ones withLost::Gap.Cursor::STARTloses nothing.- Authority first: whatever comes in (
Relay::ingest,Relay::answer) is shown to every authority added (Relay::add_authority), in the order they were added, before anything is decoded, recorded or run. One refusal refuses it. With no authority added, everything relayable is taken. Relay::ingestrecords a relayed entry in this journal with its origin: a point declared here is decoded with its codec and delivered to its listeners like an entry published here; a kind not declared here is kept with its text only and delivered to no one. The cause is the sender’s number, kept as it came. A point declared here but not relayable, or at another version, is refused.- Entries taken in are not served again by
Relay::resume: two processes relaying to each other do not echo. Relay::answerruns a relayable request’s listeners here, as an alter emit of the point with the ask’s input and value read by its codec, and answers with the value they left or the refusal. Every rule ofBusholds; a relayable request point is fail-closed. It refuses, running no listener, an ask on a point not declared here, not relayable, at another version, whose input or value it cannot read, or whose deadline has passed when it would run. When the listeners end past the ask’s deadline, the answer is a refusal (failed) whatever they did: the asker has stopped waiting and holds it refused, and both sides record the same.- Each ask is answered once: an ask whose run and number this bus has already answered for the same origin process runs no listener; it gets the first answer again while the bus still keeps it (at least as long as the ask’s deadline), else a refusal.
Required Methods§
Sourcefn cursor(&self) -> Cursor
fn cursor(&self) -> Cursor
Where a reader that starts now stands: this journal’s run and its last number.
Sourcefn resume(&self, from: Cursor, limit: usize) -> Resumed
fn resume(&self, from: Cursor, limit: usize) -> Resumed
The relayable entries after from, at most limit.
Sourcefn ingest(
&self,
origin: &Origin,
entry: RelayedEntry,
) -> Result<u64, IngestError>
fn ingest( &self, origin: &Origin, entry: RelayedEntry, ) -> Result<u64, IngestError>
Takes in an entry relayed from origin; its number in this
journal.
Sourcefn answer(&self, origin: &Origin, ask: RelayedAsk) -> RelayedAnswer
fn answer(&self, origin: &Origin, ask: RelayedAsk) -> RelayedAnswer
Answers an ask relayed from origin: runs the request’s listeners
here and says what they did. Blocks while they run.
Adds an authority shown everything that crosses in before it is taken: an event to ingest, an ask to answer. An authority that panics refuses.
Implementations§
Source§impl<'a> dyn Relay + 'a
impl<'a> dyn Relay + 'a
Adds an authority (Relay::add_authority): Err(reason)
refuses what crosses in.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".