Skip to main content

EventSourcedBehavior

Struct EventSourcedBehavior 

Source
pub struct EventSourcedBehavior<C, E, S, J = E> { /* private fields */ }
Expand description

Immutable, side-effect-free event-sourced behavior blueprint.

Implementations§

Source§

impl<C, E, S> EventSourcedBehavior<C, E, S, E>

Source

pub fn new<CH, EH, O>( persistence_id: PersistenceId, empty_state: S, command_handler: CH, event_handler: EH, ) -> Self
where CH: Fn(&S, C) -> Effect<C, E, S> + Send + Sync + 'static, EH: Fn(&S, &E) -> O + Send + Sync + 'static, O: IntoEventHandlerResult<S>,

Creates a side-effect-free behavior blueprint.

A serializer/adapter is selected separately with Self::with_event_adapter; no journal, snapshot, topic, actor, or task is touched until Self::spawn.

Source

pub fn with_enforced_replies<CH, EH, O>( persistence_id: PersistenceId, empty_state: S, command_handler: CH, event_handler: EH, ) -> Self
where CH: Fn(&S, C) -> ReplyEffect<C, E, S> + Send + Sync + 'static, EH: Fn(&S, &E) -> O + Send + Sync + 'static, O: IntoEventHandlerResult<S>,

Creates a blueprint whose command handler must return a ReplyEffect.

Source§

impl<C, E, S, J> EventSourcedBehavior<C, E, S, J>

Source

pub fn with_event_adapter<J2, A>( self, adapter: A, catalog: SerializerCatalog<J2>, ) -> EventSourcedBehavior<C, E, S, J2>
where A: EventAdapter<E, J2>, J2: 'static,

Selects an event adapter and serializer catalog, possibly changing J.

Source

pub fn with_state_adapter<SJ, A>( self, adapter: A, catalog: SerializerCatalog<SJ>, ) -> Self
where A: StateAdapter<S, SJ>, SJ: 'static, S: 'static,

Selects the state adapter and serializer catalog used for snapshots.

Source

pub fn snapshot_when<F>(self, predicate: F) -> Self
where F: Fn(&S, &E, SequenceNr) -> bool + Send + Sync + 'static,

Saves a snapshot after a batch when any post-event predicate invocation matches.

Source

pub fn with_retention(self, retention: RetentionCriteria) -> Self

Configures count-based snapshots and asynchronous cleanup.

Source

pub fn with_tagger<F>(self, tagger: F) -> Self
where F: Fn(&E) -> Vec<Tag> + Send + Sync + 'static,

Tags stored events using the domain event.

Source

pub fn with_state_tagger<F>(self, tagger: F) -> Self
where F: Fn(&S, &E) -> Vec<Tag> + Send + Sync + 'static,

Tags stored events using post-event state and the domain event.

Source

pub fn on_persist_failure(self, settings: RestartSettings) -> Self

Restarts this persistent behavior with recovery after journal failures.

Exponential delay, jitter, restart limits, and reset windows come from Datum’s shared RestartSettings. The actor remains responsive during the delayed backoff and automatically stashes domain commands.

Source

pub fn with_recovery(self, recovery: Recovery) -> Self

Changes recovery mode and snapshot selection.

Source

pub fn with_event_publishing(self, enabled: bool) -> Self

Enables or disables confirmed domain-event publishing (enabled by default).

Source

pub fn with_stash_capacity(self, capacity: usize) -> Self

Sets the manual stash capacity.

Overflow follows Akka’s default drop strategy: the newest command is dropped and chained effects registered on that stash decision do not run. If it owns a ReplyPort, dropping that command closes the port.

Source

pub fn on_signal<F>(self, handler: F) -> Self
where F: Fn(&S, &EventSourcedSignal) + Send + Sync + 'static,

Installs a persistence signal callback.

Source§

impl<C, E, S, J> EventSourcedBehavior<C, E, S, J>
where C: Message, E: Send + Sync + 'static, S: Clone + Send + Sync + 'static, J: Send + 'static,

Source

pub async fn spawn( self, runtime: EventSourcedRuntime, ) -> PersistenceResult<EventSourcedHandle<C, E, S>>

Spawns the Ractor runtime and begins recovery.

Source

pub async fn run_on( self, runtime: EventSourcedRuntime, ) -> PersistenceResult<EventSourcedHandle<C, E, S>>

Alias for Self::spawn emphasizing execution on the active Tokio runtime.

Auto Trait Implementations§

§

impl<C, E, S, J = E> !RefUnwindSafe for EventSourcedBehavior<C, E, S, J>

§

