Top Description Inners Fields Constructors Methods
org.springframework.core

public Class ReactiveAdapterRegistry

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.ArrayList, .List, .Objects, .Optional, java.util.concurrent.CompletableFuture, .CompletionStage, .Flow, java.util.function.Function, org.reactivestreams.FlowAdapters, .Publisher, reactor.adapter.JdkFlowAdapter, reactor.blockhound.BlockHound, reactor.blockhound.integration.BlockHoundIntegration, reactor.core.publisher.Flux, .Mono, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .ConcurrentReferenceHashMap, .ReflectionUtils

A registry of adapters to adapt Reactive Streams Publisher to/from various async/reactive types such as CompletableFuture, RxJava Flowable, etc. This is designed to complement Spring's Reactor Mono/Flux support while also being usable without Reactor, e.g. just for org.reactivestreams bridging.

By default, depending on classpath availability, adapters are registered for Reactor (including CompletableFuture and Flow.Publisher adapters), RxJava 3, Kotlin Coroutines' Deferred (bridged via Reactor) and SmallRye Mutiny 1.x/2.x. If Reactor is not present, a simple Flow.Publisher bridge will be registered.

Authors
Rossen Stoyanchev, Sebastien Deleuze, Juergen Hoeller
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static class
ReactiveAdapterRegistry.ReactorAdapter

ReactiveAdapter variant that wraps adapted Publishers as Flux or Mono depending on ReactiveTypeDescriptor#isMultiValue().

private static class
private static class
public static class
ReactiveAdapterRegistry.SpringCoreBlockHoundIntegration

BlockHoundIntegration for spring-core classes.

Field Summary

Modifier and TypeField and Description
private final List<ReactiveAdapter>
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static volatile ReactiveAdapterRegistry

Constructor Summary

AccessConstructor and Description
public
ReactiveAdapterRegistry()

Create a registry and auto-register default adapters.

Method Summary

Modifier and TypeMethod and Description
private ReactiveAdapter
buildAdapter(ReactiveTypeDescriptor descriptor, Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter)

public ReactiveAdapter

Returns:

the corresponding adapter, or null if none available
getAdapter
(Class<?> reactiveType)

Get the adapter for the given reactive type.

public ReactiveAdapter

Returns:

the corresponding adapter, or null if none available
getAdapter
(Class<?>
the reactive type (may be null if a concrete source object is given)
reactiveType
,
Object
an instance of the reactive type (i.e. to adapt from; may be null if the reactive type is specified)
source
)

Get the adapter for the given reactive type.

public static ReactiveAdapterRegistry

Returns:

the shared ReactiveAdapterRegistry instance
getSharedInstance
()

Return a shared default ReactiveAdapterRegistry instance, lazily building it once needed.

public boolean
hasAdapters()

Return whether the registry has any adapters.

public void
registerReactiveType(ReactiveTypeDescriptor descriptor, Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter)

Register a reactive type along with functions to adapt to and from a Reactive Streams Publisher.

public void
registerReactiveTypeOverride(ReactiveTypeDescriptor descriptor, Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter)

Register a reactive type along with functions to adapt to and from a Reactive Streams Publisher.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

adaptersback to summary
private final List<ReactiveAdapter> adapters
kotlinCoroutinesPresentback to summary
private static final boolean kotlinCoroutinesPresent
mutinyPresentback to summary
private static final boolean mutinyPresent
reactiveStreamsPresentback to summary
private static final boolean reactiveStreamsPresent
reactorPresentback to summary
private static final boolean reactorPresent
rxjava3Presentback to summary
private static final boolean rxjava3Present
sharedInstanceback to summary
private static volatile ReactiveAdapterRegistry sharedInstance
Annotations
@Nullable

Constructor Detail

ReactiveAdapterRegistryback to summary
public ReactiveAdapterRegistry()

Create a registry and auto-register default adapters.

See Also
getSharedInstance()

Method Detail

buildAdapterback to summary
private ReactiveAdapter buildAdapter(ReactiveTypeDescriptor descriptor, Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter)
getAdapterback to summary
public ReactiveAdapter getAdapter(Class<?> reactiveType)

Get the adapter for the given reactive type.

Returns:ReactiveAdapter

the corresponding adapter, or null if none available

