Search in sources :

Example 21 with CommandId

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

the class Rescheduler method onScheduledCommandExpired.

/**
 * Sets the status of the expired command to error.
 *
 * <p>We cannot post such a command because there is no handler or dispatcher registered yet.
 * Or, posting such a command may be undesirable from the business logic point of view.
 *
 * @param command the expired command
 * @see CommandExpiredException
 */
private void onScheduledCommandExpired(Command command) {
    final CommandEnvelope commandEnvelope = CommandEnvelope.of(command);
    final Message msg = commandEnvelope.getMessage();
    final CommandId id = commandEnvelope.getId();
    final Error error = CommandExpiredException.commandExpired(command);
    commandStore().setToError(commandEnvelope, error);
    log().errorExpiredCommand(msg, id);
}
Also used : Message(com.google.protobuf.Message) CommandEnvelope(io.spine.core.CommandEnvelope) Error(io.spine.base.Error) CommandId(io.spine.core.CommandId)

Example 22 with CommandId

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

the class Records method newRecordBuilder.

/**
 * Creates a command storage record builder passed on the passed parameters.
 *
 * <p>{@code targetId} and {@code targetIdType} are set to empty strings if
 * the command is not for an entity.
 *
 * @param command            a command to convert to a record. This includes instances of faulty
 *                           commands. An example of such a fault is missing command ID.
 * @param status             a command status to set in the record
 * @param generatedCommandId a command ID to be used because the passed command does not have
 *                           own ID. If the command has own ID, this parameter is {@code null}.
 * @return a storage record
 */
static CommandRecord.Builder newRecordBuilder(Command command, CommandStatus status, @Nullable CommandId generatedCommandId) {
    final CommandId commandId = generatedCommandId != null ? generatedCommandId : command.getId();
    final String commandType = CommandEnvelope.of(command).getTypeName().getSimpleName();
    final CommandRecord.Builder builder = CommandRecord.newBuilder().setCommandId(commandId).setCommandType(commandType).setCommand(command).setTimestamp(getCurrentTime()).setStatus(ProcessingStatus.newBuilder().setCode(status));
    return builder;
}
Also used : CommandId(io.spine.core.CommandId) CommandRecord(io.spine.server.commandbus.CommandRecord)

Aggregations

CommandId (io.spine.core.CommandId)22 Command (io.spine.core.Command)6 Test (org.junit.Test)6 Error (io.spine.base.Error)5 Message (com.google.protobuf.Message)4 TenantId (io.spine.core.TenantId)4 CommandRecord (io.spine.server.commandbus.CommandRecord)4 ThrowableMessage (io.spine.base.ThrowableMessage)3 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)3 Nullable (javax.annotation.Nullable)3 CommandEnvelope (io.spine.core.CommandEnvelope)2 Commands.getMessage (io.spine.core.Commands.getMessage)2 Status (io.spine.core.Status)2 CommandMessage.createProjectMessage (io.spine.server.commandbus.Given.CommandMessage.createProjectMessage)2 ProcessingStatus (io.spine.server.commandbus.ProcessingStatus)2 TenantAwareFunction (io.spine.server.tenant.TenantAwareFunction)2 Duration (com.google.protobuf.Duration)1 Timestamp (com.google.protobuf.Timestamp)1 Ack (io.spine.core.Ack)1 CommandContext (io.spine.core.CommandContext)1