Search in sources :

Example 6 with Command

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;
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.core.Command)

Example 7 with 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;
}
Also used : CommandContext(io.spine.core.CommandContext) Command(io.spine.core.Command)

Example 8 with Command

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();
}
Also used : Command(io.spine.core.Command) Any(com.google.protobuf.Any)

Example 9 with Command

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;
}
Also used : Command(io.spine.core.Command) Internal(io.spine.annotation.Internal)

Example 10 with Command

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;
}
Also used : CommandContext(io.spine.core.CommandContext) Command(io.spine.core.Command) Internal(io.spine.annotation.Internal)

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