pub struct EmbeddedTask { /* private fields */ }Expand description
One task’s processor graph, driven by an embedder instead of the runtime.
The graph runs with in-memory stores and with the record cache disabled,
which is the JVM TopologyTestDriver default, so a store emits on every
update. Changelog topics derive from the built topology’s application id,
exactly as BuiltTopology::changelog_topics lists them.
A KIP-1071 task is one (subtopology, partition) of the group’s
assignment, and for_subtopology instantiates
exactly that subtopology’s graph. new instantiates every
subtopology, which is the task itself when the topology has one.
§Examples
use assert2::assert;
use krabka_client_streams::{EmbeddedTask, NodeHandle, Record, Topology, impl_processor};
struct Upper;
impl_processor! {
impl Upper: (String, String) -> (String, String) {
async fn process(&mut self, ctx, r) {
ctx.forward(Record::new(r.key, r.value.to_uppercase(), r.timestamp));
}
}
}
let mut topo = Topology::new();
let src: NodeHandle<String, String> = topo.add_source("src", ["in"]);
let up = topo.add_processor("up", || Upper, [&src]);
topo.add_sink("out", "out", [&up]);
let built = topo.build("app").unwrap();
let mut task = EmbeddedTask::new(&built).unwrap();
task.pipe("in", 0, 0, Some(b"k"), b"hello", 0).unwrap();
let out = task.take_output();
assert!(out[0].value.as_deref() == Some(&b"HELLO"[..]));Implementations§
Source§impl EmbeddedTask
impl EmbeddedTask
Sourcepub fn new(built: &BuiltTopology) -> Result<Self, ProcessorError>
pub fn new(built: &BuiltTopology) -> Result<Self, ProcessorError>
Instantiates the whole topology’s graph, every subtopology included,
with in-memory stores, and calls init on every processor.
Use it for a topology with one subtopology, where the task is the
topology. A KIP-1071 task of a topology with several subtopologies
must use for_subtopology: a graph that
holds every subtopology runs every branch that reads a piped topic, so
two tasks of different subtopologies over the same source topic would
each emit the other’s sink output and store updates, and each would
hold the other’s stores and fire its punctuators.
§Errors
Returns the ProcessorError that instantiation or a processor’s
init raises. A topology that Topology::build
accepted raises none in practice.
Sourcepub fn for_subtopology(
built: &BuiltTopology,
subtopology_id: &str,
) -> Result<Self, ProcessorError>
pub fn for_subtopology( built: &BuiltTopology, subtopology_id: &str, ) -> Result<Self, ProcessorError>
Instantiates the graph of one subtopology, with in-memory stores, and
calls init on its processors.
The graph holds that subtopology’s sources, processors and sinks, and
the stores its processors connect to, and nothing of any other
subtopology. This is the graph of a KIP-1071 task (subtopology_id, partition); BuiltTopology::subtopology_ids lists the ids and
BuiltTopology::source_topics_for the topics to pipe.
§Errors
Returns ProcessorError::UnknownSubtopology when the topology has no
subtopology subtopology_id, else what new returns.
Sourcepub fn pipe(
&mut self,
topic: &str,
partition: i32,
offset: i64,
key: Option<&[u8]>,
value: &[u8],
timestamp: i64,
) -> Result<(), ProcessorError>
pub fn pipe( &mut self, topic: &str, partition: i32, offset: i64, key: Option<&[u8]>, value: &[u8], timestamp: i64, ) -> Result<(), ProcessorError>
Runs one source record through the graph.
partition and offset are the record’s provenance, and a processor
reads them through its record context. The record raises the task’s
stream-time to its timestamp when it is later. A record on a topic no
source reads is ignored. The sink outputs wait in
take_output and the store changelog records in
drain_changelogs.
§Errors
Returns a ProcessorError when a source serde cannot deserialize the
record, or a sink serde cannot serialize an output.
Sourcepub fn take_output(&mut self) -> Vec<OutputRecord>
pub fn take_output(&mut self) -> Vec<OutputRecord>
Takes the sink records the graph emitted since the last call, in emission order.
A record for a repartition topic is in the list too. The embedder
produces it like any other output, and the subtopology that reads the
repartition topic gets it back through pipe.
Sourcepub fn drain_changelogs(&mut self) -> Vec<ChangelogRecord>
pub fn drain_changelogs(&mut self) -> Vec<ChangelogRecord>
Takes the changelog records the stores logged since the last call.
A reuse-source store’s records are dropped, not returned, because its changelog topic is the source topic itself. Restore writes log nothing while logging is off.
Sourcepub fn restore_apply(
&mut self,
store: &str,
key: Bytes,
value: Option<Bytes>,
timestamp: i64,
)
pub fn restore_apply( &mut self, store: &str, key: Bytes, value: Option<Bytes>, timestamp: i64, )
Applies one changelog record to the named store, as a restore does.
A value of None is a tombstone. timestamp is the changelog record’s
timestamp; a versioned store inserts the version at it. Turn logging off
with set_logging for the whole replay, so the
restored writes are not logged again, and turn it back on before the
first pipe. A store the graph does not hold is ignored.
Sourcepub fn apply_global(&mut self, store: &str, key: Bytes, value: Option<Bytes>)
pub fn apply_global(&mut self, store: &str, key: Bytes, value: Option<Bytes>)
Applies one record of a global source topic to the named global store.
A GlobalKTable store is fully replicated and has no changelog, so the
embedder replays every partition of the source topic here, before the
first record that joins against it. A value of None deletes the
entry. BuiltTopology::global_store_topics maps each store to its
topic.
Sourcepub fn set_logging(&mut self, on: bool)
pub fn set_logging(&mut self, on: bool)
Turns changelog logging on or off for every store.
Sourcepub fn stream_time(&self) -> i64
pub fn stream_time(&self) -> i64
The task’s stream-time: the highest record timestamp piped so far, or
i64::MIN before the first record.
Sourcepub fn punctuate_stream_time(
&mut self,
stream_time: i64,
) -> Result<(), ProcessorError>
pub fn punctuate_stream_time( &mut self, stream_time: i64, ) -> Result<(), ProcessorError>
Raises stream-time to stream_time when it is higher, then fires every
due stream-time punctuator once at the current stream-time.
The runtime fires stream-time punctuators after each fetched batch.
Passing stream_time fires what is due without
moving the clock. What a punctuator forwards waits in
take_output and
drain_changelogs.
§Errors
Returns a ProcessorError when a sink serde cannot serialize a record
a punctuator forwarded.
Sourcepub fn punctuate_wall_clock(
&mut self,
now_ms: i64,
) -> Result<(), ProcessorError>
pub fn punctuate_wall_clock( &mut self, now_ms: i64, ) -> Result<(), ProcessorError>
Sets the wall clock to now_ms and fires every due wall-clock
punctuator once at that time.
The runtime ticks the wall clock between polls; an embedder ticks it
from its own clock. A schedule registered during the call stamps its
first fire from now_ms.
§Errors
Returns a ProcessorError when a sink serde cannot serialize a record
a punctuator forwarded.
Sourcepub fn flush_caches(&mut self) -> Result<(), ProcessorError>
pub fn flush_caches(&mut self) -> Result<(), ProcessorError>
Flushes every cached store and forwards its deduplicated changes.
The runtime flushes before each commit. The embedded graph runs with the record cache disabled, so no store is cached and the call forwards nothing; it exists so an embedder can follow the runtime’s commit sequence unchanged.
§Errors
Returns a ProcessorError when a node rejects a forwarded change.
Sourcepub fn clear_stores(&mut self)
pub fn clear_stores(&mut self)
Wipes every store, for a clean-slate replay of the changelogs.
Sourcepub fn snapshot_stores(&mut self) -> TaskSnapshot
pub fn snapshot_stores(&mut self) -> TaskSnapshot
Snapshots every store, keyed by store name, for a barrier cut.
The payloads are the ones SnapshotStore keeps,
and restore_store_snapshots takes the
task back to them.
Sourcepub fn restore_store_snapshots(
&mut self,
snapshot: &TaskSnapshot,
) -> Result<(), StreamsClientError>
pub fn restore_store_snapshots( &mut self, snapshot: &TaskSnapshot, ) -> Result<(), StreamsClientError>
Replaces every store with the snapshot taken at a cut.
A store the snapshot does not name is wiped, so the task holds the state of the cut and nothing after it.
§Errors
Returns StreamsClientError::Snapshot when a payload does not match
the format its store writes.
Sourcepub fn store_names(&self) -> Vec<String>
pub fn store_names(&self) -> Vec<String>
The names of the task’s state stores, in ascending order.
Global stores are not in the list; they belong to the application, not to a task.
Sourcepub fn store_changelog_topic(&self, store: &str) -> Option<String>
pub fn store_changelog_topic(&self, store: &str) -> Option<String>
The changelog topic of a store, or None when the task has no such
store or the store has logging off.
Sourcepub fn dump_store(&self, store: &str, limit: usize) -> Vec<(Bytes, Bytes)>
pub fn dump_store(&self, store: &str, limit: usize) -> Vec<(Bytes, Bytes)>
The first limit entries of a key-value store, as raw key and value
bytes in ascending key order.
The dump is for an inspector, and it scans the whole store before it cuts the list. A window, session or versioned store dumps nothing here, and neither does a store the task does not hold.
Auto Trait Implementations§
impl !RefUnwindSafe for EmbeddedTask
impl !Sync for EmbeddedTask
impl !UnwindSafe for EmbeddedTask
impl Freeze for EmbeddedTask
impl Send for EmbeddedTask
impl Unpin for EmbeddedTask
impl UnsafeUnpin for EmbeddedTask
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> Fruit for Twhere
T: Send + Downcast,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);