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

Allow subscribing on same rejection with different causes #1205

Merged
merged 29 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0f3da18
Add a new test case for multiple rejection subscriptions
yuri-sergiichuk Nov 27, 2019
9f2d292
Extract dispatch key creation logic into a helper utility class.
yuri-sergiichuk Nov 27, 2019
60e8fc4
Use the new rejection dispatch key in EventSubscriberMethod.
yuri-sergiichuk Nov 27, 2019
a1d292c
add stub test
yuri-sergiichuk Nov 27, 2019
97106ee
Add tests
yuri-sergiichuk Nov 28, 2019
6467617
Do not rely on declared methods.
yuri-sergiichuk Nov 28, 2019
81eb66a
Update report
yuri-sergiichuk Nov 28, 2019
7d55e76
Bump version
yuri-sergiichuk Nov 28, 2019
ef6b3ab
Use `isExternal` shortcut method
yuri-sergiichuk Nov 29, 2019
1d88a71
Add parameters to the exception message
yuri-sergiichuk Nov 29, 2019
405aef4
Rename RejectionDispatchKey to RejectionDispatchKeys
yuri-sergiichuk Nov 29, 2019
4da885b
Add backticks to the test name
yuri-sergiichuk Nov 29, 2019
c67f622
Mark `applyFilter` as `@Internal`
yuri-sergiichuk Nov 29, 2019
472baf2
Move subscriber to the given package
yuri-sergiichuk Nov 29, 2019
7126489
Use static import for the `findMethodsBy`
yuri-sergiichuk Nov 29, 2019
c040293
refine the test name
yuri-sergiichuk Nov 29, 2019
18a723e
Merge remote-tracking branch 'origin/master' into fix-1202
yuri-sergiichuk Dec 2, 2019
ca718a7
Update server/src/main/java/io/spine/server/event/model/RejectionDisp…
yuri-sergiichuk Dec 2, 2019
2e0ed0b
Merge remote-tracking branch 'origin/fix-1202' into fix-1202
yuri-sergiichuk Dec 2, 2019
0ec2a66
Upgrade v6.0.1
yuri-sergiichuk Dec 2, 2019
7363667
Inline class cast and add method name to the class cast check
yuri-sergiichuk Dec 2, 2019
c57b198
Bump version
yuri-sergiichuk Dec 2, 2019
ed7537f
Introduce RejectionHandler abstraction
yuri-sergiichuk Dec 3, 2019
3c3fa43
Update report
yuri-sergiichuk Dec 3, 2019
9380bc2
Add backticks to the class name
yuri-sergiichuk Dec 3, 2019
256236b
Cleanup docs
yuri-sergiichuk Dec 3, 2019
454add5
Remove annotation as it is not possible to actually call `super` for …
yuri-sergiichuk Dec 3, 2019
2ab3a50
Merge remote-tracking branch 'origin/master' into fix-1202
yuri-sergiichuk Dec 4, 2019
5d19827
Bump versions
yuri-sergiichuk Dec 4, 2019
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
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
29 changes: 12 additions & 17 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -175,14 +175,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
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.2.7`
# Dependencies of `io.spine:spine-client:1.2.8`

## Runtime
1. **Group:** com.google.api.grpc **Name:** proto-google-common-protos **Version:** 1.12.0
Expand Down Expand Up @@ -381,12 +381,12 @@
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Dec 03 17:19:27 EET 2019** 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 **Wed Dec 04 11:20:30 EET 2019** 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.2.7`
# Dependencies of `io.spine:spine-core:1.2.8`

## Runtime
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
Expand Down Expand Up @@ -743,12 +743,12 @@ This report was generated on **Tue Dec 03 17:19:27 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Dec 03 17:19:27 EET 2019** 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 **Wed Dec 04 11:20:30 EET 2019** 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.2.7`
# Dependencies of `io.spine.tools:spine-model-assembler:1.2.8`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -1144,12 +1144,12 @@ This report was generated on **Tue Dec 03 17:19:27 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Dec 03 17:19:28 EET 2019** 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 **Wed Dec 04 11:20:31 EET 2019** 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.2.7`
# Dependencies of `io.spine.tools:spine-model-verifier:1.2.8`

