Skip to content

Commit

Permalink
Merge pull request #1496 from SpineEventEngine/1x-delivery-reporting-…
Browse files Browse the repository at this point in the history
…errors

[1.x] Allow to handle any `RuntimeException`s occurring when delivering an `InboxMessage`
  • Loading branch information
armiol authored Jan 3, 2023
2 parents 909d5dc + 9746d9b commit 37781a5
Show file tree
Hide file tree
Showing 69 changed files with 1,510 additions and 341 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build-on-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'true'

- uses: actions/setup-java@v3
with:
java-version: 8
distribution: zulu
cache: gradle

- name: Pull config
run: git submodule update --init --recursive

- name: Build project and run tests
shell: bash
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
with:
java-version: 8
distribution: zulu
cache: gradle

- name: Decrypt CloudRepo credentials
run: ./config/scripts/decrypt.sh "$CLOUDREPO_CREDENTIALS_KEY" ./.github/keys/cloudrepo.properties.gpg ./cloudrepo.properties
Expand Down
32 changes: 16 additions & 16 deletions license-report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# Dependencies of `io.spine:spine-client:1.9.0-SNAPSHOT.5`
# Dependencies of `io.spine:spine-client:1.9.0-SNAPSHOT.6`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -399,12 +399,12 @@
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Wed Nov 09 14:52:22 TRT 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 02 10:21:33 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-core:1.9.0-SNAPSHOT.5`
# Dependencies of `io.spine:spine-core:1.9.0-SNAPSHOT.6`

## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
Expand Down Expand Up @@ -763,12 +763,12 @@ This report was generated on **Wed Nov 09 14:52:22 TRT 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Wed Nov 09 14:52:23 TRT 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 02 10:21:34 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-model-assembler:1.9.0-SNAPSHOT.5`
# Dependencies of `io.spine.tools:spine-model-assembler:1.9.0-SNAPSHOT.6`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -1162,12 +1162,12 @@ This report was generated on **Wed Nov 09 14:52:23 TRT 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Wed Nov 09 14:52:24 TRT 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 02 10:21:35 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-model-verifier:1.9.0-SNAPSHOT.5`
# Dependencies of `io.spine.tools:spine-model-verifier:1.9.0-SNAPSHOT.6`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -1627,12 +1627,12 @@ This report was generated on **Wed Nov 09 14:52:24 TRT 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Wed Nov 09 14:52:26 TRT 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 02 10:21:35 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-server:1.9.0-SNAPSHOT.5`
# Dependencies of `io.spine:spine-server:1.9.0-SNAPSHOT.6`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -2039,12 +2039,12 @@ This report was generated on **Wed Nov 09 14:52:26 TRT 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Wed Nov 09 14:52:27 TRT 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 02 10:21:36 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-testutil-client:1.9.0-SNAPSHOT.5`
# Dependencies of `io.spine:spine-testutil-client:1.9.0-SNAPSHOT.6`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -2493,12 +2493,12 @@ This report was generated on **Wed Nov 09 14:52:27 TRT 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Wed Nov 09 14:52:30 TRT 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 02 10:21:39 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-testutil-core:1.9.0-SNAPSHOT.5`
# Dependencies of `io.spine:spine-testutil-core:1.9.0-SNAPSHOT.6`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -2947,12 +2947,12 @@ This report was generated on **Wed Nov 09 14:52:30 TRT 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Wed Nov 09 14:52:32 TRT 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 02 10:21:40 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-testutil-server:1.9.0-SNAPSHOT.5`
# Dependencies of `io.spine:spine-testutil-server:1.9.0-SNAPSHOT.6`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -3445,4 +3445,4 @@ This report was generated on **Wed Nov 09 14:52:32 TRT 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Wed Nov 09 14:52:39 TRT 2022** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Jan 02 10:21:44 WET 2023** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.

<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>1.9.0-SNAPSHOT.5</version>
<version>1.9.0-SNAPSHOT.6</version>

