Class Publishers
- java.lang.Object
-
- io.micronaut.core.async.publisher.Publishers
-
@Internal public class Publishers extends java.lang.ObjectUtilities for working with rawPublisherinstances. Designed for internal use by Micronaut and not as a replacement for a reactive library such as RxJava, Reactor, Akka etc.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPublishers.JustPublisher<T>A publisher for a value.static interfacePublishers.MapOrSupplyEmpty<T,R>Maps the next result or supplies an empty result.static interfacePublishers.MicronautPublisher<T>Marker interface for any micronaut produced publishers.
-
Constructor Summary
Constructors Constructor Description Publishers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TconvertPublisher(java.lang.Object object, java.lang.Class<T> publisherType)Attempts to convert the publisher to the given type.static <T> org.reactivestreams.Publisher<T>empty()APublisherthat completes without emitting any items.static <T> org.reactivestreams.Publisher<T>fromCompletableFuture(java.util.concurrent.CompletableFuture<T> future)Build aPublisherfrom aCompletableFuture.static <T> org.reactivestreams.Publisher<T>fromCompletableFuture(java.util.function.Supplier<java.util.concurrent.CompletableFuture<T>> futureSupplier)Build aPublisherfrom aCompletableFuture.static java.util.List<java.lang.Class<?>>getKnownCompletableTypes()static java.util.List<java.lang.Class<?>>getKnownReactiveTypes()static java.util.List<java.lang.Class<?>>getKnownSingleTypes()static booleanisCompletable(java.lang.Class<?> type)Does the given reactive type emit a single result.static booleanisConvertibleToPublisher(java.lang.Class<?> type)Is the given type a Publisher or convertible to a publisher.static booleanisConvertibleToPublisher(java.lang.Object object)Is the given object a Publisher or convertible to a publisher.static booleanisSingle(java.lang.Class<?> type)Does the given reactive type emit a single result.static <T> org.reactivestreams.Publisher<T>just(java.lang.Throwable error)APublisherthat emits a fixed single value.static <T> org.reactivestreams.Publisher<T>just(T value)APublisherthat emits a fixed single value.static <T,R>
org.reactivestreams.Publisher<R>map(org.reactivestreams.Publisher<T> publisher, java.util.function.Function<T,R> mapper)Map the result from a publisher using the given mapper.static <T,R>
org.reactivestreams.Publisher<R>mapOrSupplyEmpty(org.reactivestreams.Publisher<T> publisher, Publishers.MapOrSupplyEmpty<T,R> mapOrSupplyEmpty)Map the result from a publisher using the given mapper or supply empty value.static <T> org.reactivestreams.Publisher<T>onComplete(org.reactivestreams.Publisher<T> publisher, java.util.function.Supplier<java.util.concurrent.CompletableFuture<java.lang.Void>> future)Allow executing logic on completion of a Publisher.static voidregisterReactiveCompletable(java.lang.Class<?> type)Registers an additional reactive completable type.static voidregisterReactiveSingle(java.lang.Class<?> type)Registers an additional reactive single type.static voidregisterReactiveType(java.lang.Class<?> type)Registers an additional reactive type.static <T> org.reactivestreams.Publisher<T>then(org.reactivestreams.Publisher<T> publisher, java.util.function.Consumer<T> consumer)Map the result from a publisher using the given mapper.
-
-
-
Method Detail
-
registerReactiveType
public static void registerReactiveType(java.lang.Class<?> type)
Registers an additional reactive type. Should be called during application static initialization.- Parameters:
type- The type- Since:
- 2.0
-
registerReactiveSingle
public static void registerReactiveSingle(java.lang.Class<?> type)
Registers an additional reactive single type. Should be called during application static initialization.- Parameters:
type- The type- Since:
- 2.0
-
registerReactiveCompletable
public static void registerReactiveCompletable(java.lang.Class<?> type)
Registers an additional reactive completable type. Should be called during application static initialization.- Parameters:
type- The type- Since:
- 2.0
-
getKnownReactiveTypes
public static java.util.List<java.lang.Class<?>> getKnownReactiveTypes()
- Returns:
- A list of known reactive types.
-
getKnownSingleTypes
public static java.util.List<java.lang.Class<?>> getKnownSingleTypes()
- Returns:
- A list of known single types.
-
getKnownCompletableTypes
public static java.util.List<java.lang.Class<?>> getKnownCompletableTypes()
- Returns:
- A list of known single types.
-
fromCompletableFuture
public static <T> org.reactivestreams.Publisher<T> fromCompletableFuture(java.util.function.Supplier<java.util.concurrent.CompletableFuture<T>> futureSupplier)
Build aPublisherfrom aCompletableFuture.- Type Parameters:
T- The type of the publisher- Parameters:
futureSupplier- The supplier of theCompletableFuture- Returns:
- The
Publisher
-
fromCompletableFuture
public static <T> org.reactivestreams.Publisher<T> fromCompletableFuture(java.util.concurrent.CompletableFuture<T> future)
Build aPublisherfrom aCompletableFuture.- Type Parameters:
T- The type of the publisher- Parameters:
future- TheCompletableFuture- Returns:
- The
Publisher
-
just
public static <T> org.reactivestreams.Publisher<T> just(T value)
APublisherthat emits a fixed single value.- Type Parameters:
T- The value type- Parameters:
value- The value to emit- Returns:
- The
Publisher
-
just
public static <T> org.reactivestreams.Publisher<T> just(java.lang.Throwable error)
APublisherthat emits a fixed single value.- Type Parameters:
T- The value type- Parameters:
error- The error to emit- Returns:
- The
Publisher
-
empty
public static <T> org.reactivestreams.Publisher<T> empty()
APublisherthat completes without emitting any items.- Type Parameters:
T- The value type- Returns:
- The
Publisher - Since:
- 2.0.0
-
map
public static <T,R> org.reactivestreams.Publisher<R> map(org.reactivestreams.Publisher<T> publisher, java.util.function.Function<T,R> mapper)Map the result from a publisher using the given mapper.- Type Parameters:
T- The generic typeR- The result type- Parameters:
publisher- The publishermapper- The mapper- Returns:
- The mapped publisher
-
mapOrSupplyEmpty
public static <T,R> org.reactivestreams.Publisher<R> mapOrSupplyEmpty(org.reactivestreams.Publisher<T> publisher, Publishers.MapOrSupplyEmpty<T,R> mapOrSupplyEmpty)Map the result from a publisher using the given mapper or supply empty value.- Type Parameters:
T- The generic typeR- The result type- Parameters:
publisher- The publishermapOrSupplyEmpty- The mapOrSupplyEmpty- Returns:
- The mapped publisher
- Since:
- 2.5.0
-
then
public static <T> org.reactivestreams.Publisher<T> then(org.reactivestreams.Publisher<T> publisher, java.util.function.Consumer<T> consumer)Map the result from a publisher using the given mapper.- Type Parameters:
T- The generic type- Parameters:
publisher- The publisherconsumer- The mapper- Returns:
- The mapped publisher
-
onComplete
public static <T> org.reactivestreams.Publisher<T> onComplete(org.reactivestreams.Publisher<T> publisher, java.util.function.Supplier<java.util.concurrent.CompletableFuture<java.lang.Void>> future)Allow executing logic on completion of a Publisher.- Type Parameters:
T- The generic type- Parameters:
publisher- The publisherfuture- The runnable- Returns:
- The mapped publisher
-
isConvertibleToPublisher
public static boolean isConvertibleToPublisher(java.lang.Class<?> type)
Is the given type a Publisher or convertible to a publisher.- Parameters:
type- The type to check- Returns:
- True if it is
-
isConvertibleToPublisher
public static boolean isConvertibleToPublisher(java.lang.Object object)
Is the given object a Publisher or convertible to a publisher.- Parameters:
object- The object- Returns:
- True if it is
-
convertPublisher
public static <T> T convertPublisher(java.lang.Object object, java.lang.Class<T> publisherType)Attempts to convert the publisher to the given type.- Type Parameters:
T- The generic type- Parameters:
object- The object to convertpublisherType- The publisher type- Returns:
- The Resulting in publisher
-
isSingle
public static boolean isSingle(java.lang.Class<?> type)
Does the given reactive type emit a single result.- Parameters:
type- The type- Returns:
- True it does
-
isCompletable
public static boolean isCompletable(java.lang.Class<?> type)
Does the given reactive type emit a single result.- Parameters:
type- The type- Returns:
- True it does
-
-