Class AggregateAnnotationCommandHandler<T>

java.lang.Object
org.axonframework.modelling.command.AggregateAnnotationCommandHandler<T>
Type Parameters:
T - the type of aggregate this handler handles commands for
All Implemented Interfaces:
org.axonframework.commandhandling.CommandMessageHandler, org.axonframework.messaging.MessageHandler<org.axonframework.commandhandling.CommandMessage<?>>

public class AggregateAnnotationCommandHandler<T> extends Object implements org.axonframework.commandhandling.CommandMessageHandler
Command handler that registers a set of 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
  • Constructor Details

  • Method Details

    • builder

      public static <T> AggregateAnnotationCommandHandler.Builder<T> builder()
      Instantiate a Builder to be able to create a 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.

      Type Parameters:
      T - the type of aggregate this AggregateAnnotationCommandHandler handles commands for
      Returns:
      a Builder to be able to create a AggregateAnnotationCommandHandler
    • subscribe

      public org.axonframework.common.Registration subscribe(org.axonframework.commandhandling.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(org.axonframework.commandhandling.CommandMessage<?> commandMessage) throws Exception
      Specified by:
      handle in interface org.axonframework.messaging.MessageHandler<T>
      Throws:
      Exception
    • canHandle

      public boolean canHandle(org.axonframework.commandhandling.CommandMessage<?> message)
      Specified by:
      canHandle in interface org.axonframework.messaging.MessageHandler<T>
    • resolveReturnValue

      protected Object resolveReturnValue(org.axonframework.commandhandling.CommandMessage<?> command, Aggregate<T> createdAggregate)
      Resolves the value to return when the given 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

      Parameters:
      command - The command being executed
      createdAggregate - The aggregate that has been created as a result of the command
      Returns:
      The value to report as result of the command
    • supportedCommandNames

      public Set<String> supportedCommandNames()
      Specified by:
      supportedCommandNames in interface org.axonframework.commandhandling.CommandMessageHandler