AbstractCommandHandler

public abstract class AbstractCommandHandler extends AbstractCommandDispatcher implements CommandHandler

The abstract base for non-aggregate classes that expose command handling methods and post their results to EventBus.

A command handler is responsible for:

  1. Changing the state of the business model in response to a command. This is done by one of the command handling methods to which the handler dispatches the command.
  2. Producing corresponding events.
  3. Posting events to 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.

See also

Constructors

Link copied to clipboard
public void AbstractCommandHandler()

Functions

Link copied to clipboard
public DispatchOutcome dispatch(CommandEnvelope envelope)
Dispatches the command to the handler method and posts resulting events to the EventBus.
Link copied to clipboard
public ImmutableSet<CommandClass> messageClasses()
Obtains a set of message classes that can be processed by this dispatcher.
Link copied to clipboard
public ImmutableSet<EventClass> producedEvents()
Obtains classes of the events produced by this object.
Link copied to clipboard
public void registerWith(BoundedContext context)
Registers this instance as a part of the given Bounded Context.
Link copied to clipboard
public Version version()
Always returns empty version.

Inherited functions

Link copied to clipboard
public boolean canDispatch(E envelope)
Checks if this dispatcher can dispatch the given message.
Link copied to clipboard
public void checkNotRegistered()
Verifies that this instance is NOT registered yet.
Link copied to clipboard
public void checkRegistered()
Verifies that this instance is already registered.
Link copied to clipboard
public boolean dispatchesCommands()
Verifies if this instance dispatches at least one command.
Link copied to clipboard
public boolean equals(Object o)
Indicates whether some other command handler is "equal to" this one.
Link copied to clipboard
public int hashCode()
Link copied to clipboard
public String id()
Obtains identity string of the dispatcher.
Link copied to clipboard
public boolean isRegistered()
Determines if this instance is already registered with a Bounded Context.
Link copied to clipboard
public Nothing nothing()
Obtains the io.spine.server.model.
Link copied to clipboard
protected void onError(SignalEnvelope<? extends Object, ? extends Object, ? extends Object> signal, Error error)
Link copied to clipboard
protected void onRejection(SignalEnvelope<? extends Object, ? extends Object, ? extends Object> signal, Event rejection)
Link copied to clipboard
protected void postEvents(Iterable<Event> events)
Posts passed events to EventBus.
Link copied to clipboard
public Any producerId()
Obtains ID packed into Any for being used in generated events.