A command handler returns a Effect
directive that defines what event or events,
if any, to persist.
A command handler returns a Effect
directive that defines what event or events,
if any, to persist. Use the thenPersist
, thenPersistAll
or done
methods of the context
that is passed to the command handler function to create the Effect
directive.
Additional side effects can be performed in the callback andThen
Instances of Effect
are available through factories in the respective Java and Scala DSL packages.
Not intended for user extension.
Not intended for user extension.
Not intended for user extension. Access an instance through ReplicatedEntity#Effect.
A ReplicatedEntity
has a stable entity identifier, with which
it can be accessed from anywhere in the cluster.
A ReplicatedEntity
has a stable entity identifier, with which
it can be accessed from anywhere in the cluster. It is run by an actor
and the state is persistent using event sourcing.
initialState
and behavior
are abstract methods that your concrete subclass must implement.
The behavior is defined as a set of handlers given a state. The handlers are functions to process
incoming commands.
Persistent and replicated events are applied to the state with the eventHandler
method.
The ReplicatedEntity
receives commands of type Command
that can be validated before
persisting state changes as events of type Event
. The functions that process incoming
commands are registered in the CommandHandler
using onCommand
of the
CommandHandler
.
A command may also be read-only and only perform some side-effect, such as replying
to the request. Such command handlers are registered using onReadOnlyCommand
of the CommandHandler
. Replies are sent with the sender()
ActorRef
in the context or an
ActorRef
that is passed in the command.
A command handler returns a Effect
directive that defines what event or events,
if any, to persist. Use the thenPersist
, thenPersistAll
or done
methods of the
context that is passed to the command handler function to create the Effect
directive.
When an event has been persisted successfully the state of type State
is updated by
applying the event to the current state by invoking the eventHandler
.
The eventHandler
returns the new state. The state must be immutable, so you return
a new instance of the state. Current state is passed as parameter to the event handler.
The same event handlers are also used when the entity is started up to recover its
state from the stored events.
After persisting an event, external side effects can be performed with the andThen
function of the Effect
directive.
A typical side effect is to reply to the request to confirm that it was performed
successfully. Replies are sent with the sender()
ActorRef
in the context or an
ActorRef
that is passed in the command.
The event handlers are typically only updating the state, but they may also change the behavior of the entity in the sense that new functions for processing commands and events may be defined for a given state. This is useful when implementing finite state machine (FSM) like entities.
When the entity is started the state is recovered by replaying stored events. To reduce this recovery time the entity may start the recovery from a snapshot of the state and then only replaying the events that were stored after the snapshot. Such snapshots are automatically saved after a configured number of persisted events.
the super type of all commands
the super type of all events
the type of the state
Internal API: Access an instance through ReplicatedEntity#Effect.
Internal API: Access an instance through ReplicatedEntity#Effect.
See the ReplicatedEntity class for details.
See the ReplicatedEntity class for details.