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);
}
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);
}
}
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());
}
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;
}
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));
}
}
Aggregations