Search in sources :

Example 1 with CommandClass

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());
}
Also used : CommandClass(io.spine.core.CommandClass)

Example 2 with CommandClass

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);
    }
}
Also used : CommandClass(io.spine.core.CommandClass) CommandBus(io.spine.server.commandbus.CommandBus)

Example 3 with CommandClass

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();
}
Also used : RejectionReactorMethod(io.spine.server.rejection.RejectionReactorMethod) CommandClass(io.spine.core.CommandClass)

Example 4 with CommandClass

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());
}
Also used : ExternalMessageClass(io.spine.server.integration.ExternalMessageClass) SPI(io.spine.annotation.SPI) EventClass(io.spine.core.EventClass) BoundedContext(io.spine.server.BoundedContext) CommandClass(io.spine.core.CommandClass) RejectionClass(io.spine.core.RejectionClass)

Example 5 with CommandClass

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);
}
Also used : CommandClass(io.spine.core.CommandClass)

Aggregations

CommandClass (io.spine.core.CommandClass)11 RejectionReactorMethod (io.spine.server.rejection.RejectionReactorMethod)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 SPI (io.spine.annotation.SPI)1 Event (io.spine.core.Event)1 EventClass (io.spine.core.EventClass)1 RejectionClass (io.spine.core.RejectionClass)1 BoundedContext (io.spine.server.BoundedContext)1 CommandHandlingClass (io.spine.server.command.CommandHandlingClass)1 CommandBus (io.spine.server.commandbus.CommandBus)1 ExternalMessageClass (io.spine.server.integration.ExternalMessageClass)1 Set (java.util.Set)1 Test (org.junit.Test)1