users@jax-rs-spec.java.net

[jax-rs-spec users] Suggestion to refactor rx invoker API

From: Ondrej Mihályi <ondrej.mihalyi_at_gmail.com>
Date: Sat, 14 Jan 2017 12:54:12 +0100

I was thinking about an alternative to current rx API, to simplify it in
context of supporting extensibility.

My idea is to modify the CompletionStageRxInvoker, so that it returns an
extension to CompletionStage, which would contain additional method to
convert the interface to any other reactive interface:

public interface RxCompletionStage<T> extends CompletionStage<T> {
    <NEW> NEW convert(Function<CompletionStage<T>, NEW> converter);
}

With this, we would move all the complexity to this new interface, which
still can be used as a usual CompletionStage, but with the additional
convert method, it provides an extension point to other interfaces. And
it's based on standard CompletionStage, therefore we don't need additional
rx invokers.

We could remove RxInvokerProvider, the 2 rx() methods from the Builder,
which accept RxInvokerProvider, and even remove the RxInvoker interface, as
CompletionStageRxInvoker would be the only required implementation.

Here is an example of what I mean, with RxJava2 as an example:

client.request().rx().get(). // we get the RxCompletionStage here,
which extends CompletionStage
    .convert(this::flowableFromStage) // accepts a function that
converts the CompletionStage to another interface
    .subscribe(s -> testResult = s, Throwable::printStackTrace);

An example of a working code here
<https://github.com/OndrejM-demonstrations/JavaEEReactive/blob/rxjava/src/test/java/reactivejavaee/CompletionStageRxJavaTest.java#L120>
(although not using JAX-RS, just wrapping a method that returns a
CompletionStage).

Ondrej