spring-framework / org.springframework.core / ReactiveAdapterRegistry

ReactiveAdapterRegistry

open class ReactiveAdapterRegistry

A registry of adapters to adapt a 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.

Author
Rossen Stoyanchev

Author
Sebastien Deleuze

Since
5.0

Constructors

<init>

ReactiveAdapterRegistry()

Create a registry and auto-register default adapters.

Functions

getAdapter

open fun getAdapter(reactiveType: Class<*>): ReactiveAdapter

Get the adapter for the given reactive type.

open fun getAdapter(reactiveType: Class<*>, source: Any): ReactiveAdapter

Get the adapter for the given reactive type. Or if a "source" object is provided, its actual type is used instead.

getSharedInstance

open static fun getSharedInstance(): ReactiveAdapterRegistry

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.

hasAdapters

open fun hasAdapters(): Boolean

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

open fun registerReactiveType(descriptor: ReactiveTypeDescriptor, toAdapter: Function<Any, Publisher<*>>, fromAdapter: Function<Publisher<*>, Any>): Unit

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.