Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Allow supplying Executor for SystemWriteSide #1448

Merged
merged 10 commits into from
Apr 20, 2022
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.8.1`
# Dependencies of `io.spine:spine-client:1.8.2-SNAPSHOT.1`

## 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 **Tue Mar 22 16:20:09 EET 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 **Tue Apr 19 18:02:49 EEST 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).




# Dependencies of `io.spine:spine-core:1.8.1`
# Dependencies of `io.spine:spine-core:1.8.2-SNAPSHOT.1`

## 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 **Tue Mar 22 16:20:09 EET 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Mar 22 16:20:09 EET 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 **Tue Apr 19 18:02:50 EEST 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).




# Dependencies of `io.spine.tools:spine-model-assembler:1.8.1`
# Dependencies of `io.spine.tools:spine-model-assembler:1.8.2-SNAPSHOT.1`

## 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 **Tue Mar 22 16:20:09 EET 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Mar 22 16:20:10 EET 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 **Tue Apr 19 18:02:50 EEST 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).




# Dependencies of `io.spine.tools:spine-model-verifier:1.8.1`
# Dependencies of `io.spine.tools:spine-model-verifier:1.8.2-SNAPSHOT.1`

## 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 **Tue Mar 22 16:20:10 EET 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Mar 22 16:20:10 EET 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 **Tue Apr 19 18:02:51 EEST 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).




# Dependencies of `io.spine:spine-server:1.8.1`
# Dependencies of `io.spine:spine-server:1.8.2-SNAPSHOT.1`

## 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 **Tue Mar 22 16:20:10 EET 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Mar 22 16:20:11 EET 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 **Tue Apr 19 18:02:51 EEST 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).




# Dependencies of `io.spine:spine-testutil-client:1.8.1`
# Dependencies of `io.spine:spine-testutil-client:1.8.2-SNAPSHOT.1`

## 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 **Tue Mar 22 16:20:11 EET 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Mar 22 16:20:12 EET 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 **Tue Apr 19 18:02:53 EEST 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).




# Dependencies of `io.spine:spine-testutil-core:1.8.1`
# Dependencies of `io.spine:spine-testutil-core:1.8.2-SNAPSHOT.1`

## 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 **Tue Mar 22 16:20:12 EET 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Mar 22 16:20:13 EET 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 **Tue Apr 19 18:02:54 EEST 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).




# Dependencies of `io.spine:spine-testutil-server:1.8.1`
# Dependencies of `io.spine:spine-testutil-server:1.8.2-SNAPSHOT.1`

## 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 **Tue Mar 22 16:20:13 EET 2022** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Mar 22 16:20:15 EET 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 **Tue Apr 19 18:02:55 EEST 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).
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.8.1</version>
<version>1.8.2-SNAPSHOT.1</version>

<inceptionYear>2015</inceptionYear>

Expand Down
26 changes: 12 additions & 14 deletions server/src/main/java/io/spine/server/BoundedContextBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public final class BoundedContextBuilder implements Logging {
*/
private final Collection<EventDispatcher> eventDispatchers = new ArrayList<>();

private final SystemSettings systemFeatures;
private final SystemSettings systemSettings;

private Stand stand;
private Supplier<AggregateRootDirectory> rootDirectory;
Expand All @@ -117,18 +117,18 @@ public final class BoundedContextBuilder implements Logging {
}

/**
* Creates a new builder with the given spec and system features.
* Creates a new builder with the given spec and system settings.
*
* @param spec
* the context spec for the built context
* @param systemFeatures
* system feature flags; can be changed later via {@link #systemFeatures()}
* @param systemSettings
* settings of the System context; may be changed later via {@link #systemSettings()}
* @see BoundedContext#singleTenant
* @see BoundedContext#multitenant
*/
private BoundedContextBuilder(ContextSpec spec, SystemSettings systemFeatures) {
private BoundedContextBuilder(ContextSpec spec, SystemSettings systemSettings) {
this.spec = checkNotNull(spec);
this.systemFeatures = checkNotNull(systemFeatures);
this.systemSettings = checkNotNull(systemSettings);
}

/**
Expand Down Expand Up @@ -515,14 +515,12 @@ AggregateRootDirectory aggregateRootDirectory() {
}

/**
* Obtains the system context feature configuration.
* Obtains the configuration of the System context.
*
* <p>Users may enable or disable some features of the system context.
*
* @see SystemSettings
* <p>With it, users are able to change the behavior of the system context.
*/
public SystemSettings systemFeatures() {
return systemFeatures;
public SystemSettings systemSettings() {
return systemSettings;
}

/**
Expand Down Expand Up @@ -590,7 +588,7 @@ private BoundedContext buildDomain(SystemContext system) {
}

private SystemContext buildSystem() {
BoundedContextBuilder system = new BoundedContextBuilder(systemSpec(), systemFeatures);
BoundedContextBuilder system = new BoundedContextBuilder(systemSpec(), systemSettings);
Optional<? extends TenantIndex> tenantIndex = tenantIndex();
tenantIndex.ifPresent(system::setTenantIndex);
SystemContext result =
Expand All @@ -600,7 +598,7 @@ private SystemContext buildSystem() {

private ContextSpec systemSpec() {
ContextSpec systemSpec = this.spec.toSystem();
if (!systemFeatures.includePersistentEvents()) {
if (!systemSettings.includePersistentEvents()) {
systemSpec = systemSpec.notStoringEvents();
}
return systemSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private EventReactorClass(Class<? extends S> cls) {
@SuppressWarnings("unchecked")
EventReactorClass<S> result = (EventReactorClass<S>)
get(cls, EventReactorClass.class, () -> new EventReactorClass<>(cls));
return (result);
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static ThirdPartyContext newContext(String name, boolean multitenant) {
BoundedContextBuilder contextBuilder = multitenant
? BoundedContext.multitenant(name)
: BoundedContext.singleTenant(name);
contextBuilder.systemFeatures()
contextBuilder.systemSettings()
.disableCommandLog()
.disableAggregateQuerying()
.forgetEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static io.spine.grpc.StreamObservers.noOpObserver;
import static io.spine.system.server.SystemEventFactory.forMessage;
import static java.util.concurrent.ForkJoinPool.commonPool;

/**
* The default implementation of {@link SystemWriteSide}.
Expand All @@ -61,9 +60,12 @@ final class DefaultSystemWriteSide implements SystemWriteSide {
public Event postEvent(EventMessage systemEvent, Origin origin) {
checkNotNull(systemEvent);
checkNotNull(origin);

Event event = event(systemEvent, origin);
if (system.config().postEventsInParallel()) {
commonPool().execute(() -> postEvent(event));
SystemConfig config = system.config();

if (config.postEventsInParallel()) {
config.postingExecutor().execute(() -> postEvent(event));
} else {
postEvent(event);
}
Expand Down
35 changes: 27 additions & 8 deletions server/src/main/java/io/spine/system/server/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@

package io.spine.system.server;

import com.google.common.base.Objects;
import com.google.errorprone.annotations.Immutable;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import java.util.Objects;
import java.util.concurrent.Executor;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.hash;
import static java.util.Objects.nonNull;

/**
* An immutable set of features of a {@link SystemContext}.
Expand All @@ -38,16 +44,16 @@ final class SystemConfig implements SystemFeatures {
private final boolean commandLog;
private final boolean aggregateMirrors;
private final boolean storeEvents;
private final boolean parallelPosting;
private final @Nullable Executor postingExecutor;

SystemConfig(boolean commandLog,
boolean aggregateMirrors,
boolean storeEvents,
boolean parallelPosting) {
@Nullable Executor postingExecutor) {
this.commandLog = commandLog;
this.aggregateMirrors = aggregateMirrors;
this.storeEvents = storeEvents;
this.parallelPosting = parallelPosting;
this.postingExecutor = postingExecutor;
}

@Override
Expand All @@ -67,7 +73,20 @@ public boolean includePersistentEvents() {

@Override
public boolean postEventsInParallel() {
return parallelPosting;
return nonNull(postingExecutor);
}

/**
* Returns an {@code Executor} to be used to post system events in parallel.
*
* <p>Before calling this method, make sure parallel posting
* {@linkplain #postEventsInParallel() is enabled}.
*
* @throws IllegalStateException if parallel posting of system events is disabled
*/
Executor postingExecutor() {
checkState(postEventsInParallel());
return postingExecutor;
}

@SuppressWarnings("OverlyComplexBooleanExpression")
Expand All @@ -83,11 +102,11 @@ public boolean equals(Object o) {
return commandLog == config.commandLog &&
aggregateMirrors == config.aggregateMirrors &&
storeEvents == config.storeEvents &&
parallelPosting == config.parallelPosting;
Objects.equals(postingExecutor, config.postingExecutor);
}

@Override
public int hashCode() {
return Objects.hashCode(commandLog, aggregateMirrors, storeEvents, parallelPosting);
return hash(commandLog, aggregateMirrors, storeEvents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class SystemContext extends BoundedContext {

private SystemContext(BoundedContextBuilder builder) {
super(builder);
this.config = builder.systemFeatures()
this.config = builder.systemSettings()
.freeze();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ interface SystemFeatures {
* @return {@code true} if system events should be stored, {@code false} otherwise
*/
boolean includePersistentEvents();

/**
* Checks if the system events are allowed to be posted in parallel.
*
* @return {@code true} if it's OK to post system event is parallel, {@code false} otherwise
* @return {@code true} if it's OK to post system events in parallel, {@code false} otherwise
*/
boolean postEventsInParallel();
}
Loading