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();
}
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();
}
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);
}
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();
}
Aggregations