fix more with reply types in persistence-typed examples
This commit is contained in:
parent
f85e0e7c62
commit
88ee18c3f7
5 changed files with 53 additions and 45 deletions
|
|
@ -210,11 +210,11 @@ final class CommandHandlerWithReplyBuilderByState[Command, Event, S <: State, St
|
|||
/**
|
||||
* Matches any command which the given `predicate` returns true for.
|
||||
*
|
||||
* Note: command handlers are matched in the order they are added. Once a matching is found, it's selected for handling 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.
|
||||
*/
|
||||
def matchCommand(predicate: Predicate[Command], handler: BiFunction[S, Command, ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
def onCommand(predicate: Predicate[Command], handler: BiFunction[S, Command, ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
addCase(cmd ⇒ predicate.test(cmd), handler)
|
||||
this
|
||||
}
|
||||
|
|
@ -225,11 +225,11 @@ final class CommandHandlerWithReplyBuilderByState[Command, Event, S <: State, St
|
|||
* 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 matched in the order they are added. Once a matching is found, it's selected for handling 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.
|
||||
*/
|
||||
def matchCommand(predicate: Predicate[Command], handler: JFunction[Command, ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
def onCommand(predicate: Predicate[Command], handler: JFunction[Command, ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
addCase(cmd ⇒ predicate.test(cmd), new BiFunction[S, Command, ReplyEffect[Event, State]] {
|
||||
override def apply(state: S, cmd: Command): ReplyEffect[Event, State] = handler(cmd)
|
||||
})
|
||||
|
|
@ -239,11 +239,11 @@ final class CommandHandlerWithReplyBuilderByState[Command, Event, S <: State, St
|
|||
/**
|
||||
* Matches commands that are of the given `commandClass` or subclass thereof
|
||||
*
|
||||
* Note: command handlers are matched in the order they are added. Once a matching is found, it's selected for handling 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.
|
||||
*/
|
||||
def matchCommand[C <: Command](commandClass: Class[C], handler: BiFunction[S, C, ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
def onCommand[C <: Command](commandClass: Class[C], handler: BiFunction[S, C, ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
addCase(cmd ⇒ commandClass.isAssignableFrom(cmd.getClass), handler.asInstanceOf[BiFunction[S, Command, ReplyEffect[Event, State]]])
|
||||
this
|
||||
}
|
||||
|
|
@ -254,12 +254,12 @@ final class CommandHandlerWithReplyBuilderByState[Command, Event, S <: State, St
|
|||
* 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 matched in the order they are added. Once a matching is found, it's selected for handling 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.
|
||||
*/
|
||||
def matchCommand[C <: Command](commandClass: Class[C], handler: JFunction[C, ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
matchCommand[C](commandClass, new BiFunction[S, C, ReplyEffect[Event, State]] {
|
||||
def onCommand[C <: Command](commandClass: Class[C], handler: JFunction[C, ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
onCommand[C](commandClass, new BiFunction[S, C, ReplyEffect[Event, State]] {
|
||||
override def apply(state: S, cmd: C): ReplyEffect[Event, State] = handler(cmd)
|
||||
})
|
||||
}
|
||||
|
|
@ -269,12 +269,12 @@ final class CommandHandlerWithReplyBuilderByState[Command, Event, S <: State, St
|
|||
*
|
||||
* Use this when you just need to initialize the `State` without using any data from the command.
|
||||
*
|
||||
* Note: command handlers are matched in the order they are added. Once a matching is found, it's selected for handling 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.
|
||||
*/
|
||||
def matchCommand[C <: Command](commandClass: Class[C], handler: Supplier[ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
matchCommand[C](commandClass, new BiFunction[S, C, ReplyEffect[Event, State]] {
|
||||
def onCommand[C <: Command](commandClass: Class[C], handler: Supplier[ReplyEffect[Event, State]]): CommandHandlerWithReplyBuilderByState[Command, Event, S, State] = {
|
||||
onCommand[C](commandClass, new BiFunction[S, C, ReplyEffect[Event, State]] {
|
||||
override def apply(state: S, cmd: C): ReplyEffect[Event, State] = handler.get()
|
||||
})
|
||||
}
|
||||
|
|
@ -285,16 +285,16 @@ final class CommandHandlerWithReplyBuilderByState[Command, Event, S <: State, St
|
|||
* 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 matched in the order they are added. Once a matching is found, it's selected for handling 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.
|
||||
*
|
||||
* Extra care should be taken when using [[matchAny]] as it will match any command.
|
||||
* Extra care should be taken when using [[onAnyCommand]] 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.
|
||||
*
|
||||
* @return A CommandHandlerWithReply from the appended states.
|
||||
*/
|
||||
def matchAny(handler: BiFunction[S, Command, ReplyEffect[Event, State]]): CommandHandlerWithReply[Command, Event, State] = {
|
||||
def onAnyCommand(handler: BiFunction[S, Command, ReplyEffect[Event, State]]): CommandHandlerWithReply[Command, Event, State] = {
|
||||
addCase(_ ⇒ true, handler)
|
||||
build()
|
||||
}
|
||||
|
|
@ -307,16 +307,16 @@ final class CommandHandlerWithReplyBuilderByState[Command, Event, S <: State, St
|
|||
*
|
||||
* Use this when you just need to return an [[ReplyEffect]] without using any data from the state.
|
||||
*
|
||||
* Note: command handlers are matched in the order they are added. Once a matching is found, it's selected for handling 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.
|
||||
*
|
||||
* Extra care should be taken when using [[matchAny]] as it will match any command.
|
||||
* Extra care should be taken when using [[onAnyCommand]] 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.
|
||||
*
|
||||
* @return A CommandHandlerWithReply from the appended states.
|
||||
*/
|
||||
def matchAny(handler: JFunction[Command, ReplyEffect[Event, State]]): CommandHandlerWithReply[Command, Event, State] = {
|
||||
def onAnyCommand(handler: JFunction[Command, ReplyEffect[Event, State]]): CommandHandlerWithReply[Command, Event, State] = {
|
||||
addCase(_ ⇒ true, new BiFunction[S, Command, ReplyEffect[Event, State]] {
|
||||
override def apply(state: S, cmd: Command): ReplyEffect[Event, State] = handler(cmd)
|
||||
})
|
||||
|
|
@ -330,16 +330,16 @@ final class CommandHandlerWithReplyBuilderByState[Command, Event, S <: State, St
|
|||
*
|
||||
* 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 matched in the order they are added. Once a matching is found, it's selected for handling 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.
|
||||
*
|
||||
* Extra care should be taken when using [[matchAny]] as it will match any command.
|
||||
* Extra care should be taken when using [[onAnyCommand]] 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.
|
||||
*
|
||||
* @return A CommandHandlerWithReply from the appended states.
|
||||
*/
|
||||
def matchAny(handler: Supplier[ReplyEffect[Event, State]]): CommandHandlerWithReply[Command, Event, State] = {
|
||||
def onAnyCommand(handler: Supplier[ReplyEffect[Event, State]]): CommandHandlerWithReply[Command, Event, State] = {
|
||||
addCase(_ ⇒ true, new BiFunction[S, Command, ReplyEffect[Event, State]] {
|
||||
override def apply(state: S, cmd: Command): ReplyEffect[Event, State] = handler.get()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import akka.actor.typed.javadsl.ActorContext;
|
|||
import akka.actor.typed.javadsl.Behaviors;
|
||||
import akka.persistence.typed.ExpectingReply;
|
||||
import akka.persistence.typed.PersistenceId;
|
||||
import akka.persistence.typed.javadsl.CommandHandler;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerBuilder;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerWithReply;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerWithReplyBuilder;
|
||||
import akka.persistence.typed.javadsl.EventHandler;
|
||||
import akka.persistence.typed.javadsl.EventHandlerBuilder;
|
||||
import akka.persistence.typed.javadsl.EventSourcedBehaviorWithEnforcedReplies;
|
||||
|
|
@ -240,9 +240,9 @@ public interface AccountExampleWithCommandHandlersInState {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler<AccountCommand, AccountEvent, Account> commandHandler() {
|
||||
CommandHandlerBuilder<AccountCommand, AccountEvent, Account> builder =
|
||||
newCommandHandlerBuilder();
|
||||
public CommandHandlerWithReply<AccountCommand, AccountEvent, Account> commandHandler() {
|
||||
CommandHandlerWithReplyBuilder<AccountCommand, AccountEvent, Account> builder =
|
||||
newCommandHandlerWithReplyBuilder();
|
||||
|
||||
builder
|
||||
.forStateType(EmptyAccount.class)
|
||||
|
|
@ -255,7 +255,9 @@ public interface AccountExampleWithCommandHandlersInState {
|
|||
.onCommand(GetBalance.class, OpenedAccount::getBalance)
|
||||
.onCommand(CloseAccount.class, OpenedAccount::closeAccount);
|
||||
|
||||
builder.forStateType(ClosedAccount.class).onAnyCommand(() -> Effect().unhandled());
|
||||
builder
|
||||
.forStateType(ClosedAccount.class)
|
||||
.onAnyCommand(() -> Effect().unhandled().thenNoReply());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import akka.actor.typed.javadsl.ActorContext;
|
|||
import akka.actor.typed.javadsl.Behaviors;
|
||||
import akka.persistence.typed.ExpectingReply;
|
||||
import akka.persistence.typed.PersistenceId;
|
||||
import akka.persistence.typed.javadsl.CommandHandler;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerBuilder;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerWithReply;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerWithReplyBuilder;
|
||||
import akka.persistence.typed.javadsl.ReplyEffect;
|
||||
import akka.persistence.typed.javadsl.EventHandler;
|
||||
import akka.persistence.typed.javadsl.EventHandlerBuilder;
|
||||
|
|
@ -209,9 +209,9 @@ public interface AccountExampleWithEventHandlersInState {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler<AccountCommand, AccountEvent, Account> commandHandler() {
|
||||
CommandHandlerBuilder<AccountCommand, AccountEvent, Account> builder =
|
||||
newCommandHandlerBuilder();
|
||||
public CommandHandlerWithReply<AccountCommand, AccountEvent, Account> commandHandler() {
|
||||
CommandHandlerWithReplyBuilder<AccountCommand, AccountEvent, Account> builder =
|
||||
newCommandHandlerWithReplyBuilder();
|
||||
|
||||
builder.forStateType(EmptyAccount.class).onCommand(CreateAccount.class, this::createAccount);
|
||||
|
||||
|
|
@ -222,7 +222,9 @@ public interface AccountExampleWithEventHandlersInState {
|
|||
.onCommand(GetBalance.class, this::getBalance)
|
||||
.onCommand(CloseAccount.class, this::closeAccount);
|
||||
|
||||
builder.forStateType(ClosedAccount.class).onAnyCommand(() -> Effect().unhandled());
|
||||
builder
|
||||
.forStateType(ClosedAccount.class)
|
||||
.onAnyCommand(() -> Effect().unhandled().thenNoReply());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import akka.actor.typed.javadsl.ActorContext;
|
|||
import akka.actor.typed.javadsl.Behaviors;
|
||||
import akka.persistence.typed.ExpectingReply;
|
||||
import akka.persistence.typed.PersistenceId;
|
||||
import akka.persistence.typed.javadsl.CommandHandler;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerBuilder;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerWithReply;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerWithReplyBuilder;
|
||||
import akka.persistence.typed.javadsl.EventHandler;
|
||||
import akka.persistence.typed.javadsl.EventHandlerBuilder;
|
||||
import akka.persistence.typed.javadsl.EventSourcedBehaviorWithEnforcedReplies;
|
||||
|
|
@ -203,9 +203,9 @@ public interface AccountExampleWithMutableState {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler<AccountCommand, AccountEvent, Account> commandHandler() {
|
||||
CommandHandlerBuilder<AccountCommand, AccountEvent, Account> builder =
|
||||
newCommandHandlerBuilder();
|
||||
public CommandHandlerWithReply<AccountCommand, AccountEvent, Account> commandHandler() {
|
||||
CommandHandlerWithReplyBuilder<AccountCommand, AccountEvent, Account> builder =
|
||||
newCommandHandlerWithReplyBuilder();
|
||||
|
||||
builder.forStateType(EmptyAccount.class).onCommand(CreateAccount.class, this::createAccount);
|
||||
|
||||
|
|
@ -216,7 +216,9 @@ public interface AccountExampleWithMutableState {
|
|||
.onCommand(GetBalance.class, this::getBalance)
|
||||
.onCommand(CloseAccount.class, this::closeAccount);
|
||||
|
||||
builder.forStateType(ClosedAccount.class).onAnyCommand(() -> Effect().unhandled());
|
||||
builder
|
||||
.forStateType(ClosedAccount.class)
|
||||
.onAnyCommand(() -> Effect().unhandled().thenNoReply());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import akka.actor.typed.javadsl.ActorContext;
|
|||
import akka.actor.typed.javadsl.Behaviors;
|
||||
import akka.persistence.typed.ExpectingReply;
|
||||
import akka.persistence.typed.PersistenceId;
|
||||
import akka.persistence.typed.javadsl.CommandHandler;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerBuilder;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerWithReply;
|
||||
import akka.persistence.typed.javadsl.CommandHandlerWithReplyBuilder;
|
||||
import akka.persistence.typed.javadsl.EventHandler;
|
||||
import akka.persistence.typed.javadsl.EventHandlerBuilder;
|
||||
import akka.persistence.typed.javadsl.EventSourcedBehaviorWithEnforcedReplies;
|
||||
|
|
@ -201,9 +201,9 @@ public interface AccountExampleWithNullState {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler<AccountCommand, AccountEvent, Account> commandHandler() {
|
||||
CommandHandlerBuilder<AccountCommand, AccountEvent, Account> builder =
|
||||
newCommandHandlerBuilder();
|
||||
public CommandHandlerWithReply<AccountCommand, AccountEvent, Account> commandHandler() {
|
||||
CommandHandlerWithReplyBuilder<AccountCommand, AccountEvent, Account> builder =
|
||||
newCommandHandlerWithReplyBuilder();
|
||||
|
||||
builder.forNullState().onCommand(CreateAccount.class, this::createAccount);
|
||||
|
||||
|
|
@ -214,7 +214,9 @@ public interface AccountExampleWithNullState {
|
|||
.onCommand(GetBalance.class, this::getBalance)
|
||||
.onCommand(CloseAccount.class, this::closeAccount);
|
||||
|
||||
builder.forStateType(ClosedAccount.class).onAnyCommand(() -> Effect().unhandled());
|
||||
builder
|
||||
.forStateType(ClosedAccount.class)
|
||||
.onAnyCommand(() -> Effect().unhandled().thenNoReply());
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue