Class EventSourcedBehavior<Command,​Event,​State>

    • Method Detail

      • Effect

        protected final EffectFactories<Event,​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 events).

        Returns:
        (undocumented)
      • commandHandler

        protected abstract CommandHandler<Command,​Event,​State> commandHandler()
        Implement by handling incoming commands and return an Effect() to persist or signal other effects of the command handling such as stopping the behavior or others.

        The command handlers are only invoked when the actor is running (i.e. not replaying). While the actor is persisting events, the incoming messages are stashed and only delivered to the handler once persisting them has completed.

        Returns:
        (undocumented)
      • 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".

        Returns:
        (undocumented)
      • eventHandler

        protected abstract EventHandler<State,​Event> eventHandler()
        Implement by applying the event to the current state in order to return a new state.

        The event handlers are invoked during recovery as well as running operation of this behavior, in order to keep updating the state state.

        For that reason it is strongly discouraged to perform side-effects in this handler; Side effects should be executed in andThen or recoveryCompleted blocks.

        Returns:
        (undocumented)
      • newEventHandlerBuilder

        protected final EventHandlerBuilder<State,​Event> newEventHandlerBuilder()
        Returns:
        A new, mutable, event handler builder
      • onRecoveryCompleted

        public void onRecoveryCompleted​(State state)
        The callback function is called to notify the actor that the recovery process is finished.
        Parameters:
        state - (undocumented)
      • onRecoveryFailure

        public void onRecoveryFailure​(java.lang.Throwable failure)
        The callback function is called to notify the actor that the recovery process has failed
        Parameters:
        failure - (undocumented)
      • onSnapshot

        public void onSnapshot​(SnapshotMetadata meta,
                               java.util.Optional<java.lang.Throwable> result)
        Override to get notified when a snapshot is finished.

        Parameters:
        result - None if successful otherwise contains the exception thrown when snapshotting
        meta - (undocumented)
      • shouldSnapshot

        public boolean shouldSnapshot​(State state,
                                      Event event,
                                      long sequenceNr)
        Initiates a snapshot if the given function returns true. When persisting multiple events at once the snapshot is triggered after all the events have been persisted.

        receives the State, Event and the sequenceNr used for the Event

        Parameters:
        state - (undocumented)
        event - (undocumented)
        sequenceNr - (undocumented)
        Returns:
        true if snapshot should be saved for the given event
        See Also:
        snapshotEvery()
      • snapshotEvery

        public long snapshotEvery()
        Override and define that snapshot should be saved every N events.

        If this is overridden shouldSnapshot is not used.

        Returns:
        number of events between snapshots, should be greater than 0
        See Also:
        shouldSnapshot(State, Event, long)
      • tagsFor

        public java.util.Set<java.lang.String> tagsFor​(Event event)
        The tagger function should give event tags, which will be used in persistence query
        Parameters:
        event - (undocumented)
        Returns:
        (undocumented)