CommandHandlerHolder getCommandHandlerMethodFromClass()

in src/main/java/org/apache/fineract/cn/command/internal/CommandBus.java [150:173]


  CommandHandlerHolder getCommandHandlerMethodFromClass(final Class<?> commandClass, final Object aggregate) {
    final Method[] methods = aggregate.getClass().getDeclaredMethods();
    for (final Method method : methods) {
      final CommandHandler commandHandlerAnnotation = AnnotationUtils.findAnnotation(method, CommandHandler.class);
      if (commandHandlerAnnotation != null
          && method.getParameterCount() == 1
          && method.getParameterTypes()[0].isAssignableFrom(commandClass)) {
        this.logger.debug("CommandBus::findCommandHandler added method for {}.", commandClass.getSimpleName());

        //Note that as much of the logic of determining how to log as possible is moved into the creation of the
        //handler holder rather than performing it in the process of handling the command.  Creation of the command
        //handler holder is not performance critical, but execution of the command is.
        final Consumer<Object> logStart = getLogHandler(commandHandlerAnnotation.logStart(),
                "Handling command of type " + commandClass.getCanonicalName() + " for tenant {}, -> command {}");

        final Consumer<Object> logFinish = getLogHandler(commandHandlerAnnotation.logFinish(),
                "Handled command of type " + commandClass.getCanonicalName() + " for tenant {}, -> result {}");

        return new CommandHandlerHolder(aggregate, method, AnnotationUtils.findAnnotation(method, EventEmitter.class),
            method.getExceptionTypes(), logStart, logFinish);
      }
    }
    return null;
  }