Search in sources :

Example 1 with Command

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

the class CommandScheduler method scheduleAndStore.

private void scheduleAndStore(CommandEnvelope commandEnvelope) {
    final Command command = commandEnvelope.getCommand();
    schedule(command);
    commandBus().commandStore().store(command, SCHEDULED);
}
Also used : Command(io.spine.core.Command)

Example 2 with Command

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

the class CommandValidator method isTenantIdValid.

private Optional<MessageInvalid> isTenantIdValid(CommandEnvelope envelope) {
    final TenantId tenantId = envelope.getTenantId();
    final boolean tenantSpecified = !isDefault(tenantId);
    final Command command = envelope.getCommand();
    if (commandBus.isMultitenant()) {
        if (!tenantSpecified) {
            final MessageInvalid report = missingTenantId(command);
            return of(report);
        }
    } else {
        if (tenantSpecified) {
            final MessageInvalid report = tenantIdInapplicable(command);
            return of(report);
        }
    }
    return absent();
}
Also used : InvalidCommandException.onMissingTenantId(io.spine.server.commandbus.InvalidCommandException.onMissingTenantId) TenantId(io.spine.core.TenantId) InvalidCommandException.onInapplicableTenantId(io.spine.server.commandbus.InvalidCommandException.onInapplicableTenantId) Command(io.spine.core.Command) MessageInvalid(io.spine.core.MessageInvalid)

Example 3 with Command

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

the class Rescheduler method rescheduleForTenant.

private void rescheduleForTenant(final TenantId tenantId) {
    final TenantAwareFunction0<Iterator<Command>> func = new TenantAwareFunction0<Iterator<Command>>(tenantId) {

        @Override
        public Iterator<Command> apply() {
            return commandStore().iterator(SCHEDULED);
        }
    };
    final Iterator<Command> commands = func.execute(Empty.getDefaultInstance());
    final TenantAwareOperation op = new TenantAwareOperation(tenantId) {

        @Override
        public void run() {
            while (commands.hasNext()) {
                final Command command = commands.next();
                reschedule(command);
            }
        }
    };
    op.execute();
}
Also used : Command(io.spine.core.Command) TenantAwareFunction0(io.spine.server.tenant.TenantAwareFunction0) Iterator(java.util.Iterator) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation)

Example 4 with Command

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

the class CommandRouter method routeAll.

/**
 * Posts the added messages as commands to {@code CommandBus}.
 *
 * <p>The commands are posted in the order their messages were added.
 *
 * <p>The method returns after the last command was successfully posted.
 *
 * @return the event with the source and produced commands
 */
public CommandRouted routeAll() {
    final CommandRouted.Builder result = CommandRouted.newBuilder();
    result.setSource(getSource());
    while (hasNext()) {
        final Message message = next();
        final Command command = route(message);
        result.addProduced(command);
    }
    return result.build();
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.core.Command)

Example 5 with Command

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

the class IteratingCommandRouter method routeFirst.

/**
 * Routes the first of the messages and returns the message
 * to be associated with the source command.
 *
 * <p>The rest of the messages are stored and those to follow.
 *
 * @return {@code CommandRouted} message with
 * <ul>
 *     <li>the source command,
 *     <li>the first produced command,
 *     <li>the command messages for the commands that will be posted by the router later
 * </ul>
 * @see CommandRouted#getMessageToFollowList()
 */
protected CommandRouted routeFirst() {
    final CommandRouted.Builder result = CommandRouted.newBuilder();
    result.setSource(getSource());
    final Message message = next();
    final Command command = route(message);
    result.addProduced(command);
    final Iterable<Any> iterable = new Iterable<Any>() {

        @Override
        public Iterator<Any> iterator() {
            return AnyPacker.pack(commandMessages());
        }
    };
    result.addAllMessageToFollow(iterable);
    return result.build();
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.core.Command) Any(com.google.protobuf.Any)

Aggregations

Command (io.spine.core.Command)137 Test (org.junit.Test)87 Event (io.spine.core.Event)19 TenantId (io.spine.core.TenantId)17 Ack (io.spine.core.Ack)15 Message (com.google.protobuf.Message)14 Rejection (io.spine.core.Rejection)13 CommandEnvelope (io.spine.core.CommandEnvelope)11 Timestamp (com.google.protobuf.Timestamp)9 Error (io.spine.base.Error)9 CommandContext (io.spine.core.CommandContext)9 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)8 CommandRecord (io.spine.server.commandbus.CommandRecord)8 ProjectId (io.spine.test.aggregate.ProjectId)8 CommandBus (io.spine.server.commandbus.CommandBus)7 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)7 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)7 Any (com.google.protobuf.Any)6 CommandId (io.spine.core.CommandId)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6