Class AnnotationCommandHandlerAdapter<T>
java.lang.Object
org.axonframework.commandhandling.AnnotationCommandHandlerAdapter<T>
- All Implemented Interfaces:
CommandMessageHandler,MessageHandler<CommandMessage<?>>
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 Summary
ConstructorsConstructorDescriptionAnnotationCommandHandlerAdapter(T annotatedCommandHandler) Wraps the givenannotatedCommandHandler, allowing it to be subscribed to a Command Bus.AnnotationCommandHandlerAdapter(T annotatedCommandHandler, ParameterResolverFactory parameterResolverFactory) Wraps the givenannotatedCommandHandler, allowing it to be subscribed to a Command Bus.AnnotationCommandHandlerAdapter(T annotatedCommandHandler, ParameterResolverFactory parameterResolverFactory, HandlerDefinition handlerDefinition) Wraps the givenannotatedCommandHandler, allowing it to be subscribed to a Command Bus. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanHandle(CommandMessage<?> message) Indicates whether this handler can handle the given messagehandle(CommandMessage<?> command) Invokes the@CommandHandlerannotated method that accepts the givencommand.subscribe(CommandBus commandBus) Subscribe this command handler to the givencommandBus.Returns the set of command names this handler supports.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.MessageHandler
canHandleType, getTargetType
-
Constructor Details
-
AnnotationCommandHandlerAdapter
Wraps the givenannotatedCommandHandler, 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 givenannotatedCommandHandler, allowing it to be subscribed to a Command Bus.- Parameters:
annotatedCommandHandler- The object containing the @CommandHandler annotated methodsparameterResolverFactory- The strategy for resolving handler method parameter values
-
AnnotationCommandHandlerAdapter
public AnnotationCommandHandlerAdapter(T annotatedCommandHandler, ParameterResolverFactory parameterResolverFactory, HandlerDefinition handlerDefinition) Wraps the givenannotatedCommandHandler, allowing it to be subscribed to a Command Bus.- Parameters:
annotatedCommandHandler- The object containing the @CommandHandler annotated methodsparameterResolverFactory- The strategy for resolving handler method parameter valueshandlerDefinition- The handler definition used to create concrete handlers
-
-
Method Details
-
subscribe
Subscribe this command handler to the givencommandBus. 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
Invokes the@CommandHandlerannotated method that accepts the givencommand.- Specified by:
handlein interfaceMessageHandler<T>- Parameters:
command- The command to handle.- Returns:
- The result of the command handling. Is
nullwhen the annotated handler has avoidreturn value. - Throws:
NoHandlerForCommandException- When no handler is found for givencommand.Exception- Any exception occurring while handling the command.
-
canHandle
Description copied from interface:MessageHandlerIndicates whether this handler can handle the given message- Specified by:
canHandlein interfaceMessageHandler<T>- Parameters:
message- The message to verify- Returns:
trueif this handler can handle the message, otherwisefalse
-
supportedCommandNames
Description copied from interface:CommandMessageHandlerReturns the set of command names this handler supports.- Specified by:
supportedCommandNamesin interfaceCommandMessageHandler- Returns:
- the set of supported command names
-