<inceptionYear>2015</inceptionYear>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class AggregateEndpoint<I,
}

@Override
public final void dispatchTo(I aggregateId) {
protected final DispatchOutcome performDispatch(I aggregateId) {
A aggregate = loadOrCreate(aggregateId);
LifecycleFlags flagsBefore = aggregate.lifecycleFlags();
DispatchOutcome outcome = handleAndApplyEvents(aggregate);
Expand All @@ -86,6 +86,7 @@ public final void dispatchTo(I aggregateId) {
repository().lifecycleOf(aggregateId)
.onDispatchingFailed(envelope(), error);
}
return outcome;
}

private void storeAndPost(A aggregate, DispatchOutcome outcome) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.spine.core.CommandId;
import io.spine.core.Event;
import io.spine.core.EventContext;
import io.spine.json.Json;
import io.spine.server.BoundedContext;
import io.spine.server.ServerEnvironment;
import io.spine.server.aggregate.model.AggregateClass;
Expand All @@ -43,6 +44,7 @@
import io.spine.server.delivery.Inbox;
import io.spine.server.delivery.InboxLabel;
import io.spine.server.dispatch.BatchDispatchOutcome;
import io.spine.server.dispatch.DispatchOutcome;
import io.spine.server.entity.EntityLifecycle;
import io.spine.server.entity.EventProducingRepository;
import io.spine.server.entity.Repository;
Expand Down Expand Up @@ -73,8 +75,11 @@
import static com.google.common.base.Suppliers.memoize;
import static io.spine.option.EntityOption.Kind.AGGREGATE;
import static io.spine.server.aggregate.model.AggregateClass.asAggregateClass;
import static io.spine.server.dispatch.DispatchOutcomes.maybeSentToInbox;
import static io.spine.server.dispatch.DispatchOutcomes.sentToInbox;
import static io.spine.server.tenant.TenantAwareRunner.with;
import static io.spine.util.Exceptions.newIllegalStateException;
import static java.util.Objects.requireNonNull;

/**
* The repository which manages instances of {@code Aggregate}s.
Expand Down Expand Up @@ -200,7 +205,7 @@ public void onEnd(I id) {
}

private Inbox<I> inbox() {
return checkNotNull(inbox);
return requireNonNull(inbox);
}

/**
Expand Down Expand Up @@ -333,11 +338,12 @@ public final ImmutableSet<CommandClass> messageClasses() {
* the command to dispatch
*/
@Override
public final void dispatch(CommandEnvelope cmd) {
public final DispatchOutcome dispatch(CommandEnvelope cmd) {
checkNotNull(cmd);
Optional<I> target = route(cmd);
target.ifPresent(id -> inbox().send(cmd)
.toHandler(id));
return maybeSentToInbox(cmd, target);
}

private Optional<I> route(CommandEnvelope cmd) {
Expand Down Expand Up @@ -387,11 +393,12 @@ public ImmutableSet<EventClass> outgoingEvents() {
* the event to dispatch
*/
@Override
public void dispatchEvent(EventEnvelope event) {
public DispatchOutcome dispatchEvent(EventEnvelope event) {
checkNotNull(event);
Set<I> targets = route(event);
targets.forEach((id) -> inbox().send(event)
.toReactor(id));
return sentToInbox(event, targets);
}

private Set<I> route(EventEnvelope event) {
Expand All @@ -402,11 +409,12 @@ private Set<I> route(EventEnvelope event) {
/**
* Imports the passed event into one of the aggregates.
*/
final void importEvent(EventEnvelope event) {
final DispatchOutcome importEvent(EventEnvelope event) {
checkNotNull(event);
Optional<I> target = routeImport(event);
target.ifPresent(id -> inbox().send(event)
.toImporter(id));
.toImporter(id));
return maybeSentToInbox(event, target);
}

private Optional<I> routeImport(EventEnvelope event) {
Expand Down Expand Up @@ -475,7 +483,7 @@ protected int snapshotTrigger() {
*
* <p><b>NOTE</b>: repository read operations are optimized around the current snapshot
* trigger. Setting the snapshot trigger to a new value may cause read operations to perform
* sub-optimally, until a new snapshot is created. This doesn't apply to newly created
* suboptimally, until a new snapshot is created. This doesn't apply to newly created
* repositories.
*
* @param snapshotTrigger
Expand Down Expand Up @@ -590,7 +598,7 @@ private Optional<A> load(I id) {
*
* <p>The current {@link #snapshotTrigger} is used as a read operation
* {@linkplain AggregateReadRequest#batchSize()} batch size}, so the method can perform
* sub-optimally for some time after a {@link #snapshotTrigger} change.
* suboptimally for some time after a {@link #snapshotTrigger} change.
*
* @param id
* the ID of the {@code Aggregate} to fetch
Expand Down Expand Up @@ -623,10 +631,14 @@ protected A play(I id, AggregateHistory history) {
tx.commitIfActive();
if (!success) {
lifecycleOf(id).onCorruptedState(outcome);
throw newIllegalStateException("Aggregate `%s` (ID: %s) cannot be loaded.%n",
aggregateClass().value()
.getName(),
result.idAsString());
String outcomeDetails = Json.toJson(outcome);
String aggClass = aggregateClass().value()
.getName();
throw newIllegalStateException("Aggregate `%s` (ID: %s) cannot be loaded.%n" +
"Erroneous dispatch outcome: `%s`.",
aggClass,
result.idAsString(),
outcomeDetails);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.spine.annotation.Internal;
import io.spine.logging.Logging;
import io.spine.server.dispatch.DispatchOutcome;
import io.spine.server.event.EventDispatcher;
import io.spine.server.type.EventClass;
import io.spine.server.type.EventEnvelope;
Expand Down Expand Up @@ -84,7 +85,7 @@ public ImmutableSet<EventClass> externalEventClasses() {

@CanIgnoreReturnValue
@Override
public void dispatch(EventEnvelope event) {
repository.importEvent(event);
public DispatchOutcome dispatch(EventEnvelope event) {
return repository.importEvent(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package io.spine.server.bus;

import com.google.common.collect.ImmutableSet;
import io.spine.server.dispatch.DispatchOutcome;
import io.spine.server.type.MessageEnvelope;
import io.spine.type.MessageClass;

Expand All @@ -48,11 +49,12 @@ public interface MessageDispatcher<C extends MessageClass, E extends MessageEnve
ImmutableSet<C> messageClasses();

/**
* Dispatches the message contained in the passed envelope.
* Dispatches the message contained in the passed envelope
* and returns the outcome.
*
* @param envelope the envelope with the message
*/
void dispatch(E envelope);
DispatchOutcome dispatch(E envelope);

/**
* Checks if this dispatcher can dispatch the given message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.spine.server.command.model.CommandHandlerClass;
import io.spine.server.command.model.CommandHandlerMethod;
import io.spine.server.commandbus.CommandDispatcher;
import io.spine.server.dispatch.DispatchOutcome;
import io.spine.server.dispatch.DispatchOutcomeHandler;
import io.spine.server.event.EventBus;
import io.spine.server.type.CommandClass;
Expand Down Expand Up @@ -82,14 +83,16 @@ public abstract class AbstractCommandHandler
* if an exception occurred during command dispatching with this exception as the cause
*/
@Override
public void dispatch(CommandEnvelope envelope) {
public DispatchOutcome dispatch(CommandEnvelope envelope) {
CommandHandlerMethod method = thisClass.handlerOf(envelope.messageClass());
DispatchOutcome outcome = method.invoke(this, envelope);
DispatchOutcomeHandler
.from(method.invoke(this, envelope))
.from(outcome)
.onEvents(this::postEvents)
.onError(error -> onError(envelope, error))
.onRejection(rejection -> onRejection(envelope, rejection))
.handle();
return outcome;
}

@Override
Expand Down
Loading

0 comments on commit 37781a5

Please sign in to comment.