use of io.spine.core.CommandClass in project core-java by SpineEventEngine.
the class RejectionSubscriber method handle.
private void handle(RejectionEnvelope rejection) {
final CommandClass commandClass = CommandClass.of(rejection.getCommandMessage());
final RejectionSubscriberMethod method = thisClass.getSubscriber(rejection.getMessageClass(), commandClass);
method.invoke(this, rejection.getMessage(), rejection.getRejectionContext());
}
use of io.spine.core.CommandClass in project core-java by SpineEventEngine.
the class CommandService method post.
@SuppressWarnings("MethodDoesntCallSuperMethod")
// as we override default implementation with `unimplemented` status.
@Override
public void post(Command request, StreamObserver<Ack> responseObserver) {
final CommandClass commandClass = CommandClass.of(request);
final BoundedContext boundedContext = boundedContextMap.get(commandClass);
if (boundedContext == null) {
handleUnsupported(request, responseObserver);
} else {
final CommandBus commandBus = boundedContext.getCommandBus();
commandBus.post(request, responseObserver);
}
}
use of io.spine.core.CommandClass in project core-java by SpineEventEngine.
the class Aggregate method reactOn.
/**
* Dispatches the rejection to which the aggregate reacts.
*
* <p>Reacting on a rejection may result in emitting event messages. All the
* {@linkplain Empty empty} messages are filtered out from the result.
*
* @param rejection the envelope with the rejection
* @return a list of event messages that the aggregate produces in reaction to
* the rejection, or an empty list if the aggregate state does not change in
* response to this rejection
*/
List<? extends Message> reactOn(RejectionEnvelope rejection) {
final CommandClass commandClass = CommandClass.of(rejection.getCommandMessage());
final RejectionReactorMethod method = thisClass().getReactor(rejection.getMessageClass(), commandClass);
final List<? extends Message> messages = method.invoke(this, rejection.getMessage(), rejection.getRejectionContext());
return from(messages).filter(nonEmpty()).toList();
}
use of io.spine.core.CommandClass in project core-java by SpineEventEngine.
the class AggregateRepository method onRegistered.
/**
* {@inheritDoc}
*
* <p>{@linkplain io.spine.server.commandbus.CommandBus#register(
* io.spine.server.bus.MessageDispatcher) Registers} itself with the {@code CommandBus} of the
* parent {@code BoundedContext}.
*/
@Override
public void onRegistered() {
super.onRegistered();
final BoundedContext boundedContext = getBoundedContext();
final Set<CommandClass> commandClasses = getMessageClasses();
final DelegatingEventDispatcher<I> eventDispatcher;
eventDispatcher = DelegatingEventDispatcher.of(this);
final Set<EventClass> eventClasses = eventDispatcher.getMessageClasses();
final ExternalMessageDispatcher<I> extEventDispatcher;
extEventDispatcher = eventDispatcher.getExternalDispatcher();
final Set<ExternalMessageClass> extEventClasses = extEventDispatcher.getMessageClasses();
final DelegatingRejectionDispatcher<I> rejectionDispatcher;
rejectionDispatcher = DelegatingRejectionDispatcher.of(this);
final Set<RejectionClass> rejectionClasses = rejectionDispatcher.getMessageClasses();
final ExternalMessageDispatcher<I> extRejectionDispatcher;
extRejectionDispatcher = rejectionDispatcher.getExternalDispatcher();
final Set<ExternalMessageClass> extRejectionClasses = extRejectionDispatcher.getMessageClasses();
if (commandClasses.isEmpty() && eventClasses.isEmpty() && rejectionClasses.isEmpty() && extEventClasses.isEmpty() && extRejectionClasses.isEmpty()) {
throw newIllegalStateException("Aggregates of the repository %s neither handle commands" + " nor react on events or rejections.", this);
}
registerInCommandBus(boundedContext, commandClasses);
registerInEventBus(boundedContext, eventDispatcher, eventClasses);
registerInRejectionBus(boundedContext, rejectionDispatcher, rejectionClasses);
registerExtMessageDispatcher(boundedContext, extEventDispatcher, extEventClasses);
registerExtMessageDispatcher(boundedContext, extRejectionDispatcher, extRejectionClasses);
this.commandErrorHandler = CommandErrorHandler.with(boundedContext.getRejectionBus());
}
use of io.spine.core.CommandClass in project core-java by SpineEventEngine.
the class CommandDispatcherRegistry method checkNotAlreadyRegistered.
/**
* Ensures that all of the commands of the passed dispatcher are not
* already registered for dispatched in this command bus.
*
* @throws IllegalArgumentException if at least one command class already has
* a registered dispatcher
*/
private void checkNotAlreadyRegistered(CommandDispatcher<?> dispatcher) {
final Set<CommandClass> commandClasses = dispatcher.getMessageClasses();
final Map<CommandClass, CommandDispatcher<?>> alreadyRegistered = Maps.newHashMap();
// Gather command classes from this dispatcher that are registered.
for (CommandClass commandClass : commandClasses) {
final Optional<? extends CommandDispatcher<?>> registeredDispatcher = getDispatcher(commandClass);
if (registeredDispatcher.isPresent()) {
alreadyRegistered.put(commandClass, registeredDispatcher.get());
}
}
doCheck(alreadyRegistered, dispatcher);
}
Aggregations