Search in sources :

Example 1 with CommandOperation

use of io.spine.server.tenant.CommandOperation in project core-java by SpineEventEngine.

the class FailureSubscriber method dispatch.

@Override
public void dispatch(final FailureEnvelope envelope) {
    final Command originCommand = envelope.getOuterObject().getContext().getCommand();
    final CommandOperation op = new CommandOperation(originCommand) {

        @Override
        public void run() {
            handle(envelope.getMessage(), envelope.getCommandMessage(), envelope.getCommandContext());
        }
    };
    op.execute();
}
Also used : Command(io.spine.base.Command) CommandOperation(io.spine.server.tenant.CommandOperation)

Example 2 with CommandOperation

use of io.spine.server.tenant.CommandOperation in project core-java by SpineEventEngine.

the class AggregateRepository method dispatch.

/**
     * Dispatches the passed command to an aggregate.
     *
     * <p>The aggregate ID is obtained from the passed command.
     *
     * <p>The repository loads the aggregate by this ID, or creates a new aggregate
     * if there is no aggregate with such ID.
     *
     * @param envelope the envelope of the command to dispatch
     */
@Override
public void dispatch(final CommandEnvelope envelope) {
    final Command command = envelope.getCommand();
    final CommandOperation op = new CommandOperation(command) {

        @Override
        public void run() {
            final AggregateCommandEndpoint<I, A> commandEndpoint = createFor(AggregateRepository.this, envelope);
            commandEndpoint.execute();
            final Optional<A> processedAggregate = commandEndpoint.getAggregate();
            if (!processedAggregate.isPresent()) {
                throw new IllegalStateException("No aggregate loaded for command: " + command);
            }
            final A aggregate = processedAggregate.get();
            final List<Event> events = aggregate.getUncommittedEvents();
            store(aggregate);
            stand.post(aggregate, command.getContext());
            postEvents(events);
        }
    };
    op.execute();
}
Also used : Command(io.spine.base.Command) GetTargetIdFromCommand(io.spine.server.entity.idfunc.GetTargetIdFromCommand) CommandOperation(io.spine.server.tenant.CommandOperation) Event(io.spine.base.Event)

Example 3 with CommandOperation

use of io.spine.server.tenant.CommandOperation in project core-java by SpineEventEngine.

the class RejectionSubscriber method dispatch.

/**
 * {@inheritDoc}
 *
 * @param envelope the envelope with the message
 * @return a one element set with the result of {@link #toString()} as the identity of
 * the subscriber, or empty set if dispatching failed
 */
@Override
public Set<String> dispatch(final RejectionEnvelope envelope) {
    final Command originCommand = envelope.getOuterObject().getContext().getCommand();
    final CommandOperation op = new CommandOperation(originCommand) {

        @Override
        public void run() {
            handle(envelope);
        }
    };
    try {
        op.execute();
    } catch (RuntimeException e) {
        onError(envelope, e);
        return ImmutableSet.of();
    }
    return Identity.of(this);
}
Also used : Command(io.spine.core.Command) CommandOperation(io.spine.server.tenant.CommandOperation)

Example 4 with CommandOperation

use of io.spine.server.tenant.CommandOperation in project core-java by SpineEventEngine.

the class CommandStore method updateStatus.

/**
 * Updates the status of the command with the passed error.
 *
 * @param commandEnvelope the ID of the command
 * @param error           the error, which occurred during command processing
 */
private void updateStatus(CommandEnvelope commandEnvelope, final Error error) {
    keepTenantId(commandEnvelope.getCommand());
    final TenantAwareOperation op = new CommandOperation(commandEnvelope.getCommand()) {

        @Override
        public void run() {
            repository.updateStatus(commandId(), error);
        }
    };
    op.execute();
}
Also used : CommandOperation(io.spine.server.tenant.CommandOperation) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation)

Aggregations

CommandOperation (io.spine.server.tenant.CommandOperation)4 Command (io.spine.base.Command)2 Event (io.spine.base.Event)1 Command (io.spine.core.Command)1 GetTargetIdFromCommand (io.spine.server.entity.idfunc.GetTargetIdFromCommand)1 TenantAwareOperation (io.spine.server.tenant.TenantAwareOperation)1