Add Smallrye Mutiny support.

Closes #2471
This commit is contained in:
hantsy
2021-09-28 16:06:59 +08:00
committed by Mark Paluch
parent 03de5995c7
commit d18275770c
5 changed files with 73 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ package org.springframework.data.repository.util;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import kotlinx.coroutines.flow.Flow;
import kotlinx.coroutines.flow.FlowKt;
import kotlinx.coroutines.reactive.ReactiveFlowKt;
@@ -104,6 +106,11 @@ public abstract class ReactiveWrapperConverters {
REACTIVE_WRAPPERS.add(FlowWrapper.INSTANCE);
}
if (ReactiveWrappers.isAvailable(ReactiveLibrary.MUTINY)) {
REACTIVE_WRAPPERS.add(UniWrapper.INSTANCE);
REACTIVE_WRAPPERS.add(MultiWrapper.INSTANCE);
}
registerConvertersIn(GENERIC_CONVERSION_SERVICE);
}
@@ -527,6 +534,43 @@ public abstract class ReactiveWrapperConverters {
}
}
/**
* Wrapper for SmallRye Mutiny's {@link io.smallrye.mutiny.Uni}.
*/
private enum UniWrapper implements ReactiveTypeWrapper<io.smallrye.mutiny.Uni<?>> {
INSTANCE;
@Override
public Class<? super io.smallrye.mutiny.Uni<?>> getWrapperClass() {
return io.smallrye.mutiny.Uni.class;
}
@Override
public io.smallrye.mutiny.Uni<?> map(Object wrapper, Function<Object, Object> function) {
return ((io.smallrye.mutiny.Uni<?>) wrapper).map(function::apply);
}
}
/**
* Wrapper for SmallRye Mutiny's {@link io.smallrye.mutiny.Multi}.
*/
private enum MultiWrapper implements ReactiveTypeWrapper<io.smallrye.mutiny.Multi<?>> {
INSTANCE;
@Override
public Class<? super io.smallrye.mutiny.Multi<?>> getWrapperClass() {
return io.smallrye.mutiny.Multi.class;
}
@Override
public io.smallrye.mutiny.Multi<?> map(Object wrapper, Function<Object, Object> function) {
return ((io.smallrye.mutiny.Multi<?>) wrapper).map(function::apply);
}
}
// -------------------------------------------------------------------------
// ReactiveStreams converters
// -------------------------------------------------------------------------

View File

@@ -83,6 +83,9 @@ public abstract class ReactiveWrappers {
private static final boolean KOTLIN_COROUTINES_PRESENT = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt",
ReactiveWrappers.class.getClassLoader());
private static final boolean MUTINY_PRESENT = ClassUtils.isPresent("io.smallrye.mutiny.Multi",
ReactiveWrappers.class.getClassLoader());
private ReactiveWrappers() {}
/**
@@ -104,7 +107,7 @@ public abstract class ReactiveWrappers {
* @deprecated since 2.6, use RxJava 3 instead. To be removed with Spring Data 3.0.
*/
@Deprecated
RXJAVA2, RXJAVA3, KOTLIN_COROUTINES;
RXJAVA2, RXJAVA3, KOTLIN_COROUTINES, MUTINY;
}
/**
@@ -138,6 +141,8 @@ public abstract class ReactiveWrappers {
return RXJAVA3_PRESENT;
case KOTLIN_COROUTINES:
return PROJECT_REACTOR_PRESENT && KOTLIN_COROUTINES_PRESENT;
case MUTINY:
return MUTINY_PRESENT;
default:
throw new IllegalArgumentException(String.format("Reactive library %s not supported", reactiveLibrary));
}