org.springframework.core

Class ReactiveAdapterRegistry

  • java.lang.Object
    • org.springframework.core.ReactiveAdapterRegistry


  • public class ReactiveAdapterRegistry
    extends java.lang.Object
    A registry of adapters to adapt Reactive Streams Publisher to/from various async/reactive types such as CompletableFuture, RxJava Observable, and others.

    By default, depending on classpath availability, adapters are registered for Reactor, RxJava 1, RxJava 2 types, CompletableFuture, and Java 9+ Flow.Publisher.

    Since:
    5.0
    Author:
    Rossen Stoyanchev, Sebastien Deleuze
    • Constructor Summary

      Constructors 
      Constructor and Description
      ReactiveAdapterRegistry()
      Create a registry and auto-register default adapters.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      ReactiveAdapter getAdapter(java.lang.Class<?> reactiveType)
      Get the adapter for the given reactive type.
      ReactiveAdapter getAdapter(java.lang.Class<?> reactiveType, java.lang.Object source)
      Get the adapter for the given reactive type.
      static ReactiveAdapterRegistry getSharedInstance()
      Return a shared default ReactiveAdapterRegistry instance, lazily building it once needed.
      boolean hasAdapters()
      Whether the registry has any adapters which would be the case if any of Reactor, RxJava 2, or RxJava 1 (+ RxJava Reactive Streams bridge) are present on the classpath.
      void registerReactiveType(ReactiveTypeDescriptor descriptor, java.util.function.Function<java.lang.Object,org.reactivestreams.Publisher<?>> toAdapter, java.util.function.Function<org.reactivestreams.Publisher<?>,java.lang.Object> fromAdapter)
      Register a reactive type along with functions to adapt to and from a Reactive Streams Publisher.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReactiveAdapterRegistry

        public ReactiveAdapterRegistry()
        Create a registry and auto-register default adapters.
        See Also:
        getSharedInstance()
    • Method Detail

      • hasAdapters

        public boolean hasAdapters()
        Whether the registry has any adapters which would be the case if any of Reactor, RxJava 2, or RxJava 1 (+ RxJava Reactive Streams bridge) are present on the classpath.
      • registerReactiveType

        public void registerReactiveType(ReactiveTypeDescriptor descriptor,
                                         java.util.function.Function<java.lang.Object,org.reactivestreams.Publisher<?>> toAdapter,
                                         java.util.function.Function<org.reactivestreams.Publisher<?>,java.lang.Object> fromAdapter)
        Register a reactive type along with functions to adapt to and from a Reactive Streams Publisher. The functions can assume their input is never be null nor Optional.
      • getAdapter

        @Nullable
        public ReactiveAdapter getAdapter(java.lang.Class<?> reactiveType)
        Get the adapter for the given reactive type.
      • getAdapter

        @Nullable
        public ReactiveAdapter getAdapter(@Nullable
                                                    java.lang.Class<?> reactiveType,
                                                    @Nullable
                                                    java.lang.Object source)
        Get the adapter for the given reactive type. Or if a "source" object is provided, its actual type is used instead.
        Parameters:
        reactiveType - the reactive type (may be null if a concrete source object is given)
        source - an instance of the reactive type (i.e. to adapt from; may be null if the reactive type is specified)
      • getSharedInstance

        public static ReactiveAdapterRegistry getSharedInstance()
        Return a shared default ReactiveAdapterRegistry instance, lazily building it once needed.

        NOTE: We highly recommend passing a long-lived, pre-configured ReactiveAdapterRegistry instance for customization purposes. This accessor is only meant as a fallback for code paths that want to fall back on a default instance if one isn't provided.

        Returns:
        the shared ReactiveAdapterRegistry instance (never null)
        Since:
        5.0.2