Class AnnotationCommandHandlerAdapter<T>

java.lang.Object
org.axonframework.commandhandling.AnnotationCommandHandlerAdapter<T>
All Implemented Interfaces:
CommandMessageHandler, MessageHandler<CommandMessage<?>>

public class AnnotationCommandHandlerAdapter<T> extends Object implements CommandMessageHandler
Adapter that turns any @CommandHandler annotated bean into a MessageHandler implementation. Each annotated method is subscribed as a Command Handler at the CommandBus for the command type specified by the parameter of that method.
Since:
0.5
Author:
Allard Buijze
See Also:
  • Constructor Details

    • AnnotationCommandHandlerAdapter

      public AnnotationCommandHandlerAdapter(T annotatedCommandHandler)
      Wraps the given annotatedCommandHandler, allowing it to be subscribed to a Command Bus.
      Parameters:
      annotatedCommandHandler - The object containing the @CommandHandler annotated methods
    • AnnotationCommandHandlerAdapter

      public AnnotationCommandHandlerAdapter(T annotatedCommandHandler, ParameterResolverFactory parameterResolverFactory)
      Wraps the given annotatedCommandHandler, allowing it to be subscribed to a Command Bus.
      Parameters:
      annotatedCommandHandler - The object containing the @CommandHandler annotated methods
      parameterResolverFactory - The strategy for resolving handler method parameter values
    • AnnotationCommandHandlerAdapter

      public AnnotationCommandHandlerAdapter(T annotatedCommandHandler, ParameterResolverFactory parameterResolverFactory, HandlerDefinition handlerDefinition)
      Wraps the given annotatedCommandHandler, allowing it to be subscribed to a Command Bus.
      Parameters:
      annotatedCommandHandler - The object containing the @CommandHandler annotated methods
      parameterResolverFactory - The strategy for resolving handler method parameter values
      handlerDefinition - The handler definition used to create concrete handlers
  • Method Details

    • subscribe

      public Registration subscribe(CommandBus commandBus)
      Subscribe this command handler to the given commandBus. The command handler will be subscribed for each of the supported commands.
      Parameters:
      commandBus - The command bus instance to subscribe to
      Returns:
      A handle that can be used to unsubscribe
    • handle

      public Object handle(CommandMessage<?> command) throws Exception
      Invokes the @CommandHandler annotated method that accepts the given command.
      Specified by:
      handle in interface MessageHandler<T>
      Parameters:
      command - The command to handle.
      Returns:
      The result of the command handling. Is null when the annotated handler has a void return value.
      Throws:
      NoHandlerForCommandException - When no handler is found for given command.
      Exception - Any exception occurring while handling the command.
    • canHandle

      public boolean canHandle(CommandMessage<?> message)
      Description copied from interface: MessageHandler
      Indicates whether this handler can handle the given message
      Specified by:
      canHandle in interface MessageHandler<T>
      Parameters:
      message - The message to verify
      Returns:
      true if this handler can handle the message, otherwise false
    • supportedCommandNames

      public Set<String> supportedCommandNames()
      Description copied from interface: CommandMessageHandler
      Returns the set of command names this handler supports.
      Specified by:
      supportedCommandNames in interface CommandMessageHandler
      Returns:
      the set of supported command names