Search in sources :

Example 1 with CommandClass

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

the class CommandExpiredException method messageFormat.

private static String messageFormat(Command command) {
    final CommandClass commandClass = CommandClass.of(command);
    final String typeName = TypeName.ofCommand(command).value();
    final String result = format("A scheduled command expired. Command class: `%s`; Protobuf type: `%s`.", commandClass, typeName);
    return result;
}
Also used : CommandClass(io.spine.type.CommandClass)

Example 2 with CommandClass

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

the class ProcessManagerRepository method dispatchCommand.

/**
     * Dispatches the command to a corresponding process manager.
     *
     * <p>If there is no stored process manager with such an ID,
     * a new process manager is created and stored after it handles the passed command.
     *
     * @param envelope a request to dispatch
     * @see CommandHandlingEntity#dispatchCommand(CommandEnvelope)
     */
@Override
public void dispatchCommand(CommandEnvelope envelope) {
    final Message commandMessage = envelope.getMessage();
    final CommandContext context = envelope.getCommandContext();
    final CommandClass commandClass = envelope.getMessageClass();
    checkCommandClass(commandClass);
    final I id = getIdFromCommandMessage.apply(commandMessage, context);
    final P manager = findOrCreate(id);
    final ProcManTransaction<?, ?, ?> tx = beginTransactionFor(manager);
    final List<Event> events = manager.dispatchCommand(envelope);
    store(manager);
    tx.commit();
    postEvents(events);
}
Also used : Message(com.google.protobuf.Message) CommandContext(io.spine.base.CommandContext) Event(io.spine.base.Event) CommandClass(io.spine.type.CommandClass)

Example 3 with CommandClass

use of io.spine.type.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<CommandDispatcher> registeredDispatcher = getDispatcher(commandClass);
        if (registeredDispatcher.isPresent()) {
            alreadyRegistered.put(commandClass, registeredDispatcher.get());
        }
    }
    doCheck(alreadyRegistered, dispatcher);
}
Also used : CommandClass(io.spine.type.CommandClass)

Example 4 with CommandClass

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

the class UnsupportedCommandException method messageFormat.

private static String messageFormat(Command command) {
    final CommandClass commandClass = CommandClass.of(command);
    final String typeName = TypeName.ofCommand(command).value();
    final String result = format("There is no registered handler or dispatcher for the command of class: `%s`. " + "Protobuf type: `%s`", commandClass, typeName);
    return result;
}
Also used : CommandClass(io.spine.type.CommandClass)

Example 5 with CommandClass

use of io.spine.type.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<Response> 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.type.CommandClass) CommandBus(io.spine.server.commandbus.CommandBus)

Aggregations

CommandClass (io.spine.type.CommandClass)5 Message (com.google.protobuf.Message)1 CommandContext (io.spine.base.CommandContext)1 Event (io.spine.base.Event)1 CommandBus (io.spine.server.commandbus.CommandBus)1