## Runtime
1. **Group:** aopalliance **Name:** aopalliance **Version:** 1.0
Expand Down Expand Up @@ -1699,12 +1699,12 @@ This report was generated on **Tue Dec 03 17:19:28 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Dec 03 17:19:29 EET 2019** 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 **Wed Dec 04 11:20:31 EET 2019** 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.2.7`
# Dependencies of `io.spine:spine-server:1.2.8`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -2117,12 +2117,12 @@ This report was generated on **Tue Dec 03 17:19:29 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Dec 03 17:19:29 EET 2019** 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 **Wed Dec 04 11:20:32 EET 2019** 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.2.7`
# Dependencies of `io.spine:spine-testutil-client:1.2.8`

## Runtime
1. **Group:** com.google.api.grpc **Name:** proto-google-common-protos **Version:** 1.12.0
Expand Down Expand Up @@ -2536,12 +2536,12 @@ This report was generated on **Tue Dec 03 17:19:29 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Dec 03 17:19:30 EET 2019** 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 **Wed Dec 04 11:20:32 EET 2019** 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.2.7`
# Dependencies of `io.spine:spine-testutil-core:1.2.8`

## Runtime
1. **Group:** com.google.api.grpc **Name:** proto-google-common-protos **Version:** 1.12.0
Expand Down Expand Up @@ -2963,12 +2963,12 @@ This report was generated on **Tue Dec 03 17:19:30 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Dec 03 17:19:30 EET 2019** 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 **Wed Dec 04 11:20:32 EET 2019** 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.2.7`
# Dependencies of `io.spine:spine-testutil-server:1.2.8`

## Runtime
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
Expand Down Expand Up @@ -3466,4 +3466,4 @@ This report was generated on **Tue Dec 03 17:19:30 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Tue Dec 03 17:19:31 EET 2019** 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 **Wed Dec 04 11:20:33 EET 2019** 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.2.7</version>
<version>1.2.8</version>

<inceptionYear>2015</inceptionYear>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,17 @@

package io.spine.server.event.model;

import com.google.protobuf.Message;
import io.spine.base.CommandMessage;
import io.spine.base.EventMessage;
import io.spine.server.model.AbstractHandlerMethod;
import io.spine.server.model.DispatchKey;
import io.spine.server.model.MethodParams;
import io.spine.server.model.ParameterSpec;
import io.spine.server.type.CommandClass;
import io.spine.server.type.EventClass;
import io.spine.server.type.EventEnvelope;
import io.spine.type.MessageClass;

import java.lang.reflect.Method;

import static com.google.common.base.Preconditions.checkArgument;

