Search in sources :

Example 11 with Ack

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();
}
Also used : UnsupportedCommandException(io.spine.server.commandbus.UnsupportedCommandException) Ack(io.spine.core.Ack) Error(io.spine.base.Error)

Example 12 with Ack

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);
    }
}
Also used : Ack(io.spine.core.Ack)

Example 13 with Ack

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();
    }
}
Also used : Ack(io.spine.core.Ack) Error(io.spine.base.Error) Any(com.google.protobuf.Any)

Example 14 with Ack

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();
    }
}
Also used : Ack(io.spine.core.Ack) Error(io.spine.base.Error) MessageInvalid(io.spine.core.MessageInvalid) Any(com.google.protobuf.Any)

Example 15 with Ack

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;
}
Also used : Rejections.toRejection(io.spine.core.Rejections.toRejection) Rejections.causedByRejection(io.spine.core.Rejections.causedByRejection) Rejection(io.spine.core.Rejection) ThrowableMessage(io.spine.base.ThrowableMessage) Ack(io.spine.core.Ack) Exceptions.toError(io.spine.util.Exceptions.toError) Error(io.spine.base.Error) CommandClass(io.spine.core.CommandClass)

Aggregations

Ack (io.spine.core.Ack)29 Test (org.junit.Test)18 Command (io.spine.core.Command)15 Error (io.spine.base.Error)11 TenantId (io.spine.core.TenantId)11 CommandBus (io.spine.server.commandbus.CommandBus)7 Any (com.google.protobuf.Any)6 Event (io.spine.core.Event)6 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)6 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)6 Rejection (io.spine.core.Rejection)5 BoundedContext (io.spine.server.BoundedContext)5 ProjectId (io.spine.test.aggregate.ProjectId)4 Status (io.spine.core.Status)3 AggregateMessageDispatcher.dispatchRejection (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchRejection)3 IdempotencyGuardTestEnv.newProjectId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newProjectId)3 IdempotencyGuardTestEnv.newTenantId (io.spine.server.aggregate.given.IdempotencyGuardTestEnv.newTenantId)3 AggregateTestEnv.newTaskBoundedContext (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTaskBoundedContext)3 IgTestAggregate (io.spine.server.aggregate.given.aggregate.IgTestAggregate)3 Rejections.toRejection (io.spine.core.Rejections.toRejection)2