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

From: Ondrej Mihályi <>
Date: Tue, 17 Jan 2017 18:14:38 +0100

In fact, on second thought, it's not true we have to have CompletableFuture
in the chain at all. The CompletionStage is an interface, which can
implement the ability to convert to use any provider. The provider doesn't
have to use the CompletionStage at all, we can go deeper and let it
implement a custom InvocationCallback instead.

I just wanted to make it simple. But if you want to bypass CompletionStage,
imagine this (I slightly modified my original proposal):

client.request().rx().get(). // we get the RxCompletionStage here,
which extends CompletionStage
    .unwrap(this::provideInvocationCallbackAndRxFlowable) // accepts
a producer function, which returns an InvocationCallback AND Flowable,
which will be the result of the unwrap method (the 2 return values
wrapped in a new container interface)
    .subscribe(s -> testResult = s, Throwable::printStackTrace);

with these definitions:

UNWRAPPED>> unwrapperProvider);


interface Unwrapper<RESPONSE_TYPE, UNWRAPPED> {

   InvocationCallback<RESPONSE_TYPE> getCallback();

   UNWRAPPED getUnwrapped();


The producer passed to unwrap() would just need to implement the callback,
which forwards to the new UNWRAPPED instance (e.g. Flowable in RxJava2).

The invocation callback can be execute mutiple times, making it possible to
send multiple events (unlike using CompletionStage), but I don't think that
makes sense in REST client.

Do you think this could work? Should I try to elaborate further and provide
a working example?


2017-01-17 17:20 GMT+01:00 Santiago Pericasgeertsen <>:

> On Jan 15, 2017, at 1:37 PM, Pavel Bucek <> wrote:
> I guess the second quiestion is almost reduced to the first one - do we
> really want to have CompletableFuture ALWAYS in the chain? (or to be more
> on point - do we want to create JaxRsCompletableFuture and use that as an
> "rx extension point"?)
> This is the biggest issue with this proposal, it’s just delegation to
> CompletionStage, always. This is not the same as the RxInvoker proposal, in
> which other Rx library can be “natively” integrated.
> This is a showstopper for me, so -1.
> — Santiago