public final class ByStateCommandHandlerBuilder<Command,Event,State> extends java.lang.Object implements SignalHandlerBuilder<Command,Event,State>
CommandHandlers where different states should have different command handlers.
CommandHandler per state are added with the match methods and finally a CommandHandler is created with build().
Match statements are appended and evaluated in order, the first one to match is used. If no match is found when
evaluating the built CommandHandler for a given state a MatchError is thrown.
Instances should not be created by user code but instead accessed through ReplicatedEntity.commandHandlerBuilder(java.lang.Class<Command>).
| Constructor and Description |
|---|
ByStateCommandHandlerBuilder(java.lang.Class<State> rootStateClass) |
| Modifier and Type | Method and Description |
|---|---|
CommandHandler<Command,Event,State> |
build()
Build a command handler from the appended cases.
|
CommandHandler<Command,Event,State> |
matchAny(CommandHandler<Command,Event,State> commandHandler)
Match any state
|
<S extends State> |
matchExact(S state,
CommandHandler<Command,Event,S> commandHandler)
Match states that are equal to the given
state instance |
<S extends State> |
matchState(java.lang.Class<S> stateClass,
CommandHandler<Command,Event,S> commandHandler)
Match any state which is an instance of
S or a subtype of S |
<S extends State> |
matchState(java.lang.Class<S> stateClass,
akka.japi.pf.FI.TypedPredicate<S> predicate,
CommandHandler<Command,Event,S> commandHandler)
Match any state which is an instance of
S or a subtype of S and for which the predicate returns true |
ByStateCommandHandlerBuilder<Command,Event,State> |
matchState(akka.japi.pf.FI.TypedPredicate<State> predicate,
CommandHandler<Command,Event,State> commandHandler)
Match any state that the
predicate returns true for. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuildSignalHandlers, onReceiveTimeout, onTerminated, onTimer, signalHandlers_$eq, signalHandlerspublic ByStateCommandHandlerBuilder(java.lang.Class<State> rootStateClass)
public CommandHandler<Command,Event,State> build()
MatchError if applied to
a command that has no defined match.
The builder is reset to empty after build has been called.
build in interface SignalHandlerBuilder<Command,Event,State>public CommandHandler<Command,Event,State> matchAny(CommandHandler<Command,Event,State> commandHandler)
Builds and returns the handler since this will not let through any states to subsequent match statements
commandHandler - (undocumented)public <S extends State> ByStateCommandHandlerBuilder<Command,Event,State> matchExact(S state, CommandHandler<Command,Event,S> commandHandler)
state instancestate - (undocumented)commandHandler - (undocumented)public ByStateCommandHandlerBuilder<Command,Event,State> matchState(akka.japi.pf.FI.TypedPredicate<State> predicate, CommandHandler<Command,Event,State> commandHandler)
predicate returns true for.predicate - (undocumented)commandHandler - (undocumented)public <S extends State> ByStateCommandHandlerBuilder<Command,Event,State> matchState(java.lang.Class<S> stateClass, CommandHandler<Command,Event,S> commandHandler)
S or a subtype of S
Throws java.lang.IllegalArgumentException if stateClass is not a subtype of the root State this builder was created with
stateClass - (undocumented)commandHandler - (undocumented)public <S extends State> ByStateCommandHandlerBuilder<Command,Event,State> matchState(java.lang.Class<S> stateClass, akka.japi.pf.FI.TypedPredicate<S> predicate, CommandHandler<Command,Event,S> commandHandler)
S or a subtype of S and for which the predicate returns true
Throws java.lang.IllegalArgumentException if stateClass is not a subtype of the root State this builder was created with
stateClass - (undocumented)predicate - (undocumented)commandHandler - (undocumented)