Class AnnotatedCommandHandler
java.lang.Object
dk.cloudcreate.essentials.reactive.command.AnnotatedCommandHandler
- All Implemented Interfaces:
CommandHandler
Extending this class will allow you to colocate multiple related Command handling methods inside the same class and use it together with the
Each method must accept a single Command argument, may return a value or return void and be annotated with either the
The method argument type is matched against the concrete command type using
The method accessibility can be any combination of private, protected, public, etc.
Example:
LocalCommandBusEach method must accept a single Command argument, may return a value or return void and be annotated with either the
Handler or CmdHandler annotation.The method argument type is matched against the concrete command type using
Class.isAssignableFrom(Class).The method accessibility can be any combination of private, protected, public, etc.
Example:
public class OrdersCommandHandler extends AnnotatedCommandHandler {
@Handler
private OrderId handle(CreateOrder cmd) {
...
}
@CmdHandler
private void someMethod(ReimburseOrder cmd) {
...
}
}-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate anAnnotatedCommandHandlerthat can resolve and invoke command handler methods, i.e.AnnotatedCommandHandler(Object invokeCommandHandlerMethodsOn) Create anAnnotatedCommandHandlerthat can resolve and invoke command handler methods, i.e. -
Method Summary
Modifier and TypeMethodDescriptionbooleanThis method is called by theLocalCommandBusto check if this concreteCommandHandlersupports a given command typefinal ObjectThis method is called by theLocalCommandBusafter it has determined that only thisCommandHandlerinstance is capable of handling the command (based on the commands type)toString()
-
Constructor Details
-
AnnotatedCommandHandler
Create anAnnotatedCommandHandlerthat can resolve and invoke command handler methods, i.e. methods annotated with @Handler, on another object- Parameters:
invokeCommandHandlerMethodsOn- the object that contains the @Handler annotated methods
-
AnnotatedCommandHandler
protected AnnotatedCommandHandler()Create anAnnotatedCommandHandlerthat can resolve and invoke command handler methods, i.e. methods annotated with @Handler, on this concrete subclass ofAnnotatedCommandHandler
-
-
Method Details
-
canHandle
Description copied from interface:CommandHandlerThis method is called by theLocalCommandBusto check if this concreteCommandHandlersupports a given command type- Specified by:
canHandlein interfaceCommandHandler- Parameters:
commandType- the type of command being processed by theLocalCommandBus- Returns:
- true if this command handler can handle a command of the given type - otherwise it must return false
-
handle
Description copied from interface:CommandHandlerThis method is called by theLocalCommandBusafter it has determined that only thisCommandHandlerinstance is capable of handling the command (based on the commands type)- Specified by:
handlein interfaceCommandHandler- Parameters:
command- the command- Returns:
- the result of handling the command (if any)
-
toString
-