Class AggregateAnnotationCommandHandler<T>
- Type Parameters:
T- the type of aggregate this handler handles commands for
- All Implemented Interfaces:
CommandMessageHandler,MessageHandler<CommandMessage<?>>
CommandHandler based on annotations of an aggregate. Those
annotations may appear on methods, in which case a specific aggregate instance needs to be targeted by the command,
or on the constructor. The latter will create a new Aggregate instance, which is then stored in the repository.
Despite being an CommandMessageHandler it does not actually handle the commands. During registration to the
CommandBus it registers the CommandMessageHandlers directly instead of itself so duplicate command
handlers can be detected and handled correctly.
- Since:
- 1.2
- Author:
- Allard Buijze
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate aAggregateAnnotationCommandHandler. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aAggregateAnnotationCommandHandlerbased on the fields contained in theAggregateAnnotationCommandHandler.Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> AggregateAnnotationCommandHandler.Builder<T> builder()Instantiate a Builder to be able to create aAggregateAnnotationCommandHandler.booleancanHandle(CommandMessage<?> message) Indicates whether this handler can handle the given messagehandle(CommandMessage<?> commandMessage) Handles the givenmessage.protected ObjectresolveReturnValue(CommandMessage<?> command, Aggregate<T> createdAggregate) Resolves the value to return when the givencommandhas created the givenaggregate.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
-
AggregateAnnotationCommandHandler
Instantiate aAggregateAnnotationCommandHandlerbased on the fields contained in theAggregateAnnotationCommandHandler.Builder.Will assert that the
RepositoryandCommandTargetResolverare notnull, and will throw anAxonConfigurationExceptionif either of them isnull. Next to that, the provided Builder's goal is to create anAggregateModel(describing the structure of a given aggregate). To instantiate this AggregateModel, either anAggregateModelcan be provided directly or anaggregateTypeof typeClasscan be used. The latter will internally resolve to an AggregateModel. Thus, either the AggregateModel or theaggregateTypeshould be provided. An AxonConfigurationException is thrown if this criteria is not met.- Parameters:
builder- theAggregateAnnotationCommandHandler.Builderused to instantiate aAggregateAnnotationCommandHandlerinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aAggregateAnnotationCommandHandler.The
CommandTargetResolveris defaulted to aAnnotationCommandTargetResolver. TheRepositoryis a hard requirement and as such should be provided. Next to that, this Builder's goal is to provide anAggregateModel(describing the structure of a given aggregate). To instantiate this AggregateModel, either anAggregateModelcan be provided directly or anaggregateTypeof typeClasscan be used. The latter will internally resolve to an AggregateModel. Thus, either the AggregateModel or theaggregateTypeshould be provided.- Type Parameters:
T- the type of aggregate thisAggregateAnnotationCommandHandlerhandles commands for- Returns:
- a Builder to be able to create a
AggregateAnnotationCommandHandler
-
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
Description copied from interface:MessageHandlerHandles the givenmessage.- Specified by:
handlein interfaceMessageHandler<T>- Parameters:
commandMessage- The message to be processed.- Returns:
- The result of the message processing.
- Throws:
Exception- any exception that occurs during message handling
-
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
-
resolveReturnValue
Resolves the value to return when the givencommandhas created the givenaggregate. This implementation returns the identifier of the created aggregate.This method may be overridden to change the return value of this Command Handler
- Parameters:
command- The command being executedcreatedAggregate- The aggregate that has been created as a result of the command- Returns:
- The value to report as result of the command
-
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
-