Class CommandHandlerWithReplyBuilderByState<Command,​Event,​S extends State,​State>


  • public final class CommandHandlerWithReplyBuilderByState<Command,​Event,​S extends State,​State>
    extends java.lang.Object
    • Constructor Detail

      • CommandHandlerWithReplyBuilderByState

        public CommandHandlerWithReplyBuilderByState​(java.lang.Class<S> stateClass,
                                                     java.util.function.Predicate<S> statePredicate)
    • Method Detail

      • builder

        public static <Command,​Event,​S extends State,​State> CommandHandlerWithReplyBuilderByState<Command,​Event,​S,​State> builder​(java.lang.Class<S> stateClass)
        Parameters:
        stateClass - The handlers defined by this builder are used when the state is an instance of the stateClass
        Returns:
        A new, mutable, CommandHandlerWithReplyBuilderByState
      • builder

        public static <Command,​Event,​State> CommandHandlerWithReplyBuilderByState<Command,​Event,​State,​State> builder​(java.util.function.Predicate<State> statePredicate)
        Parameters:
        statePredicate - The handlers defined by this builder are used when the statePredicate is true, useful for example when state type is an Optional
        Returns:
        A new, mutable, CommandHandlerWithReplyBuilderByState
      • onCommand

        public CommandHandlerWithReplyBuilderByState<Command,​Event,​S,​State> onCommand​(java.util.function.Predicate<Command> predicate,
                                                                                                        java.util.function.BiFunction<S,​Command,​ReplyEffect<Event,​State>> handler)
        Matches any command which the given predicate returns true for.

        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:
        predicate - (undocumented)
        handler - (undocumented)
        Returns:
        (undocumented)
      • onCommand

        public CommandHandlerWithReplyBuilderByState<Command,​Event,​S,​State> onCommand​(java.util.function.Predicate<Command> predicate,
                                                                                                        java.util.function.Function<Command,​ReplyEffect<Event,​State>> handler)
        Matches any command which the given predicate returns true for.

        Use this when the State is not needed in the handler, otherwise there is an overloaded method that pass the state in a BiFunction.

        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:
        predicate - (undocumented)
        handler - (undocumented)
        Returns:
        (undocumented)
      • onCommand

        public <C extends CommandCommandHandlerWithReplyBuilderByState<Command,​Event,​S,​State> onCommand​(java.lang.Class<C> commandClass,
                                                                                                                            java.util.function.BiFunction<S,​C,​ReplyEffect<Event,​State>> handler)
        Matches commands that are of the given commandClass or subclass thereof

        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:
        commandClass - (undocumented)
        handler - (undocumented)
        Returns:
        (undocumented)
      • onCommand

        public <C extends CommandCommandHandlerWithReplyBuilderByState<Command,​Event,​S,​State> onCommand​(java.lang.Class<C> commandClass,
                                                                                                                            java.util.function.Function<C,​ReplyEffect<Event,​State>> handler)
        Matches commands that are of the given commandClass or subclass thereof.

        Use this when the State is not needed in the handler, otherwise there is an overloaded method that pass the state in a BiFunction.

        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:
        commandClass - (undocumented)
        handler - (undocumented)
        Returns:
        (undocumented)
      • onCommand

        public <C extends CommandCommandHandlerWithReplyBuilderByState<Command,​Event,​S,​State> onCommand​(java.lang.Class<C> commandClass,
                                                                                                                            java.util.function.Supplier<ReplyEffect<Event,​State>> handler)
        Matches commands that are of the given commandClass or subclass thereof.

        Use this when you just need to initialize the State without using any data from the command.

        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:
        commandClass - (undocumented)
        handler - (undocumented)
        Returns:
        (undocumented)
      • onAnyCommand

        public CommandHandlerWithReply<Command,​Event,​State> onAnyCommand​(java.util.function.BiFunction<S,​Command,​ReplyEffect<Event,​State>> handler)
        Matches any command.

        Use this to declare a command handler that will match any command. This is particular useful when encoding a finite state machine in which the final state is not supposed to handle any new command.

        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 onAnyCommand(java.util.function.BiFunction<S,Command,akka.persistence.typed.javadsl.ReplyEffect<Event,State>>) as it will match any command. This method builds and returns the command handler since this will not let through any states to subsequent match statements.

        Parameters:
        handler - (undocumented)
        Returns:
        A CommandHandlerWithReply from the appended states.
      • onAnyCommand

        public CommandHandlerWithReply<Command,​Event,​State> onAnyCommand​(java.util.function.Function<Command,​ReplyEffect<Event,​State>> handler)
        Matches any command.

        Use this to declare a command handler that will match any command. This is particular useful when encoding a finite state machine in which the final state is not supposed to handle any new command.

        Use this when you just need to return an ReplyEffect without using any data from the 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.

        Extra care should be taken when using onAnyCommand(java.util.function.BiFunction<S,Command,akka.persistence.typed.javadsl.ReplyEffect<Event,State>>) as it will match any command. This method builds and returns the command handler since this will not let through any states to subsequent match statements.

        Parameters:
        handler - (undocumented)
        Returns:
        A CommandHandlerWithReply from the appended states.
      • onAnyCommand

        public CommandHandlerWithReply<Command,​Event,​State> onAnyCommand​(java.util.function.Supplier<ReplyEffect<Event,​State>> handler)
        Matches any command.

        Use this to declare a command handler that will match any command. This is particular useful when encoding a finite state machine in which the final state is not supposed to handle any new command.

        Use this when you just need to return an ReplyEffect without using any data from the command or from the 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.

        Extra care should be taken when using onAnyCommand(java.util.function.BiFunction<S,Command,akka.persistence.typed.javadsl.ReplyEffect<Event,State>>) as it will match any command. This method builds and returns the command handler since this will not let through any states to subsequent match statements.

        Parameters:
        handler - (undocumented)
        Returns:
        A CommandHandlerWithReply from the appended states.