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:
Subscribable

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

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, CommandBus commandBus)
          Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, to be registered on the given commandBus.
AggregateAnnotationCommandHandler(Class<T> aggregateType, Repository<T> repository, CommandBus commandBus, CommandTargetResolver commandTargetResolver)
          Initializes an AnnotationCommandHandler based on the annotations on given aggregateType, to be registered on the given commandBus.
 
Method Summary
 void subscribe()
          Subscribe this instance with its configured component.
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.
 void unsubscribe()
          Unsubscribe this instance from its subscribed component.
 
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,
                                         CommandBus 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

public AggregateAnnotationCommandHandler(Class<T> aggregateType,
                                         Repository<T> repository,
                                         CommandBus commandBus,
                                         CommandTargetResolver 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.

unsubscribe

@PreDestroy
public void unsubscribe()
Description copied from interface: Subscribable
Unsubscribe this instance from its subscribed component.

Specified by:
unsubscribe in interface Subscribable

subscribe

@PostConstruct
public void subscribe()
Description copied from interface: Subscribable
Subscribe this instance with its configured component.

Specified by:
subscribe in interface Subscribable


Copyright © 2010-2012. All Rights Reserved.