Add support for RxJava 2
This commit adds support for RxJava 2 Completable, Single, Observable and Flowable types (io.reactivex package). Issue: SPR-14628
This commit is contained in:
@@ -23,8 +23,11 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
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;
|
||||
@@ -48,6 +51,9 @@ public class ReactiveAdapterRegistry {
|
||||
private static final boolean rxJava1Present =
|
||||
ClassUtils.isPresent("rx.Observable", ReactiveAdapterRegistry.class.getClassLoader());
|
||||
|
||||
private static final boolean rxJava2Present =
|
||||
ClassUtils.isPresent("io.reactivex.Flowable", ReactiveAdapterRegistry.class.getClassLoader());
|
||||
|
||||
private final Map<Class<?>, ReactiveAdapter> adapterMap = new LinkedHashMap<>(4);
|
||||
|
||||
|
||||
@@ -72,6 +78,9 @@ public class ReactiveAdapterRegistry {
|
||||
if (rxJava1Present) {
|
||||
new RxJava1AdapterRegistrar().register(this);
|
||||
}
|
||||
if (rxJava2Present) {
|
||||
new RxJava2AdapterRegistrar().register(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -269,4 +278,28 @@ public class ReactiveAdapterRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
private static class RxJava2AdapterRegistrar {
|
||||
|
||||
public void register(ReactiveAdapterRegistry registry) {
|
||||
registry.registerFluxAdapter(Flowable.class,
|
||||
source -> RxJava2Adapter.flowableToFlux((Flowable<?>) source),
|
||||
RxJava2Adapter::fluxToFlowable
|
||||
);
|
||||
registry.registerFluxAdapter(io.reactivex.Observable.class,
|
||||
source -> RxJava2Adapter.observableToFlux((io.reactivex.Observable<?>) source, BackpressureStrategy.BUFFER),
|
||||
RxJava2Adapter::fluxToObservable
|
||||
);
|
||||
registry.registerMonoAdapter(io.reactivex.Single.class,
|
||||
source -> RxJava2Adapter.singleToMono((io.reactivex.Single<?>) source),
|
||||
RxJava2Adapter::monoToSingle,
|
||||
new ReactiveAdapter.Descriptor(false, false, false)
|
||||
);
|
||||
registry.registerMonoAdapter(io.reactivex.Completable.class,
|
||||
source -> RxJava2Adapter.completableToMono((io.reactivex.Completable) source),
|
||||
RxJava2Adapter::monoToCompletable,
|
||||
new ReactiveAdapter.Descriptor(false, true, true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user