Class CommandHandlerWithReplyBuilderByState<Command,S extends State,State>
- java.lang.Object
-
- akka.persistence.typed.state.javadsl.CommandHandlerWithReplyBuilderByState<Command,S,State>
-
public final class CommandHandlerWithReplyBuilderByState<Command,S extends State,State> extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandHandlerWithReply<Command,State>
build()
Builds and returns a handler from the appended states.static <Command,S extends State,State>
CommandHandlerWithReplyBuilderByState<Command,S,State>builder(java.lang.Class<S> stateClass)
static <Command,State>
CommandHandlerWithReplyBuilderByState<Command,State,State>builder(java.util.function.Predicate<State> statePredicate)
CommandHandlerWithReply<Command,State>
onAnyCommand(java.util.function.BiFunction<S,Command,ReplyEffect<State>> handler)
Matches any command.CommandHandlerWithReply<Command,State>
onAnyCommand(java.util.function.Function<Command,ReplyEffect<State>> handler)
Matches any command.CommandHandlerWithReply<Command,State>
onAnyCommand(java.util.function.Supplier<ReplyEffect<State>> handler)
Matches any command.<C extends Command>
CommandHandlerWithReplyBuilderByState<Command,S,State>onCommand(java.lang.Class<C> commandClass, java.util.function.BiFunction<S,C,ReplyEffect<State>> handler)
Matches commands that are of the givencommandClass
or subclass thereof<C extends Command>
CommandHandlerWithReplyBuilderByState<Command,S,State>onCommand(java.lang.Class<C> commandClass, java.util.function.Function<C,ReplyEffect<State>> handler)
Matches commands that are of the givencommandClass
or subclass thereof.<C extends Command>
CommandHandlerWithReplyBuilderByState<Command,S,State>onCommand(java.lang.Class<C> commandClass, java.util.function.Supplier<ReplyEffect<State>> handler)
Matches commands that are of the givencommandClass
or subclass thereof.CommandHandlerWithReplyBuilderByState<Command,S,State>
onCommand(java.util.function.Predicate<Command> predicate, java.util.function.BiFunction<S,Command,ReplyEffect<State>> handler)
Matches any command which the givenpredicate
returns true for.CommandHandlerWithReplyBuilderByState<Command,S,State>
onCommand(java.util.function.Predicate<Command> predicate, java.util.function.Function<Command,ReplyEffect<State>> handler)
Matches any command which the givenpredicate
returns true for.<S2 extends State>
CommandHandlerWithReplyBuilderByState<Command,S2,State>orElse(CommandHandlerWithReplyBuilderByState<Command,S2,State> other)
Compose this builder with another builder.
-
-
-
Method Detail
-
builder
public static <Command,S extends State,State> CommandHandlerWithReplyBuilderByState<Command,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 thestateClass
- Returns:
- A new, mutable, CommandHandlerWithReplyBuilderByState
-
builder
public static <Command,State> CommandHandlerWithReplyBuilderByState<Command,State,State> builder(java.util.function.Predicate<State> statePredicate)
- Parameters:
statePredicate
- The handlers defined by this builder are used when thestatePredicate
istrue
, useful for example when state type is an Optional- Returns:
- A new, mutable, CommandHandlerWithReplyBuilderByState
-
onCommand
public CommandHandlerWithReplyBuilderByState<Command,S,State> onCommand(java.util.function.Predicate<Command> predicate, java.util.function.BiFunction<S,Command,ReplyEffect<State>> handler)
Matches any command which the givenpredicate
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.
-
onCommand
public CommandHandlerWithReplyBuilderByState<Command,S,State> onCommand(java.util.function.Predicate<Command> predicate, java.util.function.Function<Command,ReplyEffect<State>> handler)
Matches any command which the givenpredicate
returns true for.Use this when the
State
is not needed in thehandler
, otherwise there is an overloaded method that pass the state in aBiFunction
.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.
-
onCommand
public <C extends Command> CommandHandlerWithReplyBuilderByState<Command,S,State> onCommand(java.lang.Class<C> commandClass, java.util.function.BiFunction<S,C,ReplyEffect<State>> handler)
Matches commands that are of the givencommandClass
or subclass thereofNote: 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.
-
onCommand
public <C extends Command> CommandHandlerWithReplyBuilderByState<Command,S,State> onCommand(java.lang.Class<C> commandClass, java.util.function.Function<C,ReplyEffect<State>> handler)
Matches commands that are of the givencommandClass
or subclass thereof.Use this when the
State
is not needed in thehandler
, otherwise there is an overloaded method that pass the state in aBiFunction
.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.
-
onCommand
public <C extends Command> CommandHandlerWithReplyBuilderByState<Command,S,State> onCommand(java.lang.Class<C> commandClass, java.util.function.Supplier<ReplyEffect<State>> handler)
Matches commands that are of the givencommandClass
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.
-
onAnyCommand
public CommandHandlerWithReply<Command,State> onAnyCommand(java.util.function.BiFunction<S,Command,ReplyEffect<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.state.javadsl.ReplyEffect<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.- Returns:
- A CommandHandlerWithReply from the appended states.
-
onAnyCommand
public CommandHandlerWithReply<Command,State> onAnyCommand(java.util.function.Function<Command,ReplyEffect<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.state.javadsl.ReplyEffect<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.- Returns:
- A CommandHandlerWithReply from the appended states.
-
onAnyCommand
public CommandHandlerWithReply<Command,State> onAnyCommand(java.util.function.Supplier<ReplyEffect<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.state.javadsl.ReplyEffect<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.- Returns:
- A CommandHandlerWithReply from the appended states.
-
orElse
public <S2 extends State> CommandHandlerWithReplyBuilderByState<Command,S2,State> orElse(CommandHandlerWithReplyBuilderByState<Command,S2,State> other)
Compose this builder with another builder. The handlers in this builder will be tried first followed by the handlers inother
.
-
build
public CommandHandlerWithReply<Command,State> build()
Builds and returns a handler from the appended states. The returnedCommandHandlerWithReply
will throw aMatchError
if applied to a command that has no defined case.
-
-