Class EffectFactories<Event,State>
- java.lang.Object
-
- akka.persistence.typed.javadsl.EffectFactories<Event,State>
-
- Direct Known Subclasses:
EffectFactories$
public class EffectFactories<Event,State> extends java.lang.Object
Factory methods for creatingEffect
directives - how an event sourced actor reacts on a command. Created viaEventSourcedBehavior.Effect
.Not for user extension
-
-
Constructor Summary
Constructors Constructor Description EffectFactories()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Effect<Event,State>
async(java.util.concurrent.CompletionStage<Effect<Event,State>> effect)
Asynchronous command handling.ReplyEffect<Event,State>
asyncReply(java.util.concurrent.CompletionStage<ReplyEffect<Event,State>> effect)
Same asEffectFactories.async
when theEventSourcedBehavior
is created withEventSourcedBehaviorWithEnforcedReplies
.EffectBuilder<Event,State>
none()
Do not persist anythingReplyEffect<Event,State>
noReply()
WhenEventSourcedBehaviorWithEnforcedReplies
is used there will be compilation errors if the returned effect isn't aReplyEffect
.EffectBuilder<Event,State>
persist(Event event)
Persist a single eventEffectBuilder<Event,State>
persist(java.util.List<Event> events)
Persist all of a the given events.<ReplyMessage>
ReplyEffect<Event,State>reply(ActorRef<ReplyMessage> replyTo, ReplyMessage replyWithMessage)
Send a reply message to the command.ReplyEffect<Event,State>
stash()
Stash the current command.EffectBuilder<Event,State>
stop()
Stop this persistent actorEffectBuilder<Event,State>
unhandled()
This command is not handled, but it is not an error that it isn't.Effect<Event,State>
unstashAll()
Unstash the commands that were stashed withEffectFactories.stash
.
-
-
-
Method Detail
-
persist
public final EffectBuilder<Event,State> persist(Event event)
Persist a single event
-
persist
public final EffectBuilder<Event,State> persist(java.util.List<Event> events)
Persist all of a the given events. Each event will be applied throughapplyEffect
separately but not until all events has been persisted. Ifcallback
is added throughEffectBuilder.thenRun
that will invoked after all the events has been persisted.
-
none
public EffectBuilder<Event,State> none()
Do not persist anything
-
stop
public EffectBuilder<Event,State> stop()
Stop this persistent actor
-
unhandled
public EffectBuilder<Event,State> unhandled()
This command is not handled, but it is not an error that it isn't.
-
stash
public ReplyEffect<Event,State> stash()
Stash the current command. Can be unstashed later withEffect.thenUnstashAll
orEffectFactories.unstashAll
.Note that the stashed commands are kept in an in-memory buffer, so in case of a crash they will not be processed. They will also be discarded if the actor is restarted (or stopped) due to that an exception was thrown from processing a command or side effect after persisting. The stash buffer is preserved for persist failures if an
onPersistFailure
backoff supervisor strategy is defined.Side effects can be chained with
thenRun
.
-
unstashAll
public Effect<Event,State> unstashAll()
Unstash the commands that were stashed withEffectFactories.stash
.It's allowed to stash messages while unstashing. Those newly added commands will not be processed by this
unstashAll
effect and have to be unstashed by anotherunstashAll
.- See Also:
EffectBuilder.thenUnstashAll
-
reply
public <ReplyMessage> ReplyEffect<Event,State> reply(ActorRef<ReplyMessage> replyTo, ReplyMessage replyWithMessage)
Send a reply message to the command. The type of the reply message must conform to the type specified by the passed replyToActorRef
.This has the same semantics as
replyTo.tell
.It is provided as a convenience (reducing boilerplate) and a way to enforce that replies are not forgotten when the
EventSourcedBehavior
is created withEventSourcedBehaviorWithEnforcedReplies
. WhenwithEnforcedReplies
is used there will be compilation errors if the returned effect isn't aReplyEffect
. The reply message will be sent also ifwithEnforcedReplies
isn't used, but then the compiler will not help finding mistakes.
-
noReply
public ReplyEffect<Event,State> noReply()
WhenEventSourcedBehaviorWithEnforcedReplies
is used there will be compilation errors if the returned effect isn't aReplyEffect
. ThisnoReply
can be used as a conscious decision that a reply shouldn't be sent for a specific command or the reply will be sent later.
-
async
public Effect<Event,State> async(java.util.concurrent.CompletionStage<Effect<Event,State>> effect)
Asynchronous command handling. The effect is run when theCompletionStage
has been completed. Any incoming commands are stashed and processed later, after current command, when theCompletionStage
has been completed.This can for example be used for retrieval of external information before validating the command.
-
asyncReply
public ReplyEffect<Event,State> asyncReply(java.util.concurrent.CompletionStage<ReplyEffect<Event,State>> effect)
Same asEffectFactories.async
when theEventSourcedBehavior
is created withEventSourcedBehaviorWithEnforcedReplies
.
-
-