Class ReactorResourceFactory
- All Implemented Interfaces:
DisposableBean
,InitializingBean
,Lifecycle
- Direct Known Subclasses:
ReactorResourceFactory
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.
- Since:
- 6.1
- Author:
- Rossen Stoyanchev, Brian Clozel, Sebastien Deleuze
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addGlobalResourcesConsumer
(Consumer<reactor.netty.http.HttpResources> consumer) Add a Consumer for configuring the global Reactor Netty resources on startup.void
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.void
destroy()
Invoked by the containingBeanFactory
on destruction of a bean.reactor.netty.resources.ConnectionProvider
Return the configuredConnectionProvider
.reactor.netty.resources.LoopResources
Return the configuredLoopResources
.boolean
Check whether this component is currently running.boolean
Whether this factory exposes the globalHttpResources
holder.void
setConnectionProvider
(reactor.netty.resources.ConnectionProvider connectionProvider) Use this when you want to provide an externally managedConnectionProvider
instance.void
setConnectionProviderSupplier
(Supplier<reactor.netty.resources.ConnectionProvider> supplier) Use this when you don't want to participate in global resources and you want to customize the creation of the managedConnectionProvider
.void
setLoopResources
(reactor.netty.resources.LoopResources loopResources) Use this option when you want to provide an externally managedLoopResources
instance.void
setLoopResourcesSupplier
(Supplier<reactor.netty.resources.LoopResources> supplier) Use this when you don't want to participate in global resources and you want to customize the creation of the managedLoopResources
.void
setShutdownQuietPeriod
(Duration shutdownQuietPeriod) Configure the amount of time we'll wait before shutting down resources.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 theshutdownQuietPeriod
.void
setUseGlobalResources
(boolean useGlobalResources) Whether to use global Reactor Netty resources viaHttpResources
.void
start()
Start this component.void
stop()
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.
-
Constructor Details
-
ReactorResourceFactory
public ReactorResourceFactory()
-
-
Method Details
-
setUseGlobalResources
public void setUseGlobalResources(boolean useGlobalResources) Whether to use global Reactor Netty resources viaHttpResources
.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
- whether to expose and manage the global resources- See Also:
-
isUseGlobalResources
public boolean isUseGlobalResources()Whether this factory exposes the globalHttpResources
holder. -
addGlobalResourcesConsumer
Add a Consumer for configuring the global Reactor Netty resources on startup. When this option is used,setUseGlobalResources(boolean)
is also enabled.- Parameters:
consumer
- the consumer to apply- See Also:
-
setConnectionProviderSupplier
public void setConnectionProviderSupplier(Supplier<reactor.netty.resources.ConnectionProvider> supplier) Use this when you don't want to participate in global resources and you want to customize the creation of the managedConnectionProvider
.By default,
ConnectionProvider.elastic("http")
is used.Note that this option is ignored if
userGlobalResources=false
orsetConnectionProvider(ConnectionProvider)
is set.- Parameters:
supplier
- the supplier to use
-
setConnectionProvider
public void setConnectionProvider(reactor.netty.resources.ConnectionProvider connectionProvider) Use this when you want to provide an externally managedConnectionProvider
instance.- Parameters:
connectionProvider
- the connection provider to use as is
-
getConnectionProvider
public reactor.netty.resources.ConnectionProvider getConnectionProvider()Return the configuredConnectionProvider
. -
setLoopResourcesSupplier
Use this when you don't want to participate in global resources and you want to customize the creation of the managedLoopResources
.By default,
LoopResources.create("reactor-http")
is used.Note that this option is ignored if
userGlobalResources=false
orsetLoopResources(LoopResources)
is set.- Parameters:
supplier
- the supplier to use
-
setLoopResources
public void setLoopResources(reactor.netty.resources.LoopResources loopResources) Use this option when you want to provide an externally managedLoopResources
instance.- Parameters:
loopResources
- the loop resources to use as is
-
getLoopResources
public reactor.netty.resources.LoopResources getLoopResources()Return the configuredLoopResources
. -
setShutdownQuietPeriod
Configure the amount of time we'll wait before shutting down resources. If a task is submitted during theshutdownQuietPeriod
, it is guaranteed to be accepted and theshutdownQuietPeriod
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 propertyReactorNetty.SHUTDOWN_QUIET_PERIOD
.- See Also:
-
setShutdownTimeout
Configure the maximum amount of time to wait until the disposal of the underlying resources regardless if a task was submitted during theshutdownQuietPeriod
.By default, this is set to
LoopResources.DEFAULT_SHUTDOWN_TIMEOUT
which is 15 seconds but can also be overridden with the system propertyReactorNetty.SHUTDOWN_TIMEOUT
.- See Also:
-
afterPropertiesSet
public void afterPropertiesSet()Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,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.
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
destroy
public void destroy()Description copied from interface:DisposableBean
Invoked by the containingBeanFactory
on destruction of a bean.- Specified by:
destroy
in interfaceDisposableBean
-
start
public void start()Description copied from interface:Lifecycle
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.
-
stop
public void stop()Description copied from interface:Lifecycle
Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycle
and itsstop(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.
-
isRunning
public boolean isRunning()Description copied from interface:Lifecycle
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.
-