Class CommandHandlerBuilder<Command,Event,State>

java.lang.Object
org.apache.pekko.persistence.typed.javadsl.CommandHandlerBuilder<Command,Event,State>

public final class CommandHandlerBuilder<Command,Event,State> extends Object
  • Constructor Details

    • CommandHandlerBuilder

      public CommandHandlerBuilder()
  • Method Details

    • builder

      public static <Command, Event, State> CommandHandlerBuilder<Command,Event,State> builder()
    • forState

      public CommandHandlerBuilderByState<Command,Event,State,State> forState(Predicate<State> statePredicate)
      Use this method to define command handlers that are selected when the passed predicate holds true.

      Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your command handlers.

      Parameters:
      statePredicate - The handlers defined by this builder are used when the statePredicate is true

      Returns:
      A new, mutable, CommandHandlerBuilderByState
    • forState

      public <S extends State> CommandHandlerBuilderByState<Command,Event,S,State> forState(Class<S> stateClass, Predicate<S> statePredicate)
      Use this method to define command handlers that are selected when the passed predicate holds true for a given subtype of your model. Useful when the model is defined as class hierarchy.

      Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your command handlers.

      Parameters:
      stateClass - The handlers defined by this builder are used when the state is an instance of the stateClass
      statePredicate - The handlers defined by this builder are used when the statePredicate is true

      Returns:
      A new, mutable, CommandHandlerBuilderByState
    • forStateType

      public <S extends State> CommandHandlerBuilderByState<Command,Event,S,State> forStateType(Class<S> stateClass)
      Use this method to define command handlers for a given subtype of your model. Useful when the model is defined as class hierarchy.

      Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your command handlers.

      Parameters:
      stateClass - The handlers defined by this builder are used when the state is an instance of the stateClass.
      Returns:
      A new, mutable, CommandHandlerBuilderByState
    • forNullState

      The handlers defined by this builder are used when the state is null. This variant is particular useful when the empty state of your model is defined as null.

      Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your command handlers.

      Returns:
      A new, mutable, CommandHandlerBuilderByState
    • forNonNullState

      The handlers defined by this builder are used for any not null state.

      Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your command handlers.

      Returns:
      A new, mutable, CommandHandlerBuilderByState
    • forAnyState

      The handlers defined by this builder are used for any state. This variant is particular useful for models that have a single type (ie: no class hierarchy).

      Note: command handlers are selected in the order they are added. Once a matching is found, it's selected for handling the command and no further lookup is done. Therefore you must make sure that their matching conditions don't overlap, otherwise you risk to 'shadow' part of your command handlers. Extra care should be taken when using forAnyState() as it will match any state. Any command handler define after it will never be reached.

      Returns:
      A new, mutable, CommandHandlerBuilderByState
    • build

      public CommandHandler<Command,Event,State> build()