Skip to main content

Journal

Trait Journal 

pub trait Journal: Send + Sync {
    // Required methods
    fn last_seq(&self) -> u64;
    fn since(&self, seq: u64, limit: usize) -> Since;
    fn wait(
        &self,
        patterns: &[&str],
        seq: u64,
        timeout: Duration,
    ) -> Option<JournalEntry>;
    fn publish_any(
        &self,
        point: PointKey,
        input: Arc<dyn Any + Sync + Send>,
        fresh: fn() -> Box<dyn Any + Send>,
        cause: Option<u64>,
    ) -> Result<u64, Refused>;
    fn flush(&self, timeout: Duration) -> bool;
}
Expand description

A capability of a bus (BusJournal::journal): events kept in order with a number, read again from a number, and delivered to their point’s listeners after the publisher has moved on.

An event point is journaled when its declaration says so (JOURNALED, is_journaled). Its events are published through the journal (Journal::publish_any, typed publish::<P>), not emitted.

What an implementation promises:

  • Numbers start at 1 and increase by one with each entry; the journal is ordered by them. An implementation may keep entries that are not events of a point (its own facts, events relayed in from a kind not declared here).
  • Publishing never runs a listener and never waits on one: it records the entry and returns its number.
  • Each entry of a journaled point is delivered to the point’s listeners once, entries in number order, each as a collect emit of the point with the entry’s input (every rule of Bus holds: order, deadlines, failures, local listeners queued for their thread). Delivery runs on a thread of the implementation’s (a pump), so a slow listener delays the following entries, never the publisher; deadlines bound it.
  • The journal keeps a window: Journal::since reports a gap when entries after the number asked were dropped.

Required Methods§

fn last_seq(&self) -> u64

The number of the last entry; 0 before the first.

fn since(&self, seq: u64, limit: usize) -> Since

The entries after seq, oldest first, at most limit; a gap when some were dropped before this read.

fn wait( &self, patterns: &[&str], seq: u64, timeout: Duration, ) -> Option<JournalEntry>

The first entry after seq whose kind matches one of patterns (kind_matches; empty matches every kind), waiting for it up to timeout; None when none came. An entry already in the journal is returned at once.

fn publish_any( &self, point: PointKey, input: Arc<dyn Any + Sync + Send>, fresh: fn() -> Box<dyn Any + Send>, cause: Option<u64>, ) -> Result<u64, Refused>

Records an event of the journaled point point, caused by the entry cause; its number. fresh makes the value each listener fills at delivery. Refused, with nothing recorded, when the point is not declared journaled on this bus (not_journaled) or is declared with another type (Refused::TypeMismatch).

fn flush(&self, timeout: Duration) -> bool

Waits until every entry recorded before the call has been delivered to its listeners, up to timeout; whether it was. For a host before it exits and for tests.

Implementations§

§

impl<'a> dyn Journal + 'a

pub fn publish<P>(&self, input: <P as Point>::Input) -> Result<u64, Refused>
where P: Point, <P as Point>::Value: Default,

Publishes an event of the journaled point P: recorded now, delivered to its listeners later, in journal order. Its number.

pub fn publish_caused<P>( &self, input: <P as Point>::Input, cause: u64, ) -> Result<u64, Refused>
where P: Point, <P as Point>::Value: Default,

Publishes an event of P caused by the entry cause.

pub fn wait_for<P>( &self, seq: u64, timeout: Duration, ) -> Option<(u64, <P as Point>::Input)>
where P: Point, <P as Point>::Input: Clone,

The next event of P after seq, typed, waiting up to timeout.

Implementors§

§

impl Journal for Kernel

The host’s journal (Kernel::with_journal), behind the kernel’s own check of what may be published.