org.axonframework.commandhandling.annotation
Class AggregateAnnotationCommandHandler<T extends AggregateRoot>

java.lang.Object
  extended by org.axonframework.commandhandling.annotation.AggregateAnnotationCommandHandler<T>
Type Parameters:
T - the type of aggregate this handler handles commands for
All Implemented Interfaces:
CommandHandler<Object>, Subscribable

public class AggregateAnnotationCommandHandler<T extends AggregateRoot>
extends Object
implements Subscribable, CommandHandler<Object>

Command handler that handles commands based on CommandHandler annotations on 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.

Since:
1.2
Author:
Allard Buijze

Constructor Summary
AggregateAnnotationCommandHandler(Class<T> aggregateType, Repository<T> repository)
          Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, using the given repository to add and load aggregate instances.
AggregateAnnotationCommandHandler(Class<T> aggregateType, Repository<T> repository, CommandBus commandBus)
          Deprecated. Use AggregateAnnotationCommandHandler(Class, org.axonframework.repository.Repository) and subscribe the adapter to the command bus using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler). Alternatively, use subscribe(Class, org.axonframework.repository.Repository, org.axonframework.commandhandling.CommandBus).
AggregateAnnotationCommandHandler(Class<T> aggregateType, Repository<T> repository, CommandBus commandBus, CommandTargetResolver commandTargetResolver)
          Deprecated. Use AggregateAnnotationCommandHandler(Class, org.axonframework.repository.Repository, org.axonframework.commandhandling.CommandTargetResolver) and subscribe the handler to the command bus using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler). Alternatively, use subscribe(Class, org.axonframework.repository.Repository, org.axonframework.commandhandling.CommandBus, org.axonframework.commandhandling.CommandTargetResolver).
AggregateAnnotationCommandHandler(Class<T> aggregateType, Repository<T> repository, CommandTargetResolver commandTargetResolver)
          Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, using the given repository to add and load aggregate instances and the default ParameterResolverFactory.
AggregateAnnotationCommandHandler(Class<T> aggregateType, Repository<T> repository, CommandTargetResolver commandTargetResolver, ParameterResolverFactory parameterResolverFactory)
          Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, using the given repository to add and load aggregate instances and the given parameterResolverFactory.
 
Method Summary
 Object handle(CommandMessage<Object> commandMessage, UnitOfWork unitOfWork)
          Handles the given command.
protected  Object resolveReturnValue(CommandMessage<?> command, T createdAggregate)
          Resolves the value to return when the given command has created the given aggregate.
 void subscribe()
          Deprecated. subscribing this handler should be done using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler). Retrieve the supported commands with supportedCommands().
static void subscribe(AggregateAnnotationCommandHandler<?> aggregateAnnotationCommandHandler, CommandBus commandBus)
          Subscribe the given aggregateAnnotationCommandHandler to the given commandBus.
static
<T extends AggregateRoot>
AggregateAnnotationCommandHandler
subscribe(Class<T> aggregateType, Repository<T> repository, CommandBus commandBus)
          Subscribe a handler for the given aggregate type to the given command bus.
static
<T extends AggregateRoot>
AggregateAnnotationCommandHandler
subscribe(Class<T> aggregateType, Repository<T> repository, CommandBus commandBus, CommandTargetResolver commandTargetResolver)
          Subscribe a handler for the given aggregate type to the given command bus.
 Set<String> supportedCommands()
          Returns the set of commands supported by the annotated command handler managed by this adapter.
 void unsubscribe()
          Deprecated. unsubscribing this handler should be done using CommandBus.unsubscribe(String, org.axonframework.commandhandling.CommandHandler). Retrieve the supported commands with supportedCommands().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AggregateAnnotationCommandHandler

public AggregateAnnotationCommandHandler(Class<T> aggregateType,
                                         Repository<T> repository)
Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, using the given repository to add and load aggregate instances.

Parameters:
aggregateType - The type of aggregate
repository - The repository providing access to aggregate instances

AggregateAnnotationCommandHandler

public AggregateAnnotationCommandHandler(Class<T> aggregateType,
                                         Repository<T> repository,
                                         CommandTargetResolver commandTargetResolver)
Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, using the given repository to add and load aggregate instances and the default ParameterResolverFactory.

Parameters:
aggregateType - The type of aggregate
repository - The repository providing access to aggregate instances
commandTargetResolver - The target resolution strategy

AggregateAnnotationCommandHandler

public AggregateAnnotationCommandHandler(Class<T> aggregateType,
                                         Repository<T> repository,
                                         CommandTargetResolver commandTargetResolver,
                                         ParameterResolverFactory parameterResolverFactory)
Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, using the given repository to add and load aggregate instances and the given parameterResolverFactory.

