Search in sources :

Example 6 with CommandClass

use of io.spine.core.CommandClass in project core-java by SpineEventEngine.

the class EntityMessageEndpoint method onUnhandledCommand.

/**
 * Throws {@link IllegalStateException} with the diagnostics message on the unhandled command.
 *
 * @param  entity the entity which failed to handle the command
 * @param  cmd    the envelope with the command
 * @param  format the format string with the following parameters
 *                <ol>
 *                   <li>the name of the entity class
 *                   <li>the ID of the entity
 *                   <li>the name of the command class
 *                   <li>the ID of the command
 *                </ol>
 * @throws IllegalStateException always
 */
protected void onUnhandledCommand(Entity<R, ?> entity, CommandEnvelope cmd, String format) {
    final String entityId = Stringifiers.toString(entity.getId());
    final String entityClass = entity.getClass().getName();
    final String commandId = Stringifiers.toString(cmd.getId());
    final CommandClass commandClass = cmd.getMessageClass();
    throw newIllegalStateException(format, entityClass, entityId, commandClass, commandId);
}
Also used : CommandClass(io.spine.core.CommandClass)

Example 7 with CommandClass

use of io.spine.core.CommandClass in project core-java by SpineEventEngine.

the class Model method checkDuplicates.

private void checkDuplicates(CommandHandlingClass candidate) throws DuplicateCommandHandlerError {
    final Set<CommandClass> candidateCommands = candidate.getCommands();
    final ImmutableMap.Builder<Set<CommandClass>, CommandHandlingClass> map = ImmutableMap.builder();
    for (ModelClass<?> modelClass : classes.values()) {
        if (modelClass instanceof CommandHandlingClass) {
            final CommandHandlingClass commandHandler = (CommandHandlingClass) modelClass;
            final Set<CommandClass> commandClasses = commandHandler.getCommands();
            final Sets.SetView<CommandClass> intersection = Sets.intersection(commandClasses, candidateCommands);
            if (intersection.size() > 0) {
                map.put(intersection, commandHandler);
            }
        }
    }
    final ImmutableMap<Set<CommandClass>, CommandHandlingClass> currentHandlers = map.build();
    if (!currentHandlers.isEmpty()) {
        throw new DuplicateCommandHandlerError(candidate, currentHandlers);
    }
}
Also used : Set(java.util.Set) Sets(com.google.common.collect.Sets) CommandClass(io.spine.core.CommandClass) ImmutableMap(com.google.common.collect.ImmutableMap) CommandHandlingClass(io.spine.server.command.CommandHandlingClass)

Example 8 with CommandClass

use of io.spine.core.CommandClass in project core-java by SpineEventEngine.

the class HandlerKeyShould method return_command_class_of_empty_if_there_is_no_origin.

@Test
public void return_command_class_of_empty_if_there_is_no_origin() {
    final CommandClass handledMessage = stringClass;
    final HandlerKey key = HandlerKey.of(handledMessage);
    assertEquals(handledMessage, key.getHandledMessageCls());
    assertEquals(emptyClass, key.getOriginCls());
}
Also used : CommandClass(io.spine.core.CommandClass) Test(org.junit.Test)

Example 9 with CommandClass

use of io.spine.core.CommandClass in project core-java by SpineEventEngine.

the class ProcessManager method dispatchRejection.

/**
 * Dispatches a rejection to the reacting method of the process manager.
 *
 * @param  rejection the envelope with the rejection
 * @return a list of produced events or an empty list if the process manager does not
 *         produce new events because of the passed event
 */
List<Event> dispatchRejection(RejectionEnvelope rejection) {
    final CommandClass commandClass = CommandClass.of(rejection.getCommandMessage());
    final RejectionReactorMethod method = thisClass().getReactor(rejection.getMessageClass(), commandClass);
    final List<? extends Message> eventMessages = method.invoke(this, rejection.getMessage(), rejection.getRejectionContext());
    final List<Event> events = toEvents(eventMessages, rejection);
    return events;
}
Also used : RejectionReactorMethod(io.spine.server.rejection.RejectionReactorMethod) Event(io.spine.core.Event) CommandClass(io.spine.core.CommandClass)

Example 10 with CommandClass

use of io.spine.core.CommandClass in project core-java by SpineEventEngine.

the class CommandDispatcherRegistryShould method assertNotSupported.

@SafeVarargs
private final void assertNotSupported(Class<? extends Message>... cmdClasses) {
    final Set<CommandClass> supportedClasses = registry.getRegisteredMessageClasses();
    for (Class<? extends Message> clazz : cmdClasses) {
        final CommandClass cmdClass = CommandClass.of(clazz);
        assertFalse(supportedClasses.contains(cmdClass));
    }
}
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