public class AnnotationCommandHandlerAdapter extends Object implements CommandHandler<Object>, Subscribable
@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.CommandHandler
Constructor and Description |
---|
AnnotationCommandHandlerAdapter(Object target,
CommandBus commandBus)
Initialize the command handler adapter for the given
target which is to be subscribed with the
given commandBus . |
Modifier and Type | Method and Description |
---|---|
Object |
handle(CommandMessage<Object> command,
UnitOfWork unitOfWork)
Invokes the @CommandHandler annotated method that accepts the given
command . |
void |
subscribe()
Subscribe the command handlers to the command bus assigned during the initialization.
|
static AnnotationCommandHandlerAdapter |
subscribe(Object annotatedCommandHandler,
CommandBus commandBus)
Subscribe the annotated command handler to the given command bus.
|
void |
unsubscribe()
Unsubscribe the command handlers from the command bus assigned during the initialization.
|
public AnnotationCommandHandlerAdapter(Object target, CommandBus commandBus)
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.target
- The object containing the @CommandHandler annotated methodscommandBus
- The command bus to which the handlers must be subscribedpublic static AnnotationCommandHandlerAdapter subscribe(Object annotatedCommandHandler, CommandBus commandBus)
annotatedCommandHandler
- The annotated command handler that is to be subscribed to the command buscommandBus
- The command bus that gets the handler's subscriptionpublic Object handle(CommandMessage<Object> command, UnitOfWork unitOfWork) throws Throwable
command
.handle
in interface CommandHandler<Object>
command
- The command to handleunitOfWork
- The UnitOfWork the command is processed innull
when the annotated handler has a
void
return value.NoHandlerForCommandException
- when no handler is found for given command
.Throwable
- any exception occurring while handling the command@PostConstruct public void subscribe()
subscribe
in interface Subscribable
@PreDestroy public void unsubscribe()
unsubscribe
in interface Subscribable
Copyright © 2010-2013. All Rights Reserved.