Skip to content

More internal type filtering #1471

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

Merged
merged 32 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9439920
Bump version -> `2.0.0-SNAPSHOT.107`
alexander-yevsyukov Sep 15, 2022
7cc1f23
Improve exception class name
alexander-yevsyukov Sep 15, 2022
3a92e65
Extract method
alexander-yevsyukov Sep 15, 2022
5947d25
Narrow the var scope
alexander-yevsyukov Sep 15, 2022
d6ca2d1
Simplify logging
alexander-yevsyukov Sep 15, 2022
4dab06d
Introduce service delegation
alexander-yevsyukov Sep 15, 2022
079c300
Make impl class final
alexander-yevsyukov Sep 15, 2022
8293238
Use service delegate
alexander-yevsyukov Sep 15, 2022
1a97413
Shorten param name
alexander-yevsyukov Sep 15, 2022
3b02184
Shorten param name
alexander-yevsyukov Sep 15, 2022
a89100f
Obtain served contexts
alexander-yevsyukov Sep 15, 2022
c3c5ec7
Use service delegate for subscriptions
alexander-yevsyukov Sep 15, 2022
92209bd
Fix Javadoc language
alexander-yevsyukov Sep 16, 2022
c5f87be
Improve method name
alexander-yevsyukov Sep 16, 2022
e91ab30
Add impl-dependant param
alexander-yevsyukov Sep 16, 2022
2f44028
Migrate activation to a delegate class
alexander-yevsyukov Sep 16, 2022
963c706
Migrate cancellation to a delegate class
alexander-yevsyukov Sep 16, 2022
f4833bd
Unify usage of thread-safe observers
alexander-yevsyukov Sep 16, 2022
351ce59
Extract handling thread safety
alexander-yevsyukov Sep 16, 2022
b01704a
Fix typo
alexander-yevsyukov Sep 16, 2022
ea06cef
Fix typo
alexander-yevsyukov Sep 16, 2022
de9708b
Use exception ctor with type name
alexander-yevsyukov Sep 16, 2022
1f77c0e
Bump `base` -> `2.0.0-SNAPSHOT.96`
alexander-yevsyukov Sep 16, 2022
0f547c7
Bump `base` -> `2.0.0-SNAPSHOT.96`
alexander-yevsyukov Sep 16, 2022
e8a2ceb
Annotate log message parameter
alexander-yevsyukov Sep 16, 2022
ac282db
Migrate equality to Truth
alexander-yevsyukov Sep 16, 2022
cea0c20
Test rejecting internal command
alexander-yevsyukov Sep 16, 2022
08159fa
Test rejecting queries for internal types
alexander-yevsyukov Sep 17, 2022
227a782
Test rejecting subscriptions on internal types
alexander-yevsyukov Sep 17, 2022
bc07acf
Update build time
alexander-yevsyukov Sep 17, 2022
b9da872
Update build time
alexander-yevsyukov Sep 19, 2022
57eafa1
Fix typos
alexander-yevsyukov Sep 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class ThreadSafeObserver<V> implements StreamObserver<V> {

/**
* Creates a new instance of {@code ThreadSafeObserver} by wrapping the passed instance
* and delegating all of calls to it.
* and delegating all the calls to it.
*
* @param observer
* the observer to wrap into a thread-safe shell
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:2.0.0-SNAPSHOT.106`
# Dependencies of `io.spine:spine-client:2.0.0-SNAPSHOT.107`

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

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

This report was generated on **Thu Sep 01 15:08:23 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 **Mon Sep 19 17:28:07 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).




# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.106`
# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.107`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -1203,12 +1203,12 @@ This report was generated on **Thu Sep 01 15:08:23 EEST 2022** using [Gradle-Lic

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

This report was generated on **Thu Sep 01 15:08:23 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 **Mon Sep 19 17:28:07 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).




# Dependencies of `io.spine.tools:spine-model-assembler:2.0.0-SNAPSHOT.106`
# Dependencies of `io.spine.tools:spine-model-assembler:2.0.0-SNAPSHOT.107`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -1827,12 +1827,12 @@ This report was generated on **Thu Sep 01 15:08:23 EEST 2022** using [Gradle-Lic

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

This report was generated on **Thu Sep 01 15:08:24 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 **Mon Sep 19 17:28:07 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).




# Dependencies of `io.spine.tools:spine-model-verifier:2.0.0-SNAPSHOT.106`
# Dependencies of `io.spine.tools:spine-model-verifier:2.0.0-SNAPSHOT.107`

## Runtime
1. **Group** : com.github.ben-manes.caffeine. **Name** : caffeine. **Version** : 2.8.8.
Expand Down Expand Up @@ -2551,12 +2551,12 @@ This report was generated on **Thu Sep 01 15:08:24 EEST 2022** using [Gradle-Lic

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

This report was generated on **Thu Sep 01 15:08:24 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 **Mon Sep 19 17:28:08 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).




# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.106`
# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.107`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3183,12 +3183,12 @@ This report was generated on **Thu Sep 01 15:08:24 EEST 2022** using [Gradle-Lic

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

This report was generated on **Thu Sep 01 15:08:25 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 **Mon Sep 19 17:28:08 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).




# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.106`
# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.107`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3859,12 +3859,12 @@ This report was generated on **Thu Sep 01 15:08:25 EEST 2022** using [Gradle-Lic

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

This report was generated on **Thu Sep 01 15:08:25 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 **Mon Sep 19 17:28:09 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).




# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.106`
# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.107`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -4535,12 +4535,12 @@ This report was generated on **Thu Sep 01 15:08:25 EEST 2022** using [Gradle-Lic

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

This report was generated on **Thu Sep 01 15:08:25 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 **Mon Sep 19 17:28:09 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).




# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.106`
# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.107`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -5256,4 +5256,4 @@ This report was generated on **Thu Sep 01 15:08:25 EEST 2022** using [Gradle-Lic

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

This report was generated on **Thu Sep 01 15:08:26 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 **Mon Sep 19 17:28:09 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).
6 changes: 3 additions & 3 deletions 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.106</version>
<version>2.0.0-SNAPSHOT.107</version>

<inceptionYear>2015</inceptionYear>

Expand Down Expand Up @@ -62,7 +62,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-base</artifactId>
<version>2.0.0-SNAPSHOT.95</version>
<version>2.0.0-SNAPSHOT.96</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -158,7 +158,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-testlib</artifactId>
<version>2.0.0-SNAPSHOT.95</version>
<version>2.0.0-SNAPSHOT.96</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
97 changes: 57 additions & 40 deletions server/src/main/java/io/spine/server/CommandService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

package io.spine.server;

import io.grpc.BindableService;
import io.grpc.stub.StreamObserver;
import io.spine.base.Error;
import io.spine.base.Errors;
Expand All @@ -36,34 +37,31 @@
import io.spine.server.commandbus.UnsupportedCommandException;
import io.spine.server.type.CommandClass;
import io.spine.type.MessageClass;
import io.spine.type.TypeUrl;
import io.spine.type.UnpublishedLanguageException;
import org.checkerframework.checker.nullness.qual.Nullable;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static io.spine.server.bus.MessageIdExtensions.causedError;
import static io.spine.type.MessageExtensions.isInternal;

/**
* The {@code CommandService} allows client applications to post commands and
* receive updates from the application backend.
* The service which accepts a command from a client application and posts it to
* a command bus of the bounded context which handles the command.
*/
public final class CommandService
extends CommandServiceGrpc.CommandServiceImplBase
implements Logging {

private final TypeDictionary types;
private final CommandServiceImpl impl;

/**
* Constructs new instance using the map from a {@code CommandClass} to
* a {@code BoundedContext} instance which handles the command.
*/
private CommandService(TypeDictionary types) {
super();
this.types = types;
}

private String simpleClassName() {
return getClass().getSimpleName();
this.impl = new CommandServiceImpl(this, types);
}

/**
Expand All @@ -83,41 +81,60 @@ public static CommandService withSingle(BoundedContext context) {
}

@Override
public void post(Command request, StreamObserver<Ack> responseObserver) {
var commandClass = CommandClass.of(request);
if (isInternal(commandClass.value())) {
handleInternal(request, responseObserver);
return;
}
var boundedContext = types.find(commandClass.typeUrl());
boundedContext.ifPresentOrElse(
ctx -> ctx.commandBus().post(request, responseObserver),
() -> handleUnsupported(request, responseObserver)
);
public void post(Command command, StreamObserver<Ack> observer) {
impl.serve(command, observer, null);
}

private void handleInternal(Command command, StreamObserver<Ack> responseObserver) {
var unpublishedLanguage = new UnpublishedLanguageException(command.enclosedMessage());
_error().withCause(unpublishedLanguage)
.log("Unpublished command posted to `%s`.", simpleClassName());
var error = Errors.fromThrowable(unpublishedLanguage);
respondWithError(command, error, responseObserver);
}
private static final class CommandServiceImpl extends ServiceDelegate<Command, Ack> {

private void handleUnsupported(Command command, StreamObserver<Ack> responseObserver) {
var unsupported = new UnsupportedCommandException(command);
_error().withCause(unsupported)
.log("Unsupported command posted to `%s`.", simpleClassName());
var error = unsupported.asError();
respondWithError(command, error, responseObserver);
}
CommandServiceImpl(BindableService service, TypeDictionary types) {
super(service, types);
}

private static
void respondWithError(Command command, Error error, StreamObserver<Ack> responseObserver) {
var id = command.getId();
var response = causedError(id, error);
responseObserver.onNext(response);
responseObserver.onCompleted();
@Override
protected TypeUrl enclosedMessageType(Command request) {
var type = CommandClass.of(request).typeUrl();
return type;
}

@Override
protected void serve(BoundedContext context,
Command cmd,
StreamObserver<Ack> observer,
@Nullable Object params) {
context.commandBus().post(cmd, observer);
}

@Override
protected void handleInternal(Command cmd, StreamObserver<Ack> observer) {
var unpublishedLanguage = new UnpublishedLanguageException(cmd.enclosedMessage());
_error().withCause(unpublishedLanguage)
.log("Unpublished command posted to `%s`.", serviceName());
var error = Errors.fromThrowable(unpublishedLanguage);
respondWithError(cmd, error, observer);
}

/**
* Since a command can be handled by only one bounded context, responds
* with the acknowledgement containing {@link UnsupportedCommandException}.
*/
@Override
protected void serveNoContext(Command cmd,
StreamObserver<Ack> observer,
@Nullable Object params) {
var unsupported = new UnsupportedCommandException(cmd);
_error().withCause(unsupported)
.log("Unsupported command posted to `%s`.", serviceName());
var error = unsupported.asError();
respondWithError(cmd, error, observer);
}

private static void respondWithError(Command cmd, Error err, StreamObserver<Ack> observer) {
var id = cmd.getId();
var response = causedError(id, err);
observer.onNext(response);
observer.onCompleted();
}
}

/**
Expand Down
Loading