Parameters:
aggregateType - The type of aggregate
repository - The repository providing access to aggregate instances
commandTargetResolver - The target resolution strategy
parameterResolverFactory - The strategy for resolving parameter values for handler methods

AggregateAnnotationCommandHandler

@Deprecated
public AggregateAnnotationCommandHandler(Class<T> aggregateType,
                                                    Repository<T> repository,
                                                    CommandBus commandBus)
Deprecated. Use AggregateAnnotationCommandHandler(Class, org.axonframework.repository.Repository) and subscribe the adapter to the command bus using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler). Alternatively, use subscribe(Class, org.axonframework.repository.Repository, org.axonframework.commandhandling.CommandBus).

Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, to be registered on the given commandBus.

Parameters:
aggregateType - The type of aggregate
repository - The repository providing access to aggregate instances
commandBus - The command bus to register command handlers to

AggregateAnnotationCommandHandler

@Deprecated
public AggregateAnnotationCommandHandler(Class<T> aggregateType,
                                                    Repository<T> repository,
                                                    CommandBus commandBus,
                                                    CommandTargetResolver commandTargetResolver)
Deprecated. Use AggregateAnnotationCommandHandler(Class, org.axonframework.repository.Repository, org.axonframework.commandhandling.CommandTargetResolver) and subscribe the handler to the command bus using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler). Alternatively, use subscribe(Class, org.axonframework.repository.Repository, org.axonframework.commandhandling.CommandBus, org.axonframework.commandhandling.CommandTargetResolver).

Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, to be registered on the given commandBus.

Parameters:
aggregateType - The type of aggregate
repository - The repository providing access to aggregate instances
commandBus - The command bus to register command handlers to
commandTargetResolver - The target resolution strategy
Method Detail

subscribe

public static <T extends AggregateRoot> AggregateAnnotationCommandHandler subscribe(Class<T> aggregateType,
                                                                                    Repository<T> repository,
                                                                                    CommandBus commandBus)
Subscribe a handler for the given aggregate type to the given command bus.

Type Parameters:
T - The type of aggregate this handler handles commands for
Parameters:
aggregateType - The type of aggregate
repository - The repository providing access to aggregate instances
commandBus - The command bus to register command handlers to
Returns:
the Adapter created for the command handler target. Can be used to unsubscribe.

subscribe

public static <T extends AggregateRoot> AggregateAnnotationCommandHandler subscribe(Class<T> aggregateType,
                                                                                    Repository<T> repository,
                                                                                    CommandBus commandBus,
                                                                                    CommandTargetResolver commandTargetResolver)
Subscribe a handler for the given aggregate type to the given command bus.

Type Parameters:
T - The type of aggregate this handler handles commands for
Parameters:
aggregateType - The type of aggregate
repository - The repository providing access to aggregate instances
commandBus - The command bus to register command handlers to
commandTargetResolver - The target resolution strategy
Returns:
the Adapter created for the command handler target. Can be used to unsubscribe.

subscribe

public static void subscribe(AggregateAnnotationCommandHandler<?> aggregateAnnotationCommandHandler,
                             CommandBus commandBus)
Subscribe the given aggregateAnnotationCommandHandler to the given commandBus. The command handler will be subscribed for each of the supported commands.

Parameters:
aggregateAnnotationCommandHandler - The fully configured AggregateAnnotationCommandHandler instance to subscribe
commandBus - The command bus instance to subscribe to

unsubscribe

@PreDestroy
@Deprecated
public void unsubscribe()
Deprecated. unsubscribing this handler should be done using CommandBus.unsubscribe(String, org.axonframework.commandhandling.CommandHandler). Retrieve the supported commands with supportedCommands().

Unsubscribe this instance from its subscribed component.

Specified by:
unsubscribe in interface Subscribable

subscribe

@PostConstruct
@Deprecated
public void subscribe()
Deprecated. subscribing this handler should be done using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler). Retrieve the supported commands with supportedCommands().

Subscribe this instance with its configured component.

Specified by:
subscribe in interface Subscribable

supportedCommands

public Set<String> supportedCommands()
Returns the set of commands supported by the annotated command handler managed by this adapter. This may be used to (un)subscribe the adapter from the command bus.

Returns:
the set of commands supported by the annotated command handler

handle

public Object handle(CommandMessage<Object> commandMessage,
                     UnitOfWork unitOfWork)
              throws Throwable
Description copied from interface: CommandHandler
Handles the given command.

Specified by:
handle in interface CommandHandler<Object>
Parameters:
commandMessage - The message carrying the command to process.
unitOfWork - The UnitOfWork the command is processed in
Returns:
The result of the command processing, if any.
Throws:
Throwable - any exception that occurs during command handling

resolveReturnValue

protected Object resolveReturnValue(CommandMessage<?> command,
                                    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


Copyright © 2010-2016. All Rights Reserved.