Class DurableStateOnCommandWithReplyBehavior<Command,State>
- java.lang.Object
-
- akka.actor.typed.Behavior<T>
-
- akka.actor.typed.internal.BehaviorImpl.DeferredBehavior<Command>
-
- akka.persistence.typed.state.javadsl.DurableStateOnCommandWithReplyBehavior<Command,State>
-
public abstract class DurableStateOnCommandWithReplyBehavior<Command,State> extends BehaviorImpl.DeferredBehavior<Command>
ABehavior
for a persistent actor with durable storage of its state for projects built with Java 17 or newer where message handling can be done * using switch pattern match.Enforces replies to every received command.
For building event sourced actors with Java versions before 17, see
DurableStateBehavior
API May Change
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class akka.actor.typed.Behavior
Behavior.BehaviorDecorators<Inner>, Behavior.BehaviorDecorators$
-
-
Constructor Summary
Constructors Constructor Description DurableStateOnCommandWithReplyBehavior(PersistenceId persistenceId)
DurableStateOnCommandWithReplyBehavior(PersistenceId persistenceId, BackoffSupervisorStrategy onPersistFailure)
If using onPersistFailure the supervision is only around theDurableStateBehavior
not any outer setup/withTimers block.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Behavior<Command>
apply(TypedActorContext<Command> context)
INTERNAL API: DeferredBehavior init, not for user extensionprotected ChangeEventHandler<Command,State,?>
changeEventHandler()
API May Change: Override this and implement theChangeEventHandler
to store additional change event when the state is updated or deleted.java.lang.String
durableStateStorePluginId()
Override and define theDurableStateStore
plugin id that this actor should use instead of the default.protected EffectFactories<State>
Effect()
Factory of effects.protected abstract State
emptyState()
Implement by returning the initial empty state object.long
lastSequenceNumber(ActorContext<?> ctx)
The last sequence number that was persisted, can only be called from inside the handlers of aDurableStateBehavior
protected SignalHandlerBuilder<State>
newSignalHandlerBuilder()
protected abstract ReplyEffect<State>
onCommand(State state, Command command)
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.PersistenceId
persistenceId()
protected SignalHandler<State>
signalHandler()
Override to react on general lifecycle signals andDurableStateBehavior
specific signals (recovery related).SnapshotAdapter<State>
snapshotAdapter()
Transform the state into another type before giving it to and from the store.java.util.Optional<java.lang.Integer>
stashCapacity()
Override to define a custom stash capacity per entity.java.lang.String
tag()
The tag that can be used in persistence query.-
Methods inherited from class akka.actor.typed.Behavior
BehaviorDecorators, canonicalize, existsInStack, interpretMessage, interpretSignal, isAlive, isDeferred, isUnhandled, narrow, start, validateAsInitial
-
-
-
-
Constructor Detail
-
DurableStateOnCommandWithReplyBehavior
public DurableStateOnCommandWithReplyBehavior(PersistenceId persistenceId)
- Parameters:
persistenceId
- stable unique identifier for theDurableStateBehavior
-
DurableStateOnCommandWithReplyBehavior
public DurableStateOnCommandWithReplyBehavior(PersistenceId persistenceId, BackoffSupervisorStrategy onPersistFailure)
If using onPersistFailure the supervision is only around theDurableStateBehavior
not 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 theDurableStateBehavior
onPersistFailure
- BackoffSupervisionStrategy for persist failures
-
-
Method Detail
-
Effect
protected final EffectFactories<State> 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
public Behavior<Command> apply(TypedActorContext<Command> context)
INTERNAL API: DeferredBehavior init, not for user extension- Specified by:
apply
in classBehaviorImpl.DeferredBehavior<Command>
-
changeEventHandler
protected ChangeEventHandler<Command,State,?> changeEventHandler()
API May Change: Override this and implement theChangeEventHandler
to store additional change event when the state is updated or deleted. The event can be used in Projections.
-
durableStateStorePluginId
public java.lang.String durableStateStorePluginId()
Override and define theDurableStateStore
plugin id that this actor should use instead of the default.
-
emptyState
protected abstract State 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
public final long lastSequenceNumber(ActorContext<?> ctx)
The last sequence number that was persisted, can only be called from inside the handlers of aDurableStateBehavior
-
newSignalHandlerBuilder
protected final SignalHandlerBuilder<State> newSignalHandlerBuilder()
- Returns:
- A new, mutable signal handler builder
-
onCommand
protected abstract ReplyEffect<State> onCommand(State state, Command command)
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
DurableStateBehavior.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.
-
persistenceId
public PersistenceId persistenceId()
-
signalHandler
protected SignalHandler<State> signalHandler()
Override to react on general lifecycle signals andDurableStateBehavior
specific signals (recovery related). Those are all subtypes ofDurableStateSignal
.Use
DurableStateBehavior.newSignalHandlerBuilder()
to define the signal handler.
-
snapshotAdapter
public SnapshotAdapter<State> 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.
-
stashCapacity
public java.util.Optional<java.lang.Integer> stashCapacity()
Override to define a custom stash capacity per entity. If not defined, the defaultakka.persistence.typed.stash-capacity
will be used.
-
tag
public java.lang.String tag()
The tag that can be used in persistence query.
-
-