Class EffectFactories<State>

  • Direct Known Subclasses:
    EffectFactories$

    public class EffectFactories<State>
    extends java.lang.Object
    Factory methods for creating Effect directives - how a DurableStateBehavior reacts on a command. Created via DurableStateBehavior.Effect.

    Not for user extension

    API May Change

    • Constructor Detail

      • EffectFactories

        public EffectFactories()
    • Method Detail

      • persist

        public final EffectBuilder<State> persist​(State state)
        Persist new state.

        Side effects can be chained with thenRun.

      • delete

        public EffectBuilder<State> delete()
        Delete the persisted state.

        Side effects can be chained with thenRun.

      • none

        public EffectBuilder<State> none()
        Do not persist anything

        Side effects can be chained with thenRun

      • stop

        public EffectBuilder<State> stop()
        Stop this persistent actor

        Side effects can be chained with thenRun

      • unhandled

        public EffectBuilder<State> unhandled()
        This command is not handled, but it is not an error that it isn't.

        Side effects can be chained with thenRun

      • stash

        public ReplyEffect<State> stash()
        Stash the current command. Can be unstashed later with Effect.thenUnstashAll or EffectFactories.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<State> unstashAll()
        Unstash the commands that were stashed with EffectFactories.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 another unstashAll.

        See Also:
        EffectBuilder.thenUnstashAll
      • reply

        public <ReplyMessage> ReplyEffect<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 replyTo ActorRef.

        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 DurableStateBehavior is created with DurableStateBehaviorWithEnforcedReplies. When withEnforcedReplies is used there will be compilation errors if the returned effect isn't a ReplyEffect. The reply message will be sent also if withEnforcedReplies isn't used, but then the compiler will not help finding mistakes.