/**
* An abstract base for methods handling events.
*
Expand All @@ -45,52 +40,38 @@
* the type of the produced message classes
*/
public abstract class EventHandlerMethod<T, R extends MessageClass<?>>
extends AbstractHandlerMethod<T, EventMessage, EventClass, EventEnvelope, R> {
extends AbstractHandlerMethod<T, EventMessage, EventClass, EventEnvelope, R>
implements RejectionHandler<T, R> {

/**
* Creates a new instance to wrap {@code method} on {@code target}.
*
* @param method subscriber method
* @param method
* subscriber method
*/
EventHandlerMethod(Method method, ParameterSpec<EventEnvelope> parameterSpec) {
super(method, parameterSpec);
}

@Override
protected EventAcceptingMethodParams parameterSpec() {
public EventAcceptingMethodParams parameterSpec() {
return (EventAcceptingMethodParams) super.parameterSpec();
}

@Override
public DispatchKey key() {
EventClass eventClass = messageClass();
if (parameterSpec().acceptsCommand()) {
Class<?>[] parameters = rawMethod().getParameterTypes();
Class<? extends CommandMessage> commandMessageClass =
castClass(parameters[1], CommandMessage.class);
CommandClass commandClass = CommandClass.from(commandMessageClass);
return new DispatchKey(eventClass.value(), null, commandClass.value());
} else {
return super.key();
}
return RejectionHandler.super.key();
}

@Override
public MethodParams params() {
if (parameterSpec().acceptsCommand()) {
if (RejectionHandler.super.handlesRejection()) {
MethodParams result = MethodParams.of(rawMethod());
return result;
}
return super.params();
}

private static <T extends Message> Class<T> castClass(Class<?> raw, Class<T> targetBound) {
checkArgument(targetBound.isAssignableFrom(raw));
@SuppressWarnings("unchecked") // Checked above.
Class<T> result = (Class<T>) raw;
return result;
}

/**
* Ensures that the passed event matches the {@code external} attribute
* of the method annotation.
Expand All @@ -111,5 +92,4 @@ protected void checkAttributesMatch(EventEnvelope event) {
.getExternal();
ensureExternalMatch(external);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
package io.spine.server.event.model;

import com.google.errorprone.annotations.Immutable;
import io.spine.server.event.EventSubscriber;
import io.spine.server.model.ArgumentFilter;
import io.spine.server.model.DispatchKey;
import io.spine.server.model.ParameterSpec;
import io.spine.server.type.EmptyClass;
import io.spine.server.type.EventEnvelope;

import java.lang.reflect.Method;
Expand All @@ -31,13 +34,25 @@
* A wrapper for an event subscriber method.
*/
@Immutable
public final class EventSubscriberMethod extends SubscriberMethod {
public final class EventSubscriberMethod extends SubscriberMethod
implements RejectionHandler<EventSubscriber, EmptyClass> {

/** Creates a new instance. */
EventSubscriberMethod(Method method, ParameterSpec<EventEnvelope> parameterSpec) {
super(method, parameterSpec);
}

@Override
public EventAcceptingMethodParams parameterSpec() {
return (EventAcceptingMethodParams) super.parameterSpec();
}

@Override
public DispatchKey key() {
DispatchKey dispatchKey = RejectionHandler.super.key();
return applyFilter(dispatchKey);
}

@Override
public ArgumentFilter createFilter() {
ArgumentFilter result = ArgumentFilter.createFilter(rawMethod());
Expand All @@ -47,6 +62,6 @@ public ArgumentFilter createFilter() {
@Override
protected void checkAttributesMatch(EventEnvelope event) throws IllegalArgumentException {
super.checkAttributesMatch(event);
ensureExternalMatch(event.context().getExternal());
ensureExternalMatch(event.isExternal());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2019, TeamDev. All rights reserved.
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.server.event.model;

import io.spine.base.CommandMessage;
import io.spine.server.model.DispatchKey;
import io.spine.server.type.CommandClass;
import io.spine.server.type.EventClass;

import java.lang.reflect.Method;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

/**
* A helper utility class that allows creating {@link DispatchKey}s for rejection handling methods.
*/
final class RejectionDispatchKeys {

/** Prevents instantiation of this utility class. **/
private RejectionDispatchKeys() {
}

/**
* Creates a new {@code DispatchKey} for a rejection handling method that accepts commands as
* a second parameter.
*
* @implSpec the developer is responsible for verifying that the method actually has a
* {@code CommandClass} type as a second parameter.
*/
static DispatchKey of(EventClass eventClass, Method rawMethod) {
checkNotNull(eventClass);
checkNotNull(rawMethod);
Class<?>[] parameters = rawMethod.getParameterTypes();
String methodName = rawMethod.getName();
checkArgument(parameters.length >= 2,
"The method `%s` should have at least 2 parameters, but has `%s`.",
methodName,
parameters.length);
Class<?> secondParameter = parameters[1];
checkArgument(CommandMessage.class.isAssignableFrom(secondParameter),
"The method `%s` should have the second parameter assignable from `CommandMessage`, but has `%s`.",
methodName,
secondParameter);
@SuppressWarnings("unchecked") // checked above
Class<? extends CommandMessage> commandMessageClass =
(Class<? extends CommandMessage>) secondParameter;
CommandClass commandClass = CommandClass.from(commandMessageClass);
return new DispatchKey(eventClass.value(), null, commandClass.value());
}
}
Loading