org.axonframework.commandhandling.annotation
Class AnnotationCommandHandlerAdapter

java.lang.Object
  extended by org.axonframework.commandhandling.annotation.AnnotationCommandHandlerAdapter
All Implemented Interfaces:
CommandHandler<Object>, Subscribable

public class AnnotationCommandHandlerAdapter
extends Object
implements CommandHandler<Object>, Subscribable

Adapter that turns any @CommandHandler annotated bean into a CommandHandler implementation. Each annotated method is subscribed as a CommandHandler at the CommandBus for the command type specified by the parameter of that method.

Since:
0.5
Author:
Allard Buijze
See Also:
CommandHandler

Constructor Summary
AnnotationCommandHandlerAdapter(Object annotatedCommandHandler)
          Wraps the given annotatedCommandHandler, allowing it to be subscribed to a Command Bus.
AnnotationCommandHandlerAdapter(Object target, CommandBus commandBus)
          Deprecated. Use AnnotationCommandHandlerAdapter(Object) and subscribe the handler to the command bus using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler).
AnnotationCommandHandlerAdapter(Object annotatedCommandHandler, ParameterResolverFactory parameterResolverFactory)
          Wraps the given annotatedCommandHandler, allowing it to be subscribed to a Command Bus.
 
Method Summary
 Object handle(CommandMessage<Object> command, UnitOfWork unitOfWork)
          Invokes the @CommandHandler annotated method that accepts the given command.
 void subscribe()
          Deprecated. Instead, subscribe this instance using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler), using supportedCommands() to retrieve the commands the annotated handler supports.
static void subscribe(AnnotationCommandHandlerAdapter annotationCommandHandler, CommandBus commandBus)
          Subscribe the given annotationCommandHandler to the given commandBus.
static AnnotationCommandHandlerAdapter subscribe(Object annotatedCommandHandler, CommandBus commandBus)
          Subscribe the annotated command handler 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. Instead, subscribe this instance using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler), using supportedCommands() to retrieve the commands the annotated handler supports.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationCommandHandlerAdapter

@Deprecated
public AnnotationCommandHandlerAdapter(Object target,
                                                  CommandBus commandBus)
Deprecated. Use AnnotationCommandHandlerAdapter(Object) and subscribe the handler to the command bus using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler).

Initialize the command handler adapter for the given target which is to be subscribed with the given commandBus.

Note that you need to call subscribe() to actually subscribe the command handlers to the command bus.

Parameters:
target - The object containing the @CommandHandler annotated methods
commandBus - The command bus to which the handlers must be subscribed

AnnotationCommandHandlerAdapter

public AnnotationCommandHandlerAdapter(Object annotatedCommandHandler)
Wraps the given annotatedCommandHandler, allowing it to be subscribed to a Command Bus.

Parameters:
annotatedCommandHandler - The object containing the @CommandHandler annotated methods

AnnotationCommandHandlerAdapter

public AnnotationCommandHandlerAdapter(Object annotatedCommandHandler,
                                       ParameterResolverFactory parameterResolverFactory)
Wraps the given annotatedCommandHandler, allowing it to be subscribed to a Command Bus.

Parameters:
annotatedCommandHandler - The object containing the @CommandHandler annotated methods
parameterResolverFactory - The strategy for resolving handler method parameter values
Method Detail

subscribe

public static AnnotationCommandHandlerAdapter subscribe(Object annotatedCommandHandler,
                                                        CommandBus commandBus)
Subscribe the annotated command handler to the given command bus.

Parameters:
annotatedCommandHandler - The annotated command handler that is to be subscribed to the command bus
commandBus - The command bus that gets the handler's subscription
Returns:
the Adapter created for the command handler target. Can be used to unsubscribe.

subscribe

public static void subscribe(AnnotationCommandHandlerAdapter annotationCommandHandler,
                             CommandBus commandBus)
Subscribe the given annotationCommandHandler to the given commandBus. The command handler will be subscribed for each of the supported commands.

Parameters:
annotationCommandHandler - The fully configured AnnotationCommandHandlerAdapter instance to subscribe
commandBus - The command bus instance to subscribe to

handle

public Object handle(CommandMessage<Object> command,
                     UnitOfWork unitOfWork)
              throws Throwable
Invokes the @CommandHandler annotated method that accepts the given command.

Specified by:
handle in interface CommandHandler<Object>
Parameters:
command - The command to handle
unitOfWork - The UnitOfWork the command is processed in
Returns:
the result of the command handling. Is null when the annotated handler has a void return value.
Throws:
NoHandlerForCommandException - when no handler is found for given command.
Throwable - any exception occurring while handling the command

subscribe

@PostConstruct
@Deprecated
public void subscribe()
Deprecated. Instead, subscribe this instance using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler), using supportedCommands() to retrieve the commands the annotated handler supports.

Subscribe the command handlers to the command bus assigned during the initialization. A subscription is made with the command bus for each accepted type of command.

Specified by:
subscribe in interface Subscribable

unsubscribe

@PreDestroy
@Deprecated
public void unsubscribe()
Deprecated. Instead, subscribe this instance using CommandBus.subscribe(String, org.axonframework.commandhandling.CommandHandler), using supportedCommands() to retrieve the commands the annotated handler supports.

Unsubscribe the command handlers from the command bus assigned during the initialization.

Specified by:
unsubscribe in interface Subscribable

supportedCommands

public Set<String> supportedCommands()
Returns the set of commands supported by the annotated command handler managed by this adapter.

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


Copyright © 2010-2016. All Rights Reserved.