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