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
Nested ClassesModifier and TypeClassDescriptionstatic classA publisher for a value.static classA publisher that throws an error.static interfaceMaps the next result or supplies an empty result.static interfaceMarker interface for any micronaut produced publishers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TconvertPublisher(ConversionService conversionService, Object object, Class<T> publisherType) Attempts to convert the publisher to the given type.static <T> TconvertPublisher(Object object, Class<T> publisherType) Deprecated, for removal: This API element is subject to removal in a future version.convertToPublisher(@NonNull ConversionService conversionService, @NonNull Object object) Attempts to convert the publisher to the given type.static <T> Publisher<T>empty()APublisherthat completes without emitting any items.static <T> Publisher<T>fromCompletableFuture(CompletableFuture<T> future) Build aPublisherfrom aCompletableFuture.static <T> Publisher<T>fromCompletableFuture(Supplier<CompletableFuture<T>> futureSupplier) Build aPublisherfrom aCompletableFuture.static booleanisCompletable(Class<?> type) Does the given reactive type emit a single result.static booleanisConvertibleToPublisher(Class<?> type) Is the given type a Publisher or convertible to a publisher.static booleanisConvertibleToPublisher(Object object) Is the given object a Publisher or convertible to a publisher.static booleanDoes the given reactive type emit a single result.static <T> Publisher<T>APublisherthat emits a fixed single value.static <T> Publisher<T>just(T value) APublisherthat 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 voidregisterReactiveCompletable(Class<?> type) Registers an additional reactive completable type.static voidregisterReactiveSingle(Class<?> type) Registers an additional reactive single type.static voidregisterReactiveType(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 aPublisherfrom aCompletableFuture.- Type Parameters:
T- The type of the publisher- Parameters:
futureSupplier- The supplier of theCompletableFuture- Returns:
- The
Publisher
-
fromCompletableFuture
Build aPublisherfrom aCompletableFuture.- Type Parameters:
T- The type of the publisher- Parameters:
future- TheCompletableFuture- Returns:
- The
Publisher
-
just
APublisherthat emits a fixed single value.- Type Parameters:
T- The value type- Parameters:
value- The value to emit- Returns:
- The
Publisher
-
just
APublisherthat emits a fixed single value.- Type Parameters:
T- The value type- Parameters:
error- The error to emit- Returns:
- The
Publisher
-
empty
APublisherthat 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
-
convertToPublisher
@NonNull public static <T> @NonNull Publisher<T> convertToPublisher(@NonNull @NonNull ConversionService conversionService, @NonNull @NonNull Object object) Attempts to convert the publisher to the given type.- Type Parameters:
T- The generic type- Parameters:
conversionService- The conversion serviceobject- The object to convert- Returns:
- The Resulting in publisher
- Since:
- 4.6.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)