pub trait EventSourcedBehavior {
    type State: Default;
    type Command;
    type Event;

    // Required methods
    fn for_command(
        context: &Context<'_>,
        state: &Self::State,
        command: Self::Command
    ) -> Box<dyn Effect<Self>>;
    fn on_event(
        context: &Context<'_>,
        state: &mut Self::State,
        event: Self::Event
    );

    // Provided methods
    fn on_recovery_completed<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _context: &'life1 Context<'_>,
        _state: &'life2 Self::State
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_initial_recovery_completed<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

An entity’s behavior is the basic unit of modelling aspects of an Akka-Persistence-based application and encapsulates how commands can be applied to state, including the emission of events. Events can also be applied to state in order to produce more state.

Required Associated Types§

source

type State: Default

The state managed by the entity.

source

type Command

The command(s) that are able to be processed by the entity.

source

type Event

The event produced having performed an effect.

Required Methods§

source

fn for_command( context: &Context<'_>, state: &Self::State, command: Self::Command ) -> Box<dyn Effect<Self>>

Given a state and command, optionally produce an effect that may cause an event transition. Events are responsible for mutating state. State can also be associated with the behavior so that other effects can be performed. For example, a behavior might be created with a channel sender so that data can be sent as an effect of performing a command. Effects can be chained and are guaranteed to be applied in their entirety before the next command for their entity id is processed.

source

fn on_event(context: &Context<'_>, state: &mut Self::State, event: Self::Event)

Given a state and event, modify state, which could indicate transition to the next state. No side effects are to be performed. Can be used to replay events to attain a new state i.e. the major function of event sourcing.

Provided Methods§

source

fn on_recovery_completed<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _context: &'life1 Context<'_>, _state: &'life2 Self::State ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

The entity will always receive a “recovery completed” signal, even if there are no events sourced, or if it’s a new entity with a previously unused EntityId. Any required side effects should be performed once recovery has completed by overriding this method.

source

fn on_initial_recovery_completed<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: Sync + 'async_trait, 'life0: 'async_trait,

Called when the entity manager has completed initially recoverying entities, even if there are no initial entities.

Object Safety§

This trait is not object safe.

Implementors§