public abstract class AbstractCommandHandler extends AbstractCommandDispatcher implements CommandHandler
EventBus
.
A command handler is responsible for:
EventBus
.
Event messages are returned as values of command handling methods.
A command handler does not have its own state. So the state of the business model it changes is external to it. Even though such behaviour may be needed in some rare cases, using aggregates is a preferred way of handling commands.
This class implements CommandDispatcher
dispatching messages
to methods declared in the derived classes.
Aggregate
,
CommandDispatcher
Constructor and Description |
---|
AbstractCommandHandler() |
Modifier and Type | Method and Description |
---|---|
void |
dispatch(CommandEnvelope envelope)
Dispatches the command to the handler method and
posts resulting events to the
EventBus . |
com.google.common.collect.ImmutableSet<CommandClass> |
messageClasses()
Obtains a set of message classes that can be processed by this dispatcher.
|
com.google.common.collect.ImmutableSet<EventClass> |
producedEvents()
Obtains classes of the events produced by this object.
|
void |
registerWith(BoundedContext context) |
io.spine.core.Version |
version()
Always returns empty version.
|
equals, hashCode, id, isRegistered, onError, onRejection, postEvents, producerId
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
nothing, producerId
dispatchesCommands
canDispatch
public void dispatch(CommandEnvelope envelope)
EventBus
.dispatch
in interface MessageDispatcher<CommandClass,CommandEnvelope>
envelope
- the command to dispatchjava.lang.IllegalStateException
- if an exception occurred during command dispatching with this exception as the causepublic void registerWith(BoundedContext context)
registerWith
in class AbstractCommandDispatcher
public com.google.common.collect.ImmutableSet<EventClass> producedEvents()
EventProducer
producedEvents
in interface EventProducer
public com.google.common.collect.ImmutableSet<CommandClass> messageClasses()
MessageDispatcher
messageClasses
in interface MessageDispatcher<CommandClass,CommandEnvelope>
public io.spine.core.Version version()
version
in interface EventProducer