Class Publishers
- java.lang.Object
-
- io.micronaut.core.async.publisher.Publishers
-
@Internal public class Publishers extends java.lang.Object
Utilities for working with rawPublisher
instances. 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 class
Publishers.JustPublisher<T>
A publisher for a value.static interface
Publishers.MapOrSupplyEmpty<T,R>
Maps the next result or supplies an empty result.static interface
Publishers.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> T
convertPublisher(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()
APublisher
that completes without emitting any items.static <T> org.reactivestreams.Publisher<T>
fromCompletableFuture(java.util.concurrent.CompletableFuture<T> future)
Build aPublisher
from aCompletableFuture
.static <T> org.reactivestreams.Publisher<T>
fromCompletableFuture(java.util.function.Supplier<java.util.concurrent.CompletableFuture<T>> futureSupplier)
Build aPublisher
from 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 boolean
isCompletable(java.lang.Class<?> type)
Does the given reactive type emit a single result.static boolean
isConvertibleToPublisher(java.lang.Class<?> type)
Is the given type a Publisher or convertible to a publisher.static boolean
isConvertibleToPublisher(java.lang.Object object)
Is the given object a Publisher or convertible to a publisher.static boolean
isSingle(java.lang.Class<?> type)
Does the given reactive type emit a single result.static <T> org.reactivestreams.Publisher<T>
just(java.lang.Throwable error)
APublisher
that emits a fixed single value.static <T> org.reactivestreams.Publisher<T>
just(T value)
APublisher
that 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 void
registerReactiveCompletable(java.lang.Class<?> type)
Registers an additional reactive completable type.static void
registerReactiveSingle(java.lang.Class<?> type)
Registers an additional reactive single type.static void
registerReactiveType(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 aPublisher
from 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 aPublisher
from 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)
APublisher
that 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)
APublisher
that 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()
APublisher
that 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
-
-