Interface Eventsourced
- All Superinterfaces:
Actor,PersistenceIdentity,PersistenceRecovery,PersistenceStash,RequiresMessageQueue<DequeBasedMessageQueueSemantics>,Snapshotter,Stash,StashFactory,StashSupport,UnrestrictedStash
- All Known Subinterfaces:
AbstractPersistentActorLike,AtLeastOnceDelivery,AtLeastOnceDeliveryLike,PersistentActor,PersistentFSM<S,D, E>
- All Known Implementing Classes:
AbstractPersistentActor,AbstractPersistentActorWithAtLeastOnceDelivery,AbstractPersistentActorWithTimers,AbstractPersistentFSM,AbstractPersistentLoggingFSM,JournalPerfSpec.BenchActor,PersistentShardCoordinator
Scala API and implementation details of PersistentActor and AbstractPersistentActor.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classINTERNAL API: does not force the actor to stash commands; Originates from either `persistAsync` or `defer` callsstatic classstatic interfaceINTERNAL APIstatic final classINTERNAL API: message used to detect that recovery timed outstatic classstatic final classINTERNAL API: forces actor to stash incoming commands until all these invocations are handledstatic classstatic interfaceNested classes/interfaces inherited from interface org.apache.pekko.actor.Actor
Actor.emptyBehavior$, Actor.ignoringBehavior$ -
Method Summary
Modifier and TypeMethodDescriptionvoid_lastSequenceNr_$eq(long x$1) voidaroundPostRestart(Throwable reason) INTERNAL API.voidINTERNAL API.voidaroundPreRestart(Throwable reason, scala.Option<Object> message) INTERNAL API.voidINTERNAL API.voidaroundReceive(scala.PartialFunction<Object, scala.runtime.BoxedUnit> receive, Object message) INTERNAL API.voidbatchAtomicWrite(AtomicWrite atomicWrite) voidchangeState(Eventsourced.State state) voidvoiddeleteMessages(long toSequenceNr) Permanently deletes all persistent messages with sequence numbers less than or equaltoSequenceNr.voideventBatch_$eq(scala.collection.immutable.List<PersistentEnvelope> x$1) voidvoid<A> voidinternalDefer(A event, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API<A> voidinternalDeferAsync(A event, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal APIvoidinternalDeleteMessagesBeforeSnapshot(SaveSnapshotSuccess e, int keepNrOfBatches, int snapshotAfter) INTERNAL API.<A> voidinternalPersist(A event, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API<A> voidinternalPersistAll(scala.collection.immutable.Seq<A> events, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API<A> voidinternalPersistAllAsync(scala.collection.immutable.Seq<A> events, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API<A> voidinternalPersistAsync(A event, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal APIjournal()voidjournalBatch_$eq(scala.collection.immutable.Vector<PersistentEnvelope> x$1) longHighest received sequence number so far or0Lif this actor hasn't replayed or stored any persistent events yet.log()longvoidonPersistFailure(Throwable cause, Object event, long seqNr) Called when persist fails.voidonPersistRejected(Throwable cause, Object event, long seqNr) Called when the journal rejectedpersistof an event.voidonRecoveryFailure(Throwable cause, scala.Option<Object> event) Called whenever a message replay fails.voidINTERNAL API.voidpeekApplyHandler(Object payload) voidpendingStashingPersistInvocations_$eq(long x$1) scala.PartialFunction<Object,scala.runtime.BoxedUnit> Command handler.scala.PartialFunction<Object,scala.runtime.BoxedUnit> Recovery handler that receives persisted events during recovery.recovering(scala.PartialFunction<Object, scala.runtime.BoxedUnit> recoveryBehavior, scala.concurrent.duration.FiniteDuration timeout) booleanReturnstrueif this persistent actor has successfully finished recovery.booleanReturnstrueif this persistent actor is currently recovering.recoveryStarted(long replayMax, scala.concurrent.duration.FiniteDuration timeout) voidvoidsendBatchedEventsToJournal(scala.collection.immutable.Vector<PersistentEnvelope> journalBatch) voidsequenceNr_$eq(long x$1) voidsetLastSequenceNr(long value) longReturnslastSequenceNr.Snapshot store plugin actor.ReturnspersistenceId.voidstartRecovery(Recovery recovery) voidstash()Adds the current message (the message that the actor received last) to the actor's stash.voidstashInternally(Object currMsg) voidsuper$aroundPostRestart(Throwable reason) INTERNAL API.voidINTERNAL API.voidsuper$aroundPreRestart(Throwable reason, scala.Option<Object> message) INTERNAL API.voidvoidsuper$aroundReceive(scala.PartialFunction<Object, scala.runtime.BoxedUnit> receive, Object msg) Processes a loaded snapshot, if any.voidReturnstrueif this persistent actor has successfully finished recovery.voidsuper$unhandled(Object message) voidUser overridable callback.voidPrepends all messages in the stash to the mailbox, and then clears the stash.voidunstashInternally(boolean all) voidupdateLastSequenceNr(PersistentRepr persistent) waitingRecoveryPermit(Recovery recovery) voidwriteEventFailed(PersistentRepr p, Throwable cause) voidwriteEventRejected(PersistentRepr p, Throwable cause) voidvoidwriteInProgress_$eq(boolean x$1) Methods inherited from interface org.apache.pekko.actor.Actor
context, org$apache$pekko$actor$Actor$_setter_$context_$eq, org$apache$pekko$actor$Actor$_setter_$self_$eq, postRestart, preStart, receive, self, sender, supervisorStrategyMethods inherited from interface org.apache.pekko.persistence.PersistenceIdentity
journalPluginId, persistenceId, snapshotPluginIdMethods inherited from interface org.apache.pekko.persistence.PersistenceRecovery
recoveryMethods inherited from interface org.apache.pekko.persistence.PersistenceStash
internalStashOverflowStrategyMethods inherited from interface org.apache.pekko.persistence.Snapshotter
deleteSnapshot, deleteSnapshots, loadSnapshot, saveSnapshotMethods inherited from interface org.apache.pekko.actor.StashFactory
createStashMethods inherited from interface org.apache.pekko.actor.StashSupport
actorCell, clearStash, context, enqueueFirst, mailbox, org$apache$pekko$actor$StashSupport$_setter_$mailbox_$eq, prepend, self, theStash_$eq, unstash, unstashAllMethods inherited from interface org.apache.pekko.actor.UnrestrictedStash
postStop, preRestart, super$postStop, super$preRestart
-
Method Details
-
super$aroundPreStart
void super$aroundPreStart() -
super$aroundPreRestart
INTERNAL API. -
super$aroundPostRestart
INTERNAL API. -
super$aroundPostStop
void super$aroundPostStop()INTERNAL API. -
super$unhandled
-
super$stash
void super$stash()Returnstrueif this persistent actor has successfully finished recovery. -
super$aroundReceive
Processes a loaded snapshot, if any. A loaded snapshot is offered with aSnapshotOffermessage to the actor'sreceiveRecover. Then initiates a message replay, either starting from the loaded snapshot or from scratch, and switches torecoveryStartedstate. All incoming messages are stashed.- Parameters:
replayMax- maximum number of messages to replay.timeout- recovery event timeout
-
journal
ActorRef journal() -
snapshotStore
ActorRef snapshotStore()Description copied from interface:SnapshotterSnapshot store plugin actor.- Specified by:
snapshotStorein interfaceSnapshotter
-
journalBatch_$eq
-
writeInProgress_$eq
void writeInProgress_$eq(boolean x$1) -
sequenceNr_$eq
void sequenceNr_$eq(long x$1) -
_lastSequenceNr_$eq
void _lastSequenceNr_$eq(long x$1) -
currentState_$eq
-
pendingStashingPersistInvocations_$eq
void pendingStashingPersistInvocations_$eq(long x$1) -
eventBatch_$eq
-
snapshotterId
String snapshotterId()ReturnspersistenceId.- Specified by:
snapshotterIdin interfaceSnapshotter
-
lastSequenceNr
long lastSequenceNr()Highest received sequence number so far or0Lif this actor hasn't replayed or stored any persistent events yet. -
snapshotSequenceNr
long snapshotSequenceNr()ReturnslastSequenceNr.- Specified by:
snapshotSequenceNrin interfaceSnapshotter
-
onReplaySuccess
void onReplaySuccess()INTERNAL API. Called whenever a message replay succeeds. May be implemented by subclass. -
onRecoveryFailure
Called whenever a message replay fails. By default it logs the error.Subclass may override to customize logging.
The actor is always stopped after this method has been invoked.
- Parameters:
cause- failure cause.event- the event that was processed inreceiveRecover, if the exception was thrown there
-
onPersistFailure
Called when persist fails. By default it logs the error. Subclass may override to customize logging and for example send negative acknowledgment to sender.The actor is always stopped after this method has been invoked.
Note that the event may or may not have been saved, depending on the type of failure.
- Parameters:
cause- failure cause.event- the event that was to be persisted
-
onPersistRejected
Called when the journal rejectedpersistof an event. The event was not stored. By default this method logs the problem as an error, and the actor continues. The callback handler that was passed to thepersistmethod will not be invoked.- Parameters:
cause- failure causeevent- the event that was to be persisted
-
stashInternally
-
unstashInternally
void unstashInternally(boolean all) -
startRecovery
-
aroundReceive
INTERNAL API.- Specified by:
aroundReceivein interfaceActor- Parameters:
receive- current behavior.message- current message.
-
aroundPreStart
void aroundPreStart()INTERNAL API.- Specified by:
aroundPreStartin interfaceActor
-
requestRecoveryPermit
void requestRecoveryPermit() -
aroundPreRestart
INTERNAL API.- Specified by:
aroundPreRestartin interfaceActor
-
aroundPostRestart
INTERNAL API.- Specified by:
aroundPostRestartin interfaceActor
-
aroundPostStop
void aroundPostStop()INTERNAL API.- Specified by:
aroundPostStopin interfaceActor
-
unhandled
Description copied from interface:ActorUser overridable callback. Is called when a message isn't handled by the current behavior of the actor by default it fails with either apekko.actor.DeathPactException(in case of an unhandledpekko.actor.Terminatedmessage) or publishes anpekko.actor.UnhandledMessageto the actor's system'spekko.event.EventStream -
changeState
-
updateLastSequenceNr
-
setLastSequenceNr
void setLastSequenceNr(long value) -
nextSequenceNr
long nextSequenceNr() -
flushJournalBatch
void flushJournalBatch() -
sendBatchedEventsToJournal
-
log
LoggingAdapter log() -
receiveRecover
scala.PartialFunction<Object,scala.runtime.BoxedUnit> receiveRecover()Recovery handler that receives persisted events during recovery. If a state snapshot has been captured and saved, this handler will receive apekko.persistence.SnapshotOffermessage 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 there is a problem with recovering the state of the actor from the journal, the error will be logged and the actor will be stopped.
- See Also:
-
pekko.persistence.Recovery
-
receiveCommand
scala.PartialFunction<Object,scala.runtime.BoxedUnit> receiveCommand()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 callingpersist. -
internalPersist
<A> void internalPersist(A event, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API -
internalPersistAll
<A> void internalPersistAll(scala.collection.immutable.Seq<A> events, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API -
batchAtomicWrite
-
internalPersistAsync
<A> void internalPersistAsync(A event, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API -
internalPersistAllAsync
<A> void internalPersistAllAsync(scala.collection.immutable.Seq<A> events, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API -
internalDeferAsync
<A> void internalDeferAsync(A event, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API -
internalDefer
<A> void internalDefer(A event, scala.Function1<A, scala.runtime.BoxedUnit> handler) Internal API -
deleteMessages
void deleteMessages(long toSequenceNr) Permanently deletes all persistent messages with sequence numbers less than or equaltoSequenceNr.If the delete is successful a
pekko.persistence.DeleteMessagesSuccesswill be sent to the actor. If the delete fails apekko.persistence.DeleteMessagesFailurewill be sent to the actor.The given
toSequenceNrmust be less than or equal tolastSequenceNr(), otherwisepekko.persistence.DeleteMessagesFailureis sent to the actor without performing the delete. All persistent messages may be deleted without specifying the actual sequence number by usingLong.MaxValueas thetoSequenceNr.- Parameters:
toSequenceNr- upper sequence number (inclusive) bound of persistent messages to be deleted.
-
internalDeleteMessagesBeforeSnapshot
void internalDeleteMessagesBeforeSnapshot(SaveSnapshotSuccess e, int keepNrOfBatches, int snapshotAfter) INTERNAL API. AnEventsourcedactor can request cleanup by deleting either a range of, or all persistent events. For example, on successful snapshot completion, delete messages within a configurablesnapshotAfterrange that are less than or equal to the givenSnapshotMetadata.sequenceNr(provided theSnapshotMetadata.sequenceNris <= tolastSequenceNr()).Or delete all by using
Long.MaxValueas thetoSequenceNrm.copy(sequenceNr = Long.MaxValue) -
recoveryRunning
boolean recoveryRunning()Returnstrueif this persistent actor is currently recovering. -
recoveryFinished
boolean recoveryFinished()Returnstrueif this persistent actor has successfully finished recovery. -
stash
void stash()Description copied from interface:StashSupportAdds the current message (the message that the actor received last) to the actor's stash.- Specified by:
stashin interfaceStashSupport
-
unstashAll
void unstashAll()Description copied from interface:StashSupportPrepends 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
MessageQueueAppendFailedExceptionis thrown.The stash is guaranteed to be empty after calling
unstashAll().- Specified by:
unstashAllin interfaceStashSupport
-
waitingRecoveryPermit
-
recoveryStarted
-
recovering
-
flushBatch
void flushBatch() -
peekApplyHandler
-
writeEventSucceeded
-
writeEventRejected
-
writeEventFailed
-