Annotations
@Nullable
getAdapterback to summary
public ReactiveAdapter getAdapter(Class<?> reactiveType, 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:Class<?>

the reactive type (may be null if a concrete source object is given)

source:Object

an instance of the reactive type (i.e. to adapt from; may be null if the reactive type is specified)

Returns:ReactiveAdapter

the corresponding adapter, or null if none available

Annotations
@Nullable
getSharedInstanceback to summary
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:ReactiveAdapterRegistry

the shared ReactiveAdapterRegistry instance

Since
5.0.2
hasAdaptersback to summary
public boolean hasAdapters()

Return whether the registry has any adapters.

registerReactiveTypeback to summary
public void registerReactiveType(ReactiveTypeDescriptor descriptor, Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter)

Register a reactive type along with functions to adapt to and from a Reactive Streams Publisher. The function arguments assume that their input is neither null nor Optional.

This variant registers the new adapter after existing adapters. It will be matched for the exact reactive type if no earlier adapter was registered for the specific type, and it will be matched for assignability in a second pass if no earlier adapter had an assignable type before.

See Also
registerReactiveTypeOverride, getAdapter
registerReactiveTypeOverrideback to summary
public void registerReactiveTypeOverride(ReactiveTypeDescriptor descriptor, Function<Object, Publisher<?>> toAdapter, Function<Publisher<?>, Object> fromAdapter)

Register a reactive type along with functions to adapt to and from a Reactive Streams Publisher. The function arguments assume that their input is neither null nor Optional.

This variant registers the new adapter first, effectively overriding any previously registered adapters for the same reactive type. This allows for overriding existing adapters, in particular default adapters.

Note that existing adapters for specific types will still match before an assignability match with the new adapter. In order to override all existing matches, a new reactive type adapter needs to be registered for every specific type, not relying on subtype assignability matches.

Since
5.3.30
See Also
registerReactiveType, getAdapter
org.springframework.core back to summary

private Class ReactiveAdapterRegistry.CoroutinesRegistrar

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.core.ReactiveAdapterRegistry.CoroutinesRegistrar

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CoroutinesRegistrarback to summary
private CoroutinesRegistrar()

Method Detail

registerAdaptersback to summary
pack-priv void registerAdapters(ReactiveAdapterRegistry registry)
Annotations
@SuppressWarnings:KotlinInternalInJava
org.springframework.core back to summary

private Class ReactiveAdapterRegistry.EmptyCompletableFuture<T>

extends CompletableFuture<T>
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.util.concurrent.CompletableFuture:
acceptEitheracceptEitherAsyncacceptEitherAsyncallOfanyOfapplyToEitherapplyToEitherAsyncapplyToEitherAsynccancelcompletecompleteAsynccompleteAsynccompletedFuturecompletedStagecompleteExceptionallycompleteOnTimeoutcopydefaultExecutordelayedExecutordelayedExecutorexceptionallyexceptionallyAsyncexceptionallyAsyncexceptionallyComposeexceptionallyComposeAsyncexceptionallyComposeAsyncexceptionNowfailedFuturefailedStagegetgetgetNowgetNumberOfDependentshandlehandleAsynchandleAsyncisCancelledisCompletedExceptionallyisDonejoinminimalCompletionStagenewIncompleteFutureobtrudeExceptionobtrudeValueorTimeoutresultNowrunAfterBothrunAfterBothAsyncrunAfterBothAsyncrunAfterEitherrunAfterEitherAsyncrunAfterEitherAsyncrunAsyncrunAsyncstatesupplyAsyncsupplyAsyncthenAcceptthenAcceptAsyncthenAcceptAsyncthenAcceptBoththenAcceptBothAsyncthenAcceptBothAsyncthenApplythenApplyAsyncthenApplyAsyncthenCombinethenCombineAsyncthenCombineAsyncthenComposethenComposeAsyncthenComposeAsyncthenRunthenRunAsyncthenRunAsynctoCompletableFuturetoStringwhenCompletewhenCompleteAsyncwhenCompleteAsync

Constructor Detail

EmptyCompletableFutureback to summary
pack-priv EmptyCompletableFuture()
org.springframework.core back to summary

private Class ReactiveAdapterRegistry.FlowAdaptersRegistrar

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.core.ReactiveAdapterRegistry.FlowAdaptersRegistrar

Field Summary

Modifier and TypeField and Description
private static final Flow.Publisher<Object>
private static final Flow.Subscription

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_PUBLISHERback to summary
private static final Flow.Publisher<Object> EMPTY_PUBLISHER
EMPTY_SUBSCRIPTIONback to summary
private static final Flow.Subscription EMPTY_SUBSCRIPTION

Constructor Detail

FlowAdaptersRegistrarback to summary
private FlowAdaptersRegistrar()

Method Detail

registerAdaptersback to summary
pack-priv void registerAdapters(ReactiveAdapterRegistry registry)
Annotations
@SuppressWarnings:unchecked
org.springframework.core back to summary

private Class ReactiveAdapterRegistry.MutinyRegistrar

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.core.ReactiveAdapterRegistry.MutinyRegistrar

Field Summary

Modifier and TypeField and Description
private static final Method

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

uniToPublisherback to summary
private static final Method uniToPublisher

Constructor Detail

MutinyRegistrarback to summary
private MutinyRegistrar()

Method Detail

registerAdaptersback to summary
pack-priv void registerAdapters(ReactiveAdapterRegistry registry)
Annotations
@SuppressWarnings:unchecked
org.springframework.core back to summary

private Class ReactiveAdapterRegistry.ReactorAdapter

extends ReactiveAdapter
Class Inheritance

ReactiveAdapter variant that wraps adapted Publishers as Flux or Mono depending on ReactiveTypeDescriptor#isMultiValue(). This is important in places where only the stream and stream element type information is available like encoders and decoders.

Constructor Summary

AccessConstructor and Description
pack-priv
ReactorAdapter(ReactiveTypeDescriptor descriptor, Function<Object, Publisher<?>> toPublisherFunction, Function<Publisher<?>, Object> fromPublisherFunction)

Method Summary

Modifier and TypeMethod and Description
public <T> Publisher<T>
toPublisher(Object
the source object to adapt from; if the given object is null, ReactiveTypeDescriptor#getEmptyValue() is used.
source
)

Overrides org.springframework.core.ReactiveAdapter.toPublisher.

Adapt the given instance to a Reactive Streams Publisher.

Inherited from org.springframework.core.ReactiveAdapter:
fromPublishergetDescriptorgetReactiveTypeisMultiValueisNoValuesupportsEmpty

Constructor Detail

ReactorAdapterback to summary
pack-priv ReactorAdapter(ReactiveTypeDescriptor descriptor, Function<Object, Publisher<?>> toPublisherFunction, Function<Publisher<?>, Object> fromPublisherFunction)

Method Detail

toPublisherback to summary
public <T> Publisher<T> toPublisher(Object source)

Overrides org.springframework.core.ReactiveAdapter.toPublisher.

Doc from org.springframework.core.ReactiveAdapter.toPublisher.

Adapt the given instance to a Reactive Streams Publisher.

Parameters
source:Object

the source object to adapt from; if the given object is null, ReactiveTypeDescriptor#getEmptyValue() is used.

Returns:Publisher<T>

the Publisher representing the adaptation

Annotations
@Override
org.springframework.core back to summary

private Class ReactiveAdapterRegistry.ReactorRegistrar

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.core.ReactiveAdapterRegistry.ReactorRegistrar

Field Summary

Modifier and TypeField and Description
private static final Flow.Publisher<?>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_FLOWback to summary
private static final Flow.Publisher<?> EMPTY_FLOW

Constructor Detail

ReactorRegistrarback to summary
private ReactorRegistrar()

Method Detail

registerAdaptersback to summary
pack-priv void registerAdapters(ReactiveAdapterRegistry registry)
org.springframework.core back to summary

private Class ReactiveAdapterRegistry.RxJava3Registrar

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.core.ReactiveAdapterRegistry.RxJava3Registrar

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RxJava3Registrarback to summary
private RxJava3Registrar()

Method Detail

registerAdaptersback to summary
pack-priv void registerAdapters(ReactiveAdapterRegistry registry)
org.springframework.core back to summary

public Class ReactiveAdapterRegistry.SpringCoreBlockHoundIntegration

extends Object
implements BlockHoundIntegration
Class Inheritance
  • java.lang.Object
  • org.springframework.core.ReactiveAdapterRegistry.SpringCoreBlockHoundIntegration
All Implemented Interfaces
reactor.blockhound.integration.BlockHoundIntegration, java.lang.Comparable

BlockHoundIntegration for spring-core classes. Explicitly allows locking within ConcurrentReferenceHashMap.
Since
5.2.4

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
applyTo(BlockHound.Builder
an instance of BlockHound.Builder that is being installed
builder
)

Implements reactor.blockhound.integration.BlockHoundIntegration.applyTo.

Lets an integration apply the customizations (see BlockHound.Builder) before BlockHound is installed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SpringCoreBlockHoundIntegrationback to summary
public SpringCoreBlockHoundIntegration()

Method Detail

applyToback to summary
public void applyTo(BlockHound.Builder builder)

Implements reactor.blockhound.integration.BlockHoundIntegration.applyTo.

Doc from reactor.blockhound.integration.BlockHoundIntegration.applyTo.

Lets an integration apply the customizations (see BlockHound.Builder) before BlockHound is installed.

Parameters
builder:BlockHound.Builder

an instance of BlockHound.Builder that is being installed

Annotations
@Override