Id of the persistent entity for which messages should be replayed.
Id of the persistent entity for which messages should be replayed.
Command handler.
Command handler. Typically validates commands against current state (and/or by
communication with other actors). On successful validation, one or more events are
derived from a command and these events are then persisted by calling persist
.
Commands sent to event sourced persistent actors should not be Persistent messages.
Recovery handler that receives persisted events during recovery.
Recovery handler that receives persisted events during recovery. If a state snapshot has been captured and saved, this handler will receive a SnapshotOffer message followed by events that are younger than the offered snapshot.
This handler must not have side-effects other than changing persistent actor state i.e. it should not perform actions that may fail, such as interacting with external services, for example.
If recovery fails, the actor will be stopped. This can be customized by handling RecoveryFailure.
Can be overridden to intercept calls to postRestart
.
INTERNAL API.
INTERNAL API.
INTERNAL API.
INTERNAL API.
Stores the context for this actor, including self, and sender.
Stores the context for this actor, including self, and sender.
It is implicit to support operations such as forward
.
WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads!
akka.actor.ActorContext is the Scala API. getContext
returns a
akka.actor.UntypedActorContext, which is the Java API of the actor
context.
Defer the handler execution until all pending handlers have been executed.
Defer the handler execution until all pending handlers have been executed.
Allows to define logic within the actor, which will respect the invocation-order-guarantee
in respect to persistAsync
calls. That is, if persistAsync
was invoked before defer,
the corresponding handlers will be invoked in the same order as they were registered in.
This call will NOT result in event
being persisted, please use persist
or persistAsync
,
if the given event should possible to replay.
If there are no pending persist handler calls, the handler will be called immediatly.
In the event of persistence failures (indicated by PersistenceFailure messages being sent to the
PersistentActor, you can handle these messages, which in turn will enable the deferred handlers to run afterwards.
If persistence failure messages are left unhandled
, the default behavior is to stop the Actor, thus the handlers
will not be run.
event to be handled in the future, when preceeding persist operations have been processes
handler for each event
Defer the handler execution until all pending handlers have been executed.
Defer the handler execution until all pending handlers have been executed.
Allows to define logic within the actor, which will respect the invocation-order-guarantee
in respect to persistAsync
calls. That is, if persistAsync
was invoked before defer,
the corresponding handlers will be invoked in the same order as they were registered in.
This call will NOT result in event
being persisted, please use persist
or persistAsync
,
if the given event should possible to replay.
If there are no pending persist handler calls, the handler will be called immediatly.
In the event of persistence failures (indicated by PersistenceFailure messages being sent to the
PersistentActor, you can handle these messages, which in turn will enable the deferred handlers to run afterwards.
If persistence failure messages are left unhandled
, the default behavior is to stop the Actor, thus the handlers
will not be run.
event to be handled in the future, when preceeding persist operations have been processes
handler for the given event
Deletes all persistent messages with sequence numbers less than or equal toSequenceNr
.
Deletes all persistent messages with sequence numbers less than or equal toSequenceNr
. If permanent
is set to false
, the persistent messages are marked as deleted in the journal, otherwise
they permanently deleted from the journal.
upper sequence number bound of persistent messages to be deleted.
if false
, the message is marked as deleted, otherwise it is permanently deleted.
Permanently deletes all persistent messages with sequence numbers less than or equal toSequenceNr
.
Permanently deletes all persistent messages with sequence numbers less than or equal toSequenceNr
.
upper sequence number bound of persistent messages to be deleted.
Deletes a snapshot identified by sequenceNr
and timestamp
.
Deletes a snapshot identified by sequenceNr
and timestamp
.
Deletes all snapshots matching criteria
.
Deletes all snapshots matching criteria
.
INTERNAL API.
INTERNAL API.
Only here for binary compatibility in 2.3.x.
Highest received sequence number so far or 0L
if this actor hasn't received a persistent
message yet.
Highest received sequence number so far or 0L
if this actor hasn't received a persistent
message yet. Usually equal to the sequence number of currentPersistentMessage
(unless a
receiver implementation is about to re-order persistent messages using stash()
and unstash()
).
Asynchronously persists events
in specified order.
Asynchronously persists events
in specified order. This is equivalent to calling
persist[A](event: A)(handler: A => Unit)
multiple times with the same handler
,
except that events
are persisted atomically with this method.
events to be persisted
handler for each persisted events
Asynchronously persists event
.
Asynchronously persists event
. On successful persistence, handler
is called with the
persisted event. It is guaranteed that no new commands will be received by a persistent actor
between a call to persist
and the execution of its handler
. This also holds for
multiple persist
calls per received command. Internally, this is achieved by stashing new
commands and unstashing them when the event
has been persisted and handled. The stash used
for that is an internal stash which doesn't interfere with the inherited user stash.
An event handler
may close over persistent actor state and modify it. The sender
of a persisted
event is the sender of the corresponding command. This means that one can reply to a command
sender within an event handler
.
Within an event handler, applications usually update persistent actor state using persisted event data, notify listeners and reply to command senders.
If persistence of an event fails, the persistent actor will be stopped. This can be customized by handling PersistenceFailure in receiveCommand.
event to be persisted
handler for each persisted event
Asynchronously persists events
in specified order.
Asynchronously persists events
in specified order. This is equivalent to calling
persistAsync[A](event: A)(handler: A => Unit)
multiple times with the same handler
,
except that events
are persisted atomically with this method.
events to be persisted
handler for each persisted events
Asynchronously persists event
.
Asynchronously persists event
. On successful persistence, handler
is called with the
persisted event.
Unlike persist
the persistent actor will continue to receive incomming commands between the
call to persist
and executing it's handler
. This asynchronous, non-stashing, version of
of persist should be used when you favor throughput over the "command-2 only processed after
command-1 effects' have been applied" guarantee, which is provided by the plain persist method.
An event handler
may close over persistent actor state and modify it. The sender
of a persisted
event is the sender of the corresponding command. This means that one can reply to a command
sender within an event handler
.
If persistence of an event fails, the persistent actor will be stopped. This can be customized by handling PersistenceFailure in receiveCommand.
event to be persisted
handler for each persisted event
User overridable callback: By default it calls preStart()
.
User overridable callback: By default it calls preStart()
.
the Throwable that caused the restart to happen
Is called right AFTER restart on the newly created Actor to allow reinitialization after an Actor crash.
Calls super.postStop
then unstashes all messages from the internal stash.
Calls super.postStop
then unstashes all messages from the internal stash.
Calls super.preRestart
then unstashes all messages from the internal stash.
Calls super.preRestart
then unstashes all messages from the internal stash.
the Throwable that caused the restart to happen
optionally the current message the actor processed when failing, if applicable
Is called on a crashed Actor right BEFORE it is restarted to allow clean up of resources before Actor is terminated.
Calls preRestart and then super.preRestart()
.
Calls preRestart and then super.preRestart()
. If processor implementation classes want to
opt out from stopping child actors, they should override this method and call preRestart only.
User-overridable callback.
User-overridable callback. Called when a processor is started. Default implementation sends
a Recover()
to self
.
This defines the initial actor behavior, it must return a partial function with the actor logic.
This defines the initial actor behavior, it must return a partial function with the actor logic.
Returns true
if this processor has successfully finished recovery.
Returns true
if this processor has successfully finished recovery.
Returns true
if this processor is currently recovering.
Returns true
if this processor is currently recovering.
Saves a snapshot
of this snapshotter's state.
Saves a snapshot
of this snapshotter's state. If saving succeeds, this snapshotter will receive a
SaveSnapshotSuccess message, otherwise a SaveSnapshotFailure message.
The 'self' field holds the ActorRef for this actor.
The 'self' field holds the ActorRef for this actor.
Can be used to send messages to itself:
self ! message
The reference sender Actor of the last received message.
The reference sender Actor of the last received message.
Is defined if the message was sent from another Actor,
else deadLetters
in akka.actor.ActorSystem.
WARNING: Only valid within the Actor itself, so do not close over it and publish it to other threads!
Returns lastSequenceNr
.
Returns lastSequenceNr
.
Returns persistenceId
.
Returns persistenceId
.
Adds the current message (the message that the actor received last) to the actor's stash.
Adds the current message (the message that the actor received last) to the actor's stash.
IllegalStateException
if the same message is stashed more than once
StashOverflowException
in case of a stash capacity violation
User overridable definition the strategy to use for supervising child actors.
User overridable definition the strategy to use for supervising child actors.
User overridable callback.
User overridable callback.
Is called when a message isn't handled by the current behavior of the actor by default it fails with either a akka.actor.DeathPactException (in case of an unhandled akka.actor.Terminated message) or publishes an akka.actor.UnhandledMessage to the actor's system's akka.event.EventStream
Prepends all messages in the stash to the mailbox, and then clears the stash.
Prepends all messages in the stash to the mailbox, and then clears the stash.
Messages from the stash are enqueued to the mailbox until the capacity of the
mailbox (if any) has been reached. In case a bounded mailbox overflows, a
MessageQueueAppendFailedException
is thrown.
The stash is guaranteed to be empty after calling unstashAll()
.
Returns the current persistent message if there is any.
Returns the current persistent message if there is any.
(Since version 2.3.4) currentPersistentMessage will be removed, sequence number can be retrieved with lastSequenceNr
.
Deletes a persistent message identified by sequenceNr
.
Deletes a persistent message identified by sequenceNr
. If permanent
is set to false
,
the persistent message is marked as deleted in the journal, otherwise it is permanently
deleted from the journal. A deleted message is not replayed during recovery. This method
is usually called inside preRestartProcessor
when a persistent message caused an exception.
Processors that want to re-receive that persistent message during recovery should not call
this method.
sequence number of the persistent message to be deleted.
if false
, the message is marked as deleted, otherwise it is permanently deleted.
(Since version 2.3.4) deleteMessage(sequenceNr) will be removed. Instead, validate before persist, and use deleteMessages for pruning.
Marks a persistent message, identified by sequenceNr
, as deleted.
Marks a persistent message, identified by sequenceNr
, as deleted. A message marked as deleted is
not replayed during recovery. This method is usually called inside preRestartProcessor
when a
persistent message caused an exception. Processors that want to re-receive that persistent message
during recovery should not call this method.
sequence number of the persistent message to be deleted.
(Since version 2.3.4) deleteMessage(sequenceNr) will be removed. Instead, validate before persist, and use deleteMessages for pruning.
Java API: returns the current persistent message or null
if there is none.
Java API: returns the current persistent message or null
if there is none.
(Since version 2.3.4) getCurrentPersistentMessage will be removed, sequence number can be retrieved with lastSequenceNr
.
Processor id.
Processor id. Defaults to this processor's path and can be overridden.
(Since version 2.3.4) Override persistenceId: String
instead. Processor will be removed.
An persistent Actor - can be used to implement command or event sourcing.