java.lang.Object
dk.cloudcreate.essentials.reactive.command.AnnotatedCommandHandler
All Implemented Interfaces:
CommandHandler

public class AnnotatedCommandHandler extends Object implements CommandHandler
Extending this class will allow you to colocate multiple related Command handling methods inside the same class and use it together with the LocalCommandBus
Each 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 Details

    • AnnotatedCommandHandler

      public AnnotatedCommandHandler(Object invokeCommandHandlerMethodsOn)
      Create an AnnotatedCommandHandler that 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 an AnnotatedCommandHandler that can resolve and invoke command handler methods, i.e. methods annotated with @Handler, on this concrete subclass of AnnotatedCommandHandler
  • Method Details

    • canHandle

      public boolean canHandle(Class<?> commandType)
      Description copied from interface: CommandHandler
      This method is called by the LocalCommandBus to check if this concrete CommandHandler supports a given command type
      Specified by:
      canHandle in interface CommandHandler
      Parameters:
      commandType - the type of command being processed by the LocalCommandBus
      Returns:
      true if this command handler can handle a command of the given type - otherwise it must return false
    • handle

      public final Object handle(Object command)
      Description copied from interface: CommandHandler
      This method is called by the LocalCommandBus after it has determined that only this CommandHandler instance is capable of handling the command (based on the commands type)
      Specified by:
      handle in interface CommandHandler
      Parameters:
      command - the command
      Returns:
      the result of handling the command (if any)
    • toString

      public String toString()
      Overrides:
      toString in class Object