Class EventSourcedBehavior$


  • public class EventSourcedBehavior$
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static EventSourcedBehavior$ MODULE$
      Static reference to the singleton instance of this Scala object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <Command,​Event,​State>
      EventSourcedBehavior<Command,​Event,​State>
      apply​(PersistenceId persistenceId, State emptyState, scala.Function2<State,​Command,​Effect<Event,​State>> commandHandler, scala.Function2<State,​Event,​State> eventHandler)
      Create a Behavior for a persistent actor.
      <M> scala.Option<M> currentMetadata​(ActorContext<?> context, scala.reflect.ClassTag<M> evidence$1)
      The metadata of the given type that was persisted with an event, if any.
      long lastSequenceNumber​(ActorContext<?> context)
      The last sequence number that was persisted, can only be called from inside the handlers of an EventSourcedBehavior
      <Command,​Event,​State>
      EventSourcedBehavior<Command,​Event,​State>
      withEnforcedReplies​(PersistenceId persistenceId, State emptyState, scala.Function2<State,​Command,​ReplyEffect<Event,​State>> commandHandler, scala.Function2<State,​Event,​State> eventHandler)
      Create a Behavior for a persistent actor that is enforcing that replies to commands are not forgotten.
      <Command,​Event,​State>
      EventSourcedBehavior<Command,​Event,​State>
      withEnforcedRepliesMutableState​(PersistenceId persistenceId, scala.Function0<State> emptyStateFactory, scala.Function2<State,​Command,​ReplyEffect<Event,​State>> commandHandler, scala.Function2<State,​Event,​State> eventHandler)
      Create a Behavior with mutable state for a persistent actor that is enforcing that replies to commands are not forgotten.
      <Command,​Event,​State>
      EventSourcedBehavior<Command,​Event,​State>
      withMutableState​(PersistenceId persistenceId, scala.Function0<State> emptyStateFactory, scala.Function2<State,​Command,​Effect<Event,​State>> commandHandler, scala.Function2<State,​Event,​State> eventHandler)
      Create a Behavior with mutable state for a persistent actor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MODULE$

        public static final EventSourcedBehavior$ MODULE$
        Static reference to the singleton instance of this Scala object.
    • Constructor Detail

      • EventSourcedBehavior$

        public EventSourcedBehavior$()
    • Method Detail

      • apply

        public <Command,​Event,​State> EventSourcedBehavior<Command,​Event,​State> apply​(PersistenceId persistenceId,
                                                                                                             State emptyState,
                                                                                                             scala.Function2<State,​Command,​Effect<Event,​State>> commandHandler,
                                                                                                             scala.Function2<State,​Event,​State> eventHandler)
        Create a Behavior for a persistent actor.

        This can be used when the state is immutable, but if the state is mutable, it is important to use the withMutableState that takes emptyStateFactory: () => State parameter.

        Parameters:
        persistenceId - stable unique identifier for the event sourced behavior
        emptyState - the intial state for the entity before any events have been processed
        commandHandler - map commands to effects e.g. persisting events, replying to commands
        eventHandler - compute the new state given the current state when an event has been persisted
      • withMutableState

        public <Command,​Event,​State> EventSourcedBehavior<Command,​Event,​State> withMutableState​(PersistenceId persistenceId,
                                                                                                                        scala.Function0<State> emptyStateFactory,
                                                                                                                        scala.Function2<State,​Command,​Effect<Event,​State>> commandHandler,
                                                                                                                        scala.Function2<State,​Event,​State> eventHandler)
        Create a Behavior with mutable state for a persistent actor.

        When the state is mutable, it is important to use this variant to make sure that the state instance is recreated in case of failure restarts.

        Parameters:
        persistenceId - stable unique identifier for the event sourced behavior
        emptyStateFactory - factory function of the intial state for the entity before any events have been processed
        commandHandler - map commands to effects e.g. persisting events, replying to commands
        eventHandler - compute the new state given the current state when an event has been persisted
      • withEnforcedReplies

        public <Command,​Event,​State> EventSourcedBehavior<Command,​Event,​State> withEnforcedReplies​(PersistenceId persistenceId,
                                                                                                                           State emptyState,
                                                                                                                           scala.Function2<State,​Command,​ReplyEffect<Event,​State>> commandHandler,
                                                                                                                           scala.Function2<State,​Event,​State> eventHandler)
        Create a Behavior for a persistent actor that is enforcing that replies to commands are not forgotten. Then there will be compilation errors if the returned effect isn't a ReplyEffect, which can be created with Effect.reply, Effect.noReply, EffectBuilder.thenReply, or EffectBuilder.thenNoReply.

        This can be used when the state is immutable, but if the state is mutable, it is important to use the withEnforcedRepliesMutableState that takes emptyStateFactory: () => State parameter.

      • withEnforcedRepliesMutableState

        public <Command,​Event,​State> EventSourcedBehavior<Command,​Event,​State> withEnforcedRepliesMutableState​(PersistenceId persistenceId,
                                                                                                                                       scala.Function0<State> emptyStateFactory,
                                                                                                                                       scala.Function2<State,​Command,​ReplyEffect<Event,​State>> commandHandler,
                                                                                                                                       scala.Function2<State,​Event,​State> eventHandler)
        Create a Behavior with mutable state for a persistent actor that is enforcing that replies to commands are not forgotten. Then there will be compilation errors if the returned effect isn't a ReplyEffect, which can be created with Effect.reply, Effect.noReply, EffectBuilder.thenReply, or EffectBuilder.thenNoReply.

        When the state is mutable, it is important to use this variant to make sure that the state instance is recreated in case of failure restarts.

      • lastSequenceNumber

        public long lastSequenceNumber​(ActorContext<?> context)
        The last sequence number that was persisted, can only be called from inside the handlers of an EventSourcedBehavior
      • currentMetadata

        public <M> scala.Option<M> currentMetadata​(ActorContext<?> context,
                                                   scala.reflect.ClassTag<M> evidence$1)
        The metadata of the given type that was persisted with an event, if any. Can only be called from inside the event handler or RecoveryCompleted of an EventSourcedBehavior.