Search in sources :

Example 1 with CommandId

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

the class CommandScheduler method isScheduledAlready.

private static boolean isScheduledAlready(Command command) {
    final CommandId id = command.getId();
    final boolean isScheduledAlready = scheduledCommandIds.contains(id);
    return isScheduledAlready;
}
Also used : CommandId(io.spine.core.CommandId)

Example 2 with CommandId

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

the class CEntity method createForError.

static CEntity createForError(Command command, Error error) {
    checkNotNull(command);
    checkNotNull(error);
    final CommandId id = Records.getOrGenerateCommandId(command);
    final CEntity result = create(id);
    result.setError(id, command, error);
    return result;
}
Also used : CommandId(io.spine.core.CommandId)

Example 3 with CommandId

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

the class CEntity method createForStatus.

static CEntity createForStatus(Command command, CommandStatus status) {
    checkNotNull(command);
    checkNotNull(status);
    final CommandId commandId = command.getId();
    final CEntity entity = create(commandId);
    entity.setCommandAndStatus(command, status);
    return entity;
}
Also used : CommandId(io.spine.core.CommandId)

Example 4 with CommandId

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

the class CommandStore method updateCommandStatus.

// OK for this consolidated error handling.
@SuppressWarnings("ChainOfInstanceofChecks")
public void updateCommandStatus(CommandEnvelope commandEnvelope, Throwable cause, Log log) {
    final Message commandMessage = commandEnvelope.getMessage();
    final CommandId commandId = commandEnvelope.getId();
    if (cause instanceof ThrowableMessage) {
        final ThrowableMessage throwableMessage = (ThrowableMessage) cause;
        log.rejectedWith(throwableMessage, commandMessage, commandId);
        updateStatus(commandEnvelope, toRejection(throwableMessage, commandEnvelope.getCommand()));
    } else if (cause instanceof Exception) {
        final Exception exception = (Exception) cause;
        log.errorHandling(exception, commandMessage, commandId);
        updateStatus(commandEnvelope, exception);
    } else {
        log.errorHandlingUnknown(cause, commandMessage, commandId);
        final Error error = Errors.fromThrowable(cause);
        updateStatus(commandEnvelope, error);
    }
}
Also used : ThrowableMessage(io.spine.base.ThrowableMessage) ThrowableMessage(io.spine.base.ThrowableMessage) Message(com.google.protobuf.Message) Error(io.spine.base.Error) CommandId(io.spine.core.CommandId) CommandException(io.spine.server.commandbus.CommandException)

Example 5 with CommandId

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

the class CommandStore method getStatus.

/**
 * Obtains the processing status for the command with the passed ID.
 *
 * <p>Invoking this method must be performed within a {@link TenantAwareFunction} or
 * {@link TenantAwareOperation}.
 */
public ProcessingStatus getStatus(CommandId commandId) {
    final Func<CommandId, ProcessingStatus> func = new Func<CommandId, ProcessingStatus>(this) {

        @Override
        public ProcessingStatus apply(@Nullable CommandId input) {
            checkNotNull(input);
            final ProcessingStatus status = repository.getStatus(input);
            return status;
        }
    };
    return func.execute(commandId);
}
Also used : CommandId(io.spine.core.CommandId) ProcessingStatus(io.spine.server.commandbus.ProcessingStatus) Nullable(javax.annotation.Nullable)

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