Class Publishers
java.lang.Object
io.micronaut.core.async.publisher.Publishers
Utilities for working with raw
Publisher
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
- Author:
- Graeme Rocher
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A publisher for a value.static class
A publisher that throws an error.static interface
Maps the next result or supplies an empty result.static interface
Marker interface for any micronaut produced publishers. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
convertPublisher
(ConversionService conversionService, Object object, Class<T> publisherType) Attempts to convert the publisher to the given type.static <T> T
convertPublisher
(Object object, Class<T> publisherType) Deprecated, for removal: This API element is subject to removal in a future version.static <T> Publisher<T>
empty()
APublisher
that completes without emitting any items.static <T> Publisher<T>
fromCompletableFuture
(CompletableFuture<T> future) Build aPublisher
from aCompletableFuture
.static <T> Publisher<T>
fromCompletableFuture
(Supplier<CompletableFuture<T>> futureSupplier) Build aPublisher
from aCompletableFuture
.static boolean
isCompletable
(Class<?> type) Does the given reactive type emit a single result.static boolean
isConvertibleToPublisher
(Class<?> type) Is the given type a Publisher or convertible to a publisher.static boolean
isConvertibleToPublisher
(Object object) Is the given object a Publisher or convertible to a publisher.static boolean
Does the given reactive type emit a single result.static <T> Publisher<T>
APublisher
that emits a fixed single value.static <T> Publisher<T>
just
(T value) APublisher
that emits a fixed single value.static <T,
R> Publisher<R> Map the result from a publisher using the given mapper.static <T,
R> Publisher<R> mapOrSupplyEmpty
(Publisher<T> publisher, Publishers.MapOrSupplyEmpty<T, R> mapOrSupplyEmpty) Map the result from a publisher using the given mapper or supply empty value.static <T> Publisher<T>
onComplete
(Publisher<T> publisher, Supplier<CompletableFuture<Void>> future) Allow executing logic on completion of a Publisher.static void
registerReactiveCompletable
(Class<?> type) Registers an additional reactive completable type.static void
registerReactiveSingle
(Class<?> type) Registers an additional reactive single type.static void
registerReactiveType
(Class<?> type) Registers an additional reactive type.static <T> Publisher<T>
Map the result from a publisher using the given mapper.
-
Constructor Details
-
Publishers
public Publishers()
-
-
Method Details
-
getReactiveTypeNames
-
registerReactiveType
Registers an additional reactive type. Should be called during application static initialization.- Parameters:
type
- The type- Since:
- 2.0
-
registerReactiveSingle
Registers an additional reactive single type. Should be called during application static initialization.- Parameters:
type
- The type- Since:
- 2.0
-
registerReactiveCompletable
Registers an additional reactive completable type. Should be called during application static initialization.- Parameters:
type
- The type- Since:
- 2.0
-
getKnownReactiveTypes
- Returns:
- A list of known reactive types.
-
getKnownSingleTypes
- Returns:
- A list of known single types.
-
getKnownCompletableTypes
- Returns:
- A list of known single types.
-
fromCompletableFuture
Build aPublisher
from aCompletableFuture
.- Type Parameters:
T
- The type of the publisher- Parameters:
futureSupplier
- The supplier of theCompletableFuture
- Returns:
- The
Publisher
-
fromCompletableFuture
Build aPublisher
from aCompletableFuture
.- Type Parameters:
T
- The type of the publisher- Parameters:
future
- TheCompletableFuture
- Returns:
- The
Publisher
-
just
APublisher
that emits a fixed single value.- Type Parameters:
T
- The value type- Parameters:
value
- The value to emit- Returns:
- The
Publisher
-
just
APublisher
that emits a fixed single value.- Type Parameters:
T
- The value type- Parameters:
error
- The error to emit- Returns:
- The
Publisher
-
empty
APublisher
that completes without emitting any items.- Type Parameters:
T
- The value type- Returns:
- The
Publisher
- Since:
- 2.0.0
-
map
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> Publisher<R> mapOrSupplyEmpty(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
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> Publisher<T> onComplete(Publisher<T> publisher, Supplier<CompletableFuture<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
Is the given type a Publisher or convertible to a publisher.- Parameters:
type
- The type to check- Returns:
- True if it is
-
isConvertibleToPublisher
Is the given object a Publisher or convertible to a publisher.- Parameters:
object
- The object- Returns:
- True if it is
-
convertPublisher
@Deprecated(since="4", forRemoval=true) public static <T> T convertPublisher(Object object, Class<T> publisherType) Deprecated, for removal: This API element is subject to removal in a future version.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
-
convertPublisher
public static <T> T convertPublisher(ConversionService conversionService, Object object, Class<T> publisherType) Attempts to convert the publisher to the given type.- Type Parameters:
T
- The generic type- Parameters:
conversionService
- The conversion serviceobject
- The object to convertpublisherType
- The publisher type- Returns:
- The Resulting in publisher
- Since:
- 4.0.0
-
isSingle
Does the given reactive type emit a single result.- Parameters:
type
- The type- Returns:
- True it does
-
isCompletable
Does the given reactive type emit a single result.- Parameters:
type
- The type- Returns:
- True it does
-
convertPublisher(ConversionService, Object, Class)