Top Description Fields Constructors Methods
org.springframework.http.client

public Class ReactorResourceFactory

extends Object
implements InitializingBean, DisposableBean, Lifecycle
Class Inheritance
All Implemented Interfaces
org.springframework.context.Lifecycle, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean
Known Direct Subclasses
org.springframework.http.client.reactive.ReactorResourceFactory
Imports
java.time.Duration, java.util.function.Consumer, .Supplier, reactor.netty.http.HttpResources, reactor.netty.resources.ConnectionProvider, .LoopResources, org.springframework.beans.factory.DisposableBean, .InitializingBean, org.springframework.context.Lifecycle, org.springframework.lang.Nullable, org.springframework.util.Assert

Factory to manage Reactor Netty resources, i.e. LoopResources for event loop threads, and ConnectionProvider for the connection pool, within the lifecycle of a Spring ApplicationContext.

This factory implements InitializingBean, DisposableBean and Lifecycle and is expected typically to be declared as a Spring-managed bean.

Notice that after a Lifecycle stop/restart, new instances of the configured LoopResources and ConnectionProvider are created, so any references to those should be updated.

Authors
Rossen Stoyanchev, Brian Clozel, Sebastien Deleuze
Since
6.1

Field Summary

Modifier and TypeField and Description
private ConnectionProvider
private Supplier<ConnectionProvider>
private Consumer<HttpResources>
private final Object
private LoopResources
private Supplier<LoopResources>
private boolean
private boolean
private volatile boolean
private Duration
private Duration
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addGlobalResourcesConsumer(Consumer<HttpResources>
the consumer to apply
consumer
)

Add a Consumer for configuring the global Reactor Netty resources on startup.

public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Invoked by the containing BeanFactory on destruction of a bean.
public ConnectionProvider
getConnectionProvider()

Return the configured ConnectionProvider.

public LoopResources
getLoopResources()

Return the configured LoopResources.

public boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.
public boolean
isUseGlobalResources()

Whether this factory exposes the global HttpResources holder.

public void
setConnectionProvider(ConnectionProvider
the connection provider to use as is
connectionProvider
)

Use this when you want to provide an externally managed ConnectionProvider instance.

public void
setConnectionProviderSupplier(Supplier<ConnectionProvider>
the supplier to use
supplier
)

Use this when you don't want to participate in global resources and you want to customize the creation of the managed ConnectionProvider.

public void
setLoopResources(LoopResources
the loop resources to use as is
loopResources
)

Use this option when you want to provide an externally managed LoopResources instance.

public void
setLoopResourcesSupplier(Supplier<LoopResources>
the supplier to use
supplier
)

Use this when you don't want to participate in global resources and you want to customize the creation of the managed LoopResources.

public void
setShutdownQuietPeriod(Duration shutdownQuietPeriod)

Configure the amount of time we'll wait before shutting down resources.

public void
setShutdownTimeout(Duration shutdownTimeout)

Configure the maximum amount of time to wait until the disposal of the underlying resources regardless if a task was submitted during the shutdownQuietPeriod.

public void
setUseGlobalResources(boolean
whether to expose and manage the global resources
useGlobalResources
)

Whether to use global Reactor Netty resources via HttpResources.

public void
start()

Implements org.springframework.context.Lifecycle.start.

Start this component.
public void
stop()

Implements org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionProviderback to summary
private ConnectionProvider connectionProvider
Annotations
@Nullable
connectionProviderSupplierback to summary
private Supplier<ConnectionProvider> connectionProviderSupplier
globalResourcesConsumerback to summary
private Consumer<HttpResources> globalResourcesConsumer
Annotations
@Nullable
lifecycleMonitorback to summary
private final Object lifecycleMonitor
loopResourcesback to summary
private LoopResources loopResources
Annotations
@Nullable
loopResourcesSupplierback to summary
private Supplier<LoopResources> loopResourcesSupplier
manageConnectionProviderback to summary
private boolean manageConnectionProvider
manageLoopResourcesback to summary
private boolean manageLoopResources
runningback to summary
private volatile boolean running
shutdownQuietPeriodback to summary
private Duration shutdownQuietPeriod
shutdownTimeoutback to summary
private Duration shutdownTimeout
useGlobalResourcesback to summary
private boolean useGlobalResources

Constructor Detail

ReactorResourceFactoryback to summary
public ReactorResourceFactory()

Method Detail

addGlobalResourcesConsumerback to summary
public void addGlobalResourcesConsumer(Consumer<HttpResources> consumer)

