T - the type of aggregate this handler handles commands forpublic class AggregateAnnotationCommandHandler<T> extends Object implements CommandMessageHandler
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
AggregateAnnotationCommandHandler.Builder<T>
Builder class to instantiate a
AggregateAnnotationCommandHandler. |
| Modifier | Constructor and Description |
|---|---|
protected |
AggregateAnnotationCommandHandler(AggregateAnnotationCommandHandler.Builder<T> builder)
Instantiate a
AggregateAnnotationCommandHandler based on the fields contained in the AggregateAnnotationCommandHandler.Builder. |
| Modifier and Type | Method and Description |
|---|---|
static <T> AggregateAnnotationCommandHandler.Builder<T> |
builder()
Instantiate a Builder to be able to create a
AggregateAnnotationCommandHandler. |
boolean |
canHandle(CommandMessage<?> message)
Indicates whether this handler can handle the given message
|
Object |
handle(CommandMessage<?> commandMessage)
Handles the given
message. |
protected Object |
resolveReturnValue(CommandMessage<?> command,
Aggregate<T> createdAggregate)
Resolves the value to return when the given
command has created the given aggregate. |
Registration |
subscribe(CommandBus commandBus)
Subscribe this command handler to the given
commandBus. |
Set<String> |
supportedCommandNames()
Returns the set of command names this handler supports.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcanHandleType, getTargetTypeprotected AggregateAnnotationCommandHandler(AggregateAnnotationCommandHandler.Builder<T> builder)
AggregateAnnotationCommandHandler based on the fields contained in the AggregateAnnotationCommandHandler.Builder.
Will assert that the Repository and CommandTargetResolver are not null, and will throw an
AxonConfigurationException if either of them is null. Next to that, the provided Builder's goal
is to create an AggregateModel (describing the structure of a given aggregate). To instantiate this
AggregateModel, either an AggregateModel can be provided directly or an aggregateType of type
Class can be used. The latter will internally resolve to an AggregateModel. Thus, either the
AggregateModel or the aggregateType should be provided. An AxonConfigurationException is thrown if
this criteria is not met.
builder - the AggregateAnnotationCommandHandler.Builder used to instantiate a AggregateAnnotationCommandHandler instancepublic static <T> AggregateAnnotationCommandHandler.Builder<T> builder()
AggregateAnnotationCommandHandler.
The CommandTargetResolver is defaulted to a AnnotationCommandTargetResolver. The
Repository is a hard requirement and as such should be provided. Next to that, this Builder's goal
is to provide an AggregateModel (describing the structure of a given aggregate). To instantiate this
AggregateModel, either an AggregateModel can be provided directly or an aggregateType of type
Class can be used. The latter will internally resolve to an AggregateModel. Thus, either the
AggregateModel or the aggregateType should be provided.
T - the type of aggregate this AggregateAnnotationCommandHandler handles commands forAggregateAnnotationCommandHandlerpublic Registration subscribe(CommandBus commandBus)
commandBus. The command handler will be subscribed for each
of the supported commands.commandBus - The command bus instance to subscribe topublic Object handle(CommandMessage<?> commandMessage) throws Exception
MessageHandlermessage.handle in interface MessageHandler<CommandMessage<?>>commandMessage - The message to be processed.Exception - any exception that occurs during message handlingpublic boolean canHandle(CommandMessage<?> message)
MessageHandlercanHandle in interface MessageHandler<CommandMessage<?>>message - The message to verifytrue if this handler can handle the message, otherwise falseprotected Object resolveReturnValue(CommandMessage<?> command, Aggregate<T> createdAggregate)
command has created the given aggregate. This
implementation returns the identifier of the created aggregate.
This method may be overridden to change the return value of this Command Handler
command - The command being executedcreatedAggregate - The aggregate that has been created as a result of the commandpublic Set<String> supportedCommandNames()
CommandMessageHandlersupportedCommandNames in interface CommandMessageHandlerCopyright © 2010–2023. All rights reserved.