Class Publishers

java.lang.Object
io.micronaut.core.async.publisher.Publishers

@Internal public class Publishers extends Object
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
  • Constructor Details

    • Publishers

      public Publishers()
  • Method Details

    • getReactiveTypeNames

      @NonNull public static @NonNull List<String> getReactiveTypeNames()
    • registerReactiveType

      public static void registerReactiveType(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(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(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 List<Class<?>> getKnownReactiveTypes()
      Returns:
      A list of known reactive types.
    • getKnownSingleTypes

      public static List<Class<?>> getKnownSingleTypes()
      Returns:
      A list of known single types.
    • getKnownCompletableTypes

      public static List<Class<?>> getKnownCompletableTypes()
      Returns:
      A list of known single types.
    • fromCompletableFuture

      public static <T> Publisher<T> fromCompletableFuture(Supplier<CompletableFuture<T>> futureSupplier)
      Type Parameters:
      T - The type of the publisher
      Parameters:
      futureSupplier - The supplier of the CompletableFuture
      Returns:
      The Publisher
    • fromCompletableFuture

      public static <T> Publisher<T> fromCompletableFuture(CompletableFuture<T> future)
      Type Parameters:
      T - The type of the publisher
      Parameters:
      future - The CompletableFuture
      Returns:
      The Publisher
    • just

      public static <T> Publisher<T> just(T value)
      A Publisher 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> Publisher<T> just(Throwable error)
      A Publisher 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> Publisher<T> empty()
      A Publisher that completes without emitting any items.
      Type Parameters:
      T - The value type
      Returns:
      The Publisher
      Since:
      2.0.0
    • map

      public static <T, R> Publisher<R> map(Publisher<T> publisher, Function<T,R> mapper)
      Map the result from a publisher using the given mapper.
      Type Parameters:
      T - The generic type
      R - The result type
      Parameters:
      publisher - The publisher
      mapper - 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 type
      R - The result type
      Parameters:
      publisher - The publisher
      mapOrSupplyEmpty - The mapOrSupplyEmpty
      Returns:
      The mapped publisher
      Since:
      2.5.0
    • then

      public static <T> Publisher<T> then(Publisher<T> publisher, Consumer<T> consumer)
      Map the result from a publisher using the given mapper.
      Type Parameters:
      T - The generic type
      Parameters:
      publisher - The publisher
      consumer - 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 publisher
      future - The runnable
      Returns:
      The mapped publisher
    • isConvertibleToPublisher

      public static boolean isConvertibleToPublisher(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(Object object)
      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 convert
      publisherType - 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 service
      object - The object to convert
      publisherType - The publisher type
      Returns:
      The Resulting in publisher
      Since:
      4.0.0
    • isSingle

      public static boolean isSingle(Class<?> type)
      Does the given reactive type emit a single result.
      Parameters:
      type - The type
      Returns:
      True it does
    • isCompletable

      public static boolean isCompletable(Class<?> type)
      Does the given reactive type emit a single result.
      Parameters:
      type - The type
      Returns:
      True it does