Class EffectFactories<Event,​State>

  • Direct Known Subclasses:
    EffectFactories$

    public class EffectFactories<Event,​State>
    extends java.lang.Object
    Factory methods for creating Effect directives - how a persistent actor reacts on a command. Created via EventSourcedBehavior.Effect.

    Not for user extension

    • Constructor Detail

      • EffectFactories

        public EffectFactories()
    • Method Detail

      • persist

        public final Effect<Event,​State> persist​(Event event)
        Persist a single event
        Parameters:
        event - (undocumented)
        Returns:
        (undocumented)
      • persist

        public final Effect<Event,​State> persist​(java.util.List<Event> events)
        Persist all of a the given events. Each event will be applied through applyEffect separately but not until all events has been persisted. If an afterCallBack is added through Effect.andThen(akka.persistence.typed.SideEffect<State>) that will invoked after all the events has been persisted.
        Parameters:
        events - (undocumented)
        Returns:
        (undocumented)
      • none

        public Effect<Event,​State> none()
        Do not persist anything
        Returns:
        (undocumented)
      • stop

        public Effect<Event,​State> stop()
        Stop this persistent actor
        Returns:
        (undocumented)
      • unhandled

        public Effect<Event,​State> unhandled()
        This command is not handled, but it is not an error that it isn't.
        Returns:
        (undocumented)
      • stash

        public ReplyEffect<Event,​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 andThen.

        Returns:
        (undocumented)
      • unstashAll

        public Effect<Event,​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.

        Side effects can be chained with andThen, but note that the side effect is run immediately and not after processing all unstashed commands.

        Returns:
        (undocumented)
        See Also:
        Effect.thenUnstashAll
      • reply

        public <ReplyMessage> ReplyEffect<Event,​State> reply​(ExpectingReply<ReplyMessage> cmd,
                                                                   ReplyMessage replyWithMessage)
        Send a reply message to the command, which implements ExpectingReply. The type of the reply message must conform to the type specified in ExpectingReply.replyTo ActorRef.

        This has the same semantics as cmd.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 with EventSourcedBehaviorWithEnforcedReplies. 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.

        Parameters:
        cmd - (undocumented)
        replyWithMessage - (undocumented)
        Returns:
        (undocumented)