Class AnnotatedCommandHandler

  • All Implemented Interfaces:
    CommandHandler

    public abstract 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 the EventHandler 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:
    {@code
     public class OrdersCommandHandler extends AnnotatedCommandHandler {
    • Constructor Detail

      • AnnotatedCommandHandler

        public AnnotatedCommandHandler()
    • Method Detail

      • 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)