use of io.spine.core.Command in project core-java by SpineEventEngine.
the class IteratingCommandRouter method routeNext.
/**
* Creates and posts a next command.
*
* <p>The commands are created and posted in the sequence their messages were added.
*
* @return the posted command
* @throws NoSuchElementException if there are no command messages to post
* @see #hasNext()
*/
protected Command routeNext() {
final Message message = next();
final Command command = route(message);
return command;
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandFactory method create.
/**
* Creates a new {@code Command} with the passed message and target entity version.
*
* <p>The {@code targetVersion} parameter defines the version of the entity which handles
* the resulting command. Note that the framework performs no validation of the target version
* before a command is handled. The validation may be performed by the user themselves instead.
*
* @param message the command message
* @param targetVersion the version of the entity for which this command is intended
* @return new command instance
* @throws ValidationException if the passed message does not satisfy the constraints
* set for it in its Protobuf definition
*/
public Command create(Message message, int targetVersion) throws ValidationException {
checkNotNull(message);
checkValid(message);
final CommandContext context = createContext(targetVersion);
final Command result = createCommand(message, context);
return result;
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandFactory method createCommand.
/**
* Creates a command instance with the given {@code message} and {@code context}.
*
* <p>If an instance of {@link Any} is passed as the {@code message} parameter, the packed
* message is used for the command construction.
*
* <p>The ID of the new command instance is automatically generated.
*
* @param message the command message
* @param context the context of the command
* @return a new command
*/
private static Command createCommand(Message message, CommandContext context) {
final Any packed = AnyPacker.pack(message);
final Command.Builder result = Command.newBuilder().setId(Commands.generateId()).setMessage(packed).setContext(context);
return result.build();
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandFactory method createWithContext.
/**
* Creates a new {@code Command} with the passed {@code message} and {@code context}.
*
* @param message the command message
* @param context the command context
* @return a new command instance
* @throws ValidationException if the passed message does not satisfy the constraints
* set for it in its Protobuf definition
*/
@Internal
public Command createWithContext(Message message, CommandContext context) throws ValidationException {
checkNotNull(message);
checkNotNull(context);
checkValid(message);
final Command result = createCommand(message, context);
return result;
}
use of io.spine.core.Command in project core-java by SpineEventEngine.
the class CommandFactory method createBasedOnContext.
/**
* Creates new {@code Command} with the passed message, using the existing context.
*
* <p>The produced command is created with a {@code CommandContext} instance, copied from
* the given one, but with the current time set as a context timestamp.
*
* @param message the command message
* @param context the command context to use as a base for the new command
* @return new command instance
* @throws ValidationException if the passed message does not satisfy the constraints
* set for it in its Protobuf definition
*/
@Internal
public Command createBasedOnContext(Message message, CommandContext context) throws ValidationException {
checkNotNull(message);
checkNotNull(context);
checkValid(message);
final CommandContext newContext = contextBasedOn(context);
final Command result = createCommand(message, newContext);
return result;
}
Aggregations