Use the official RxJava to Reactive Streams adapter
This commit removes the usage of Reactor adapters (about to be moved from Reactor Core to a new Reactor Adapter module). Instead, RxReactiveStreams is now used for adapting RxJava 1 and Flowable methods are used for RxJava 2. Issue: SPR-14824
This commit is contained in:
@@ -26,12 +26,11 @@ import java.util.function.Predicate;
|
||||
import io.reactivex.BackpressureStrategy;
|
||||
import io.reactivex.Flowable;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.adapter.RxJava1Adapter;
|
||||
import reactor.adapter.RxJava2Adapter;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import rx.Completable;
|
||||
import rx.Observable;
|
||||
import rx.RxReactiveStreams;
|
||||
import rx.Single;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -51,6 +50,9 @@ public class ReactiveAdapterRegistry {
|
||||
private static final boolean rxJava1Present =
|
||||
ClassUtils.isPresent("rx.Observable", ReactiveAdapterRegistry.class.getClassLoader());
|
||||
|
||||
private static final boolean rxJava1Adapter =
|
||||
ClassUtils.isPresent("rx.RxReactiveStreams", ReactiveAdapterRegistry.class.getClassLoader());
|
||||
|
||||
private static final boolean rxJava2Present =
|
||||
ClassUtils.isPresent("io.reactivex.Flowable", ReactiveAdapterRegistry.class.getClassLoader());
|
||||
|
||||
@@ -75,7 +77,7 @@ public class ReactiveAdapterRegistry {
|
||||
new ReactiveAdapter.Descriptor(false, true, false)
|
||||
);
|
||||
|
||||
if (rxJava1Present) {
|
||||
if (rxJava1Present && rxJava1Adapter) {
|
||||
new RxJava1AdapterRegistrar().register(this);
|
||||
}
|
||||
if (rxJava2Present) {
|
||||
@@ -262,17 +264,17 @@ public class ReactiveAdapterRegistry {
|
||||
|
||||
public void register(ReactiveAdapterRegistry registry) {
|
||||
registry.registerFluxAdapter(Observable.class,
|
||||
source -> RxJava1Adapter.observableToFlux((Observable<?>) source),
|
||||
RxJava1Adapter::publisherToObservable
|
||||
source -> Flux.from(RxReactiveStreams.toPublisher((Observable<?>) source)),
|
||||
RxReactiveStreams::toObservable
|
||||
);
|
||||
registry.registerMonoAdapter(Single.class,
|
||||
source -> RxJava1Adapter.singleToMono((Single<?>) source),
|
||||
RxJava1Adapter::publisherToSingle,
|
||||
source -> Mono.from(RxReactiveStreams.toPublisher((Single<?>) source)),
|
||||
RxReactiveStreams::toSingle,
|
||||
new ReactiveAdapter.Descriptor(false, false, false)
|
||||
);
|
||||
registry.registerMonoAdapter(Completable.class,
|
||||
source -> RxJava1Adapter.completableToMono((Completable) source),
|
||||
RxJava1Adapter::publisherToCompletable,
|
||||
source -> Mono.from(RxReactiveStreams.toPublisher((Completable) source)),
|
||||
RxReactiveStreams::toCompletable,
|
||||
new ReactiveAdapter.Descriptor(false, true, true)
|
||||
);
|
||||
}
|
||||
@@ -282,21 +284,21 @@ public class ReactiveAdapterRegistry {
|
||||
|
||||
public void register(ReactiveAdapterRegistry registry) {
|
||||
registry.registerFluxAdapter(Flowable.class,
|
||||
source -> RxJava2Adapter.flowableToFlux((Flowable<?>) source),
|
||||
RxJava2Adapter::fluxToFlowable
|
||||
source -> Flux.from((Flowable<?>) source),
|
||||
source-> Flowable.fromPublisher(source)
|
||||
);
|
||||
registry.registerFluxAdapter(io.reactivex.Observable.class,
|
||||
source -> RxJava2Adapter.observableToFlux((io.reactivex.Observable<?>) source, BackpressureStrategy.BUFFER),
|
||||
RxJava2Adapter::fluxToObservable
|
||||
source -> Flux.from(((io.reactivex.Observable<?>) source).toFlowable(BackpressureStrategy.BUFFER)),
|
||||
source -> Flowable.fromPublisher(source).toObservable()
|
||||
);
|
||||
registry.registerMonoAdapter(io.reactivex.Single.class,
|
||||
source -> RxJava2Adapter.singleToMono((io.reactivex.Single<?>) source),
|
||||
RxJava2Adapter::monoToSingle,
|
||||
source -> Mono.from(((io.reactivex.Single<?>) source).toFlowable()),
|
||||
source -> Flowable.fromPublisher(source).toObservable().singleElement().toSingle(),
|
||||
new ReactiveAdapter.Descriptor(false, false, false)
|
||||
);
|
||||
registry.registerMonoAdapter(io.reactivex.Completable.class,
|
||||
source -> RxJava2Adapter.completableToMono((io.reactivex.Completable) source),
|
||||
RxJava2Adapter::monoToCompletable,
|
||||
source -> Mono.from(((io.reactivex.Completable) source).toFlowable()),
|
||||
source -> Flowable.fromPublisher(source).toObservable().ignoreElements(),
|
||||
new ReactiveAdapter.Descriptor(false, true, true)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user