Add a Consumer for configuring the global Reactor Netty resources on startup. When this option is used, setUseGlobalResources is also enabled.

Parameters
consumer:Consumer<HttpResources>

the consumer to apply

See Also
setUseGlobalResources(boolean)
afterPropertiesSetback to summary
public void afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

Annotations
@Override
destroyback to summary
public void destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Doc from org.springframework.beans.factory.DisposableBean.destroy.

Invoked by the containing BeanFactory on destruction of a bean.

Annotations
@Override
getConnectionProviderback to summary
public ConnectionProvider getConnectionProvider()

Return the configured ConnectionProvider.

getLoopResourcesback to summary
public LoopResources getLoopResources()

Return the configured LoopResources.

isRunningback to summary
public boolean isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Doc from org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

In the case of a container, this will return true only if all components that apply are currently running.

Returns:boolean

whether the component is currently running

Annotations
@Override
isUseGlobalResourcesback to summary
public boolean isUseGlobalResources()

Whether this factory exposes the global HttpResources holder.

setConnectionProviderback to summary
public void setConnectionProvider(ConnectionProvider connectionProvider)

Use this when you want to provide an externally managed ConnectionProvider instance.

Parameters
connectionProvider:ConnectionProvider

the connection provider to use as is

setConnectionProviderSupplierback to summary
public void setConnectionProviderSupplier(Supplier<ConnectionProvider> supplier)

Use this when you don't want to participate in global resources and you want to customize the creation of the managed ConnectionProvider.

By default, ConnectionProvider.elastic("http") is used.

Note that this option is ignored if userGlobalResources=false or setConnectionProvider(ConnectionProvider) is set.

Parameters
supplier:Supplier<ConnectionProvider>

the supplier to use

setLoopResourcesback to summary
public void setLoopResources(LoopResources loopResources)

Use this option when you want to provide an externally managed LoopResources instance.

Parameters
loopResources:LoopResources

the loop resources to use as is

setLoopResourcesSupplierback to summary
public void setLoopResourcesSupplier(Supplier<LoopResources> supplier)

Use this when you don't want to participate in global resources and you want to customize the creation of the managed LoopResources.

By default, LoopResources.create("reactor-http") is used.

Note that this option is ignored if userGlobalResources=false or setLoopResources(LoopResources) is set.

Parameters
supplier:Supplier<LoopResources>

the supplier to use

setShutdownQuietPeriodback to summary
public void setShutdownQuietPeriod(Duration shutdownQuietPeriod)

Configure the amount of time we'll wait before shutting down resources. If a task is submitted during the shutdownQuietPeriod, it is guaranteed to be accepted and the shutdownQuietPeriod will start over.

By default, this is set to LoopResources#DEFAULT_SHUTDOWN_QUIET_PERIOD which is 2 seconds but can also be overridden with the system property ReactorNetty.SHUTDOWN_QUIET_PERIOD.

See Also
setShutdownTimeout(Duration)
setShutdownTimeoutback to summary
public void setShutdownTimeout(Duration shutdownTimeout)

Configure the maximum amount of time to wait until the disposal of the underlying resources regardless if a task was submitted during the shutdownQuietPeriod.

By default, this is set to LoopResources#DEFAULT_SHUTDOWN_TIMEOUT which is 15 seconds but can also be overridden with the system property ReactorNetty.SHUTDOWN_TIMEOUT.

See Also
setShutdownQuietPeriod(Duration)
setUseGlobalResourcesback to summary
public void setUseGlobalResources(boolean useGlobalResources)

Whether to use global Reactor Netty resources via HttpResources.

Default is "true" in which case this factory initializes and stops the global Reactor Netty resources within Spring's ApplicationContext lifecycle. If set to "false" the factory manages its resources independent of the global ones.

Parameters
useGlobalResources:boolean

whether to expose and manage the global resources

See Also
addGlobalResourcesConsumer(Consumer)
startback to summary
public void start()

Implements org.springframework.context.Lifecycle.start.

Doc from org.springframework.context.Lifecycle.start.

Start this component.

Should not throw an exception if the component is already running.

In the case of a container, this will propagate the start signal to all components that apply.

Annotations
@Override
stopback to summary
public void stop()

Implements org.springframework.context.Lifecycle.stop.

Doc from org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing SmartLifecycle and its stop(Runnable) variant when asynchronous stop behavior is necessary.

Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecycle beans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.

Should not throw an exception if the component is not running (not started yet).

In the case of a container, this will propagate the stop signal to all components that apply.

Annotations
@Override