Skip to content

Commit

Permalink
Merge pull request #1447 from SpineEventEngine/custom-executor-service
Browse files Browse the repository at this point in the history
Allow supplying `Executor` for `SystemWriteSide`
  • Loading branch information
yevhenii-nadtochii authored Apr 19, 2022
2 parents 681df5c + 5a52218 commit b619573
Show file tree
Hide file tree
Showing 14 changed files with 465 additions and 206 deletions.
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:2.0.0-SNAPSHOT.94`
# Dependencies of `io.spine:spine-client:2.0.0-SNAPSHOT.95`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -520,12 +520,12 @@

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Apr 08 15:04: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).
This report was generated on **Fri Apr 15 19:35:16 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:2.0.0-SNAPSHOT.94`
# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.95`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -1005,12 +1005,12 @@ This report was generated on **Fri Apr 08 15:04:55 EEST 2022** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Apr 08 15:04:56 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).
This report was generated on **Fri Apr 15 19:35:17 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:2.0.0-SNAPSHOT.94`
# Dependencies of `io.spine.tools:spine-model-assembler:2.0.0-SNAPSHOT.95`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -1530,12 +1530,12 @@ This report was generated on **Fri Apr 08 15:04:56 EEST 2022** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Apr 08 15:04:56 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).
This report was generated on **Fri Apr 15 19:35:17 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:2.0.0-SNAPSHOT.94`
# Dependencies of `io.spine.tools:spine-model-verifier:2.0.0-SNAPSHOT.95`

## Runtime
1. **Group** : com.github.ben-manes.caffeine. **Name** : caffeine. **Version** : 2.8.8.
Expand Down Expand Up @@ -2155,12 +2155,12 @@ This report was generated on **Fri Apr 08 15:04:56 EEST 2022** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Apr 08 15:04:57 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).
This report was generated on **Fri Apr 15 19:35:18 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:2.0.0-SNAPSHOT.94`
# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.95`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -2688,12 +2688,12 @@ This report was generated on **Fri Apr 08 15:04:57 EEST 2022** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Apr 08 15:04:58 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).
This report was generated on **Fri Apr 15 19:35:18 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-testutil-client:2.0.0-SNAPSHOT.94`
# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.95`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3265,12 +3265,12 @@ This report was generated on **Fri Apr 08 15:04:58 EEST 2022** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Apr 08 15:04:59 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).
This report was generated on **Fri Apr 15 19:35:19 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-testutil-core:2.0.0-SNAPSHOT.94`
# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.95`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3842,12 +3842,12 @@ This report was generated on **Fri Apr 08 15:04:59 EEST 2022** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Apr 08 15:04:59 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).
This report was generated on **Fri Apr 15 19:35:19 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-testutil-server:2.0.0-SNAPSHOT.94`
# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.95`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -4464,4 +4464,4 @@ This report was generated on **Fri Apr 08 15:04:59 EEST 2022** using [Gradle-Lic

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Apr 08 15:05:00 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).
This report was generated on **Fri Apr 15 19:35:20 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 @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject.
-->
<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>2.0.0-SNAPSHOT.94</version>
<version>2.0.0-SNAPSHOT.95</version>

<inceptionYear>2015</inceptionYear>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@
* <p>Uses a hash code of the entity identifier and the remainder of its division by the total
* number of shards to determine the index of a shard, at which the modification is allowed.
* To reach the consistency of the hash code values across JVMs,
* the {@linkplain Hashing#murmur3_32() MurmurHash3, x86 variant} is used.
*
* <p>While Guava's {@code Hashing} is marked {@code @Beta}, it is still the best option
* for hashing functions — not to involve any heavy-weight third-party hashing
* solutions.
* the {@linkplain Hashing#murmur3_32_fixed() MurmurHash3, x86 variant} is used.
*/
@Immutable
public final class UniformAcrossAllShards extends DeliveryStrategy implements Serializable {
Expand All @@ -58,8 +54,7 @@ public final class UniformAcrossAllShards extends DeliveryStrategy implements Se
/**
* The hash function to use for the shard index calculation.
*/
@SuppressWarnings("UnstableApiUsage") // See the class-level docs.
private static final HashFunction HASHER = Hashing.murmur3_32();
private static final HashFunction HASHER = Hashing.murmur3_32_fixed();

private final int numberOfShards;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private EventReactorClass(Class<? extends S> cls) {
@SuppressWarnings("unchecked")
var 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 @@ -79,7 +79,6 @@ public Iterator<I> index() {
*/
public Iterator<I> index(RecordQuery<I, R> query) {
var subset = findRecords(query);
@SuppressWarnings("ConstantConditions") // Elements of the returned list are non-`null`.
var result = Iterators.transform(subset.iterator(), RecordWithColumns::id);
return result;
}
Expand Down Expand Up @@ -131,7 +130,7 @@ private List<RecordWithColumns<I, R>> findRecords(RecordQuery<I, R> query) {
var stream = data;
var sortingSpecs = query.sorting();
if (sortingSpecs.size() > 0) {
stream = stream.sorted(accordingTo(sortingSpecs.asList()));
stream = stream.sorted(accordingTo(sortingSpecs));
}
var limit = query.limit();
if (limit != null && limit > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 @@ -62,12 +61,16 @@ final class DefaultSystemWriteSide implements SystemWriteSide {
public Event postEvent(EventMessage systemEvent, Origin origin) {
checkNotNull(systemEvent);
checkNotNull(origin);

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

if (config.postEventsInParallel()) {
config.postingExecutor().execute(() -> postEvent(event));
} else {
postEvent(event);
}

return event;
}

Expand Down
32 changes: 24 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.checkNotNull;
import static java.util.Objects.hash;
import static java.util.Objects.nonNull;

/**
* An immutable set of features of a {@link SystemContext}.
Expand All @@ -37,14 +43,14 @@ final class SystemConfig implements SystemFeatures {

private final boolean commandLog;
private final boolean storeEvents;
private final boolean parallelPosting;
private final @Nullable Executor postingExecutor;

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

@Override
Expand All @@ -59,7 +65,17 @@ 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 call the method, make sure {@link #postEventsInParallel()} is enabled.
*/
Executor postingExecutor() {
checkNotNull(postingExecutor);
return postingExecutor;
}

@Override
Expand All @@ -73,11 +89,11 @@ public boolean equals(Object o) {
var config = (SystemConfig) o;
return commandLog == config.commandLog &&
storeEvents == config.storeEvents &&
parallelPosting == config.parallelPosting;
Objects.equals(postingExecutor, config.postingExecutor);
}

@Override
public int hashCode() {
return Objects.hashCode(commandLog, storeEvents, parallelPosting);
return hash(commandLog, storeEvents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,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

0 comments on commit b619573

Please sign in to comment.