Class DurableStateBehavior<Command,State>
java.lang.Object
org.apache.pekko.actor.typed.Behavior<T>
org.apache.pekko.actor.typed.internal.BehaviorImpl.DeferredBehavior<Command>
org.apache.pekko.persistence.typed.state.javadsl.DurableStateBehavior<Command,State>
- Direct Known Subclasses:
DurableStateBehaviorWithEnforcedReplies
public abstract class DurableStateBehavior<Command,State>
extends BehaviorImpl.DeferredBehavior<Command>
A
Behavior for a persistent actor with durable storage of its state.
API May Change
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.pekko.actor.typed.Behavior
Behavior.BehaviorDecorators<Inner>, Behavior.BehaviorDecorators$ -
Constructor Summary
ConstructorsConstructorDescriptionDurableStateBehavior(PersistenceId persistenceId) DurableStateBehavior(PersistenceId persistenceId, BackoffSupervisorStrategy onPersistFailure) If using onPersistFailure the supervision is only around theDurableStateBehaviornot any outer setup/withTimers block. -
Method Summary
Modifier and TypeMethodDescriptionapply(TypedActorContext<Command> context) INTERNAL API: DeferredBehavior init, not for user extensionprotected abstract CommandHandler<Command,State> Implement by handling incoming commands and return anEffect()to persist or signal other effects of the command handling such as stopping the behavior or others.Override and define theDurableStateStoreplugin id that this actor should use instead of the default.protected final EffectFactories<State>Effect()Factory of effects.protected abstract StateImplement by returning the initial empty state object.final longlastSequenceNumber(ActorContext<?> ctx) The last sequence number that was persisted, can only be called from inside the handlers of aDurableStateBehaviorprotected CommandHandlerBuilder<Command,State> protected final SignalHandlerBuilder<State>protected SignalHandler<State>Override to react on general lifecycle signals andDurableStateBehaviorspecific signals (recovery related).Transform the state into another type before giving it to and from the store.tag()The tag that can be used in persistence query.Methods inherited from class org.apache.pekko.actor.typed.Behavior
BehaviorDecorators, canonicalize, existsInStack, interpretMessage, interpretSignal, isAlive, isDeferred, isUnhandled, narrow, start, validateAsInitial
-
Constructor Details
-
DurableStateBehavior
- Parameters:
persistenceId- stable unique identifier for theDurableStateBehavior
-
DurableStateBehavior
public DurableStateBehavior(PersistenceId persistenceId, BackoffSupervisorStrategy onPersistFailure) If using onPersistFailure the supervision is only around theDurableStateBehaviornot any outer setup/withTimers block. If using restart any actions e.g. scheduling timers, can be done on the PreRestart signal or on the RecoveryCompleted signal.- Parameters:
persistenceId- stable unique identifier for theDurableStateBehavioronPersistFailure- BackoffSupervisionStrategy for persist failures
-
-
Method Details
-
Effect
Factory of effects.Return effects from your handlers in order to instruct persistence on how to act on the incoming message (i.e. persist state).
-
apply
INTERNAL API: DeferredBehavior init, not for user extension- Specified by:
applyin classBehaviorImpl.DeferredBehavior<Command>
-
commandHandler
Implement by handling incoming commands and return anEffect()to persist or signal other effects of the command handling such as stopping the behavior or others.Use
newCommandHandlerBuilder()to define the command handlers.The command handlers are only invoked when the actor is running (i.e. not recovering). While the actor is persisting state, the incoming messages are stashed and only delivered to the handler once persisting them has completed.
-
durableStateStorePluginId
Override and define theDurableStateStoreplugin id that this actor should use instead of the default. -
emptyState
Implement by returning the initial empty state object. This object will be passed into this behaviors handlers, until a new state replaces it.Also known as "zero state" or "neutral state".
-
lastSequenceNumber
The last sequence number that was persisted, can only be called from inside the handlers of aDurableStateBehavior -
newCommandHandlerBuilder
- Returns:
- A new, mutable, command handler builder
-
newSignalHandlerBuilder
- Returns:
- A new, mutable signal handler builder
-
persistenceId
-
signalHandler
Override to react on general lifecycle signals andDurableStateBehaviorspecific signals (recovery related). Those are all subtypes ofpekko.persistence.typed.state.DurableStateSignal.Use
newSignalHandlerBuilder()to define the signal handler. -
snapshotAdapter
Transform the state into another type before giving it to and from the store. Can be used to migrate from different state types e.g. when migration from PersistentFSM to Typed DurableStateBehavior. -
tag
The tag that can be used in persistence query.
-