impl<C, E, S, J = E> !UnwindSafe for EventSourcedBehavior<C, E, S, J>

§

impl<C, E, S, J> Freeze for EventSourcedBehavior<C, E, S, J>
where S: Freeze, Arc<dyn Fn(&S, C) -> Effect<C, E, S> + Sync + Send>: Freeze, Arc<dyn Fn(&S, &E) -> Result<S, PersistenceError> + Sync + Send>: Freeze, Option<EventCodec<E, J>>: Freeze, Option<Arc<dyn StateCodec<S>>>: Freeze, Arc<dyn Fn(&S, &E, SequenceNr) -> bool + Sync + Send>: Freeze, Arc<dyn Fn(&S, &E) -> Vec<Tag> + Sync + Send>: Freeze, Arc<dyn Fn(&S, &EventSourcedSignal) + Sync + Send>: Freeze, PhantomData<fn() -> J>: Freeze,

§

impl<C, E, S, J> Send for EventSourcedBehavior<C, E, S, J>
where S: Send, Arc<dyn Fn(&S, C) -> Effect<C, E, S> + Sync + Send>: Send, Arc<dyn Fn(&S, &E) -> Result<S, PersistenceError> + Sync + Send>: Send, Option<EventCodec<E, J>>: Send, Option<Arc<dyn StateCodec<S>>>: Send, Arc<dyn Fn(&S, &E, SequenceNr) -> bool + Sync + Send>: Send, Arc<dyn Fn(&S, &E) -> Vec<Tag> + Sync + Send>: Send, Arc<dyn Fn(&S, &EventSourcedSignal) + Sync + Send>: Send, PhantomData<fn() -> J>: Send,

§

impl<C, E, S, J> Sync for EventSourcedBehavior<C, E, S, J>
where S: Sync, Arc<dyn Fn(&S, C) -> Effect<C, E, S> + Sync + Send>: Sync, Arc<dyn Fn(&S, &E) -> Result<S, PersistenceError> + Sync + Send>: Sync, Option<EventCodec<E, J>>: Sync, Option<Arc<dyn StateCodec<S>>>: Sync, Arc<dyn Fn(&S, &E, SequenceNr) -> bool + Sync + Send>: Sync, Arc<dyn Fn(&S, &E) -> Vec<Tag> + Sync + Send>: Sync, Arc<dyn Fn(&S, &EventSourcedSignal) + Sync + Send>: Sync, PhantomData<fn() -> J>: Sync,

§

impl<C, E, S, J> Unpin for EventSourcedBehavior<C, E, S, J>
where S: Unpin, Arc<dyn Fn(&S, C) -> Effect<C, E, S> + Sync + Send>: Unpin, Arc<dyn Fn(&S, &E) -> Result<S, PersistenceError> + Sync + Send>: Unpin, Option<EventCodec<E, J>>: Unpin, Option<Arc<dyn StateCodec<S>>>: Unpin, Arc<dyn Fn(&S, &E, SequenceNr) -> bool + Sync + Send>: Unpin, Arc<dyn Fn(&S, &E) -> Vec<Tag> + Sync + Send>: Unpin, Arc<dyn Fn(&S, &EventSourcedSignal) + Sync + Send>: Unpin, PhantomData<fn() -> J>: Unpin,

§

impl<C, E, S, J> UnsafeUnpin for EventSourcedBehavior<C, E, S, J>
where S: UnsafeUnpin, Arc<dyn Fn(&S, C) -> Effect<C, E, S> + Sync + Send>: UnsafeUnpin, Arc<dyn Fn(&S, &E) -> Result<S, PersistenceError> + Sync + Send>: UnsafeUnpin, Option<EventCodec<E, J>>: UnsafeUnpin, Option<Arc<dyn StateCodec<S>>>: UnsafeUnpin, Arc<dyn Fn(&S, &E, SequenceNr) -> bool + Sync + Send>: UnsafeUnpin, Arc<dyn Fn(&S, &E) -> Vec<Tag> + Sync + Send>: UnsafeUnpin, Arc<dyn Fn(&S, &EventSourcedSignal) + Sync + Send>: UnsafeUnpin, PhantomData<fn() -> J>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<S> IntoEventHandlerResult<S> for S

Source§

fn into_event_handler_result(self) -> Result<S, PersistenceError>

Converts this handler output into the runtime result.
Source§

impl<T> Message for T
where T: Any + Send + 'static,

Source§

fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>

Convert a BoxedMessage to this concrete type
Source§

fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>

Convert this message to a BoxedMessage
Source§

impl<T> State for T
where T: Any + Send + 'static,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more