use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class CommandService method handleUnsupported.
private static void handleUnsupported(Command request, StreamObserver<Ack> responseObserver) {
final UnsupportedCommandException unsupported = new UnsupportedCommandException(request);
log().error("Unsupported command posted to CommandService", unsupported);
final Error error = unsupported.asError();
final Ack response = reject(request.getId(), error);
responseObserver.onNext(response);
responseObserver.onCompleted();
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class Bus method doPost.
/**
* Posts each of the given envelopes into the bus and notifies the given observer.
*
* @param envelopes the envelopes to post
* @param observer the observer to be notified of the operation result
* @see #doPost(MessageEnvelope)
*/
private void doPost(Iterable<E> envelopes, StreamObserver<Ack> observer) {
for (E message : envelopes) {
final Ack result = doPost(message);
observer.onNext(result);
}
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class DeadMessageFilter method accept.
@Override
public Optional<Ack> accept(E envelope) {
@SuppressWarnings("unchecked") final C cls = (C) envelope.getMessageClass();
final Collection<D> dispatchers = registry.getDispatchers(cls);
if (dispatchers.isEmpty()) {
final MessageUnhandled report = deadMessageHandler.handle(envelope);
final Error error = report.asError();
final Any packedId = Identifier.pack(envelope.getId());
final Ack result = reject(packedId, error);
return Optional.of(result);
} else {
return Optional.absent();
}
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class ValidatingFilter method accept.
@Override
public Optional<Ack> accept(E envelope) {
checkNotNull(envelope);
final Optional<MessageInvalid> violation = validator.validate(envelope);
if (violation.isPresent()) {
final Error error = violation.get().asError();
final Any packedId = Identifier.pack(envelope.getId());
final Ack result = reject(packedId, error);
return Optional.of(result);
} else {
return Optional.absent();
}
}
use of io.spine.core.Ack in project core-java by SpineEventEngine.
the class CommandBus method doPost.
@Override
protected Ack doPost(CommandEnvelope envelope) {
final CommandDispatcher<?> dispatcher = getDispatcher(envelope);
Ack result;
try {
dispatcher.dispatch(envelope);
commandStore.setCommandStatusOk(envelope);
result = acknowledge(envelope.getId());
} catch (RuntimeException e) {
final Throwable cause = getRootCause(e);
commandStore.updateCommandStatus(envelope, cause, log);
if (causedByRejection(e)) {
final ThrowableMessage throwableMessage = (ThrowableMessage) cause;
final Rejection rejection = toRejection(throwableMessage, envelope.getCommand());
final Class<?> rejectionClass = AnyPacker.unpack(rejection.getMessage()).getClass();
Log.log().trace("Posting rejection {} to RejectionBus.", rejectionClass.getName());
rejectionBus().post(rejection);
result = reject(envelope.getId(), rejection);
} else {
final Error error = toError(cause);
result = reject(envelope.getId(), error);
}
}
return result;
}
Aggregations