-
Notifications
You must be signed in to change notification settings - Fork 937
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
Support RxJava 3 #2501
Support RxJava 3 #2501
Conversation
Motivation: Recently RxJava 3 has been released. https://github.com/ReactiveX/RxJava/releases/tag/v3.0.0 Armeria supports RxJava2 integration with `armeria-rxjava`. This PR migrates `RequestContextAssembly` from RxJava2 to RxJava3. RxJava 3 being based on Java 8 also supports seamless conversions between CompletionStage and Single, Maybe, Observable. Modifications: * Rename original `armeria-rxjava` to `armeria-rxjava2` * Make armeria-rxjava support RxJava 3 * Use built-in converter methods for ObservableResponseConverterFunction * Change `*Callable` to `*Supplier` ReactiveX/RxJava#6511 * Don't migrate `RequestContextScalarCallableCompletable` and `RequestContextCallableCompletable` There is no subclasses of `Completable` that implement `Supplier` * Delegate `reset()` in `ConnectableFlowable` https://github.com/ReactiveX/RxJava/wiki/What's-different-in-3.0#connectable-source-reset Result: You can now use RxJava 3 with Armeria. Fixes: line#2378
public T get() { | ||
try (SafeCloseable ignored = assemblyContext.push()) { | ||
return ((ScalarSupplier<T>) source).get(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of ScalarSupplier
, which was ScalarCallable
in RxJava 2, was captured when calling Maybe.just(T)
.
I wonder do we need to push RequestContext
here? If not, I think we could remove all RequestContextScalarSupplier*
. 🧐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't have to push the context here. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I think there a chance that a user specifies a class that extends Maybe
and implements ScalarSupplier
.
The specified class might need the context in get()
method, so I think we need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... ScalarSupplier
is the same as Supplier
except it abandons throws Throwable
. If a user triggers effects in get()
method, it seems a wrong usage of ScalarSupplier
. Because it should hold const and scalar value.
https://github.com/ReactiveX/RxJava/blob/3.x/src/main/java/io/reactivex/rxjava3/internal/fuseable/ScalarSupplier.java#L19
I think the user has to use Supplier
for generating a value dynamically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. That's a good point. 👍
Codecov Report
@@ Coverage Diff @@
## master #2501 +/- ##
============================================
- Coverage 72.98% 72.76% -0.22%
- Complexity 10841 10930 +89
============================================
Files 947 972 +25
Lines 41864 42310 +446
Branches 5182 5234 +52
============================================
+ Hits 30554 30788 +234
- Misses 8659 8852 +193
- Partials 2651 2670 +19 Continue to review full report at Codecov.
|
rxjava/src/main/java/com/linecorp/armeria/rxjava/RequestContextAssembly.java
Outdated
Show resolved
Hide resolved
rxjava/src/main/java/com/linecorp/armeria/rxjava/RequestContextAssembly.java
Outdated
Show resolved
Hide resolved
rxjava2/src/main/java/com/linecorp/armeria/server/rxjava2/package-info.java
Outdated
Show resolved
Hide resolved
rxjava/src/main/java/com/linecorp/armeria/internal/server/rxjava/package-info.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@SuppressWarnings("unchecked") | ||
@Override | ||
public T get() throws Throwable { | ||
try (SafeCloseable ignored = assemblyContext.push()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the comment above, do we need to remove here too? I still see some ScalarSupplier
has context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implements Supplier<T>
, not ScalarSupplier<T>
. So I think this is fine. 😀
Thanks a lot, @ikhoon ! |
Thanks for reviewing! 🙏 |
Motivation: Recently RxJava 3 has been released. https://github.com/ReactiveX/RxJava/releases/tag/v3.0.0 Armeria supports RxJava2 integration with `armeria-rxjava`. This PR migrates `RequestContextAssembly` from RxJava2 to RxJava3. RxJava 3 being based on Java 8 also supports seamless conversions between CompletionStage and Single, Maybe, Observable. Modifications: * Rename original `armeria-rxjava` to `armeria-rxjava2` * Make `armeria-rxjava` support RxJava 3 * Use built-in converter methods for ObservableResponseConverterFunction * Change `*Callable` to `*Supplier` ReactiveX/RxJava#6511 * Remove `assemblyContext.push()` in `RequestContextScalarCallable*.get()` * Don't need to push `RequestContext` for scalar type such as `Maybe.just(T)` * Delegate `reset()` method to `RequestContextConnectableFlowable`, `RequestContextConnectableObservable` https://github.com/ReactiveX/RxJava/wiki/What's-different-in-3.0#connectable-source-reset * Migrate `examples/context-propagation/rxjava` to RxJava 3 Result: You can now use RxJava 3 with Armeria. Fixes: line#2378
Motivation:
Recently RxJava 3 has been released.
https://github.com/ReactiveX/RxJava/releases/tag/v3.0.0
Armeria supports RxJava2 integration with
armeria-rxjava
.This PR migrates
RequestContextAssembly
from RxJava2 to RxJava3.RxJava 3 being based on Java 8 also supports seamless conversions between CompletionStage and Single, Maybe, Observable.
Modifications:
armeria-rxjava
toarmeria-rxjava2
armeria-rxjava
support RxJava 3*Callable
to*Supplier
3.x: Widen functional interface throws, replace Callable with Supplier ReactiveX/RxJava#6511
assemblyContext.push()
inRequestContextScalarCallable*.get()
RequestContext
for scalar type such asMaybe.just(T)
reset()
method toRequestContextConnectableFlowable
,RequestContextConnectableObservable
https://github.com/ReactiveX/RxJava/wiki/What's-different-in-3.0#connectable-source-reset
examples/context-propagation/rxjava
to RxJava 3Result:
You can now use RxJava 3 with Armeria.
Fixes: #2378