public class ReactorResourceFactory extends Object implements InitializingBean, DisposableBean
LoopResources
for
event loop threads, and ConnectionProvider
for the connection pool,
within the lifecycle of a Spring ApplicationContext
.
This factory implements InitializingBean
and DisposableBean
and is expected typically to be declared as a Spring-managed bean.
Constructor and Description |
---|
ReactorResourceFactory() |
Modifier and Type | Method and Description |
---|---|
void |
addGlobalResourcesConsumer(Consumer<reactor.netty.http.HttpResources> consumer)
Add a Consumer for configuring the global Reactor Netty resources on
startup.
|
void |
afterPropertiesSet()
Invoked by the containing
BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware , ApplicationContextAware etc. |
void |
destroy()
Invoked by the containing
BeanFactory on destruction of a bean. |
reactor.netty.resources.ConnectionProvider |
getConnectionProvider()
Return the configured
ConnectionProvider . |
reactor.netty.resources.LoopResources |
getLoopResources()
Return the configured
LoopResources . |
boolean |
isUseGlobalResources()
Whether this factory exposes the global
HttpResources holder. |
void |
setConnectionProvider(reactor.netty.resources.ConnectionProvider connectionProvider)
Use this when you want to provide an externally managed
ConnectionProvider 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 managed
ConnectionProvider . |
void |
setLoopResources(reactor.netty.resources.LoopResources loopResources)
Use this option when you want to provide an externally managed
LoopResources 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 managed
LoopResources . |
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 the
shutdownQuietPeriod . |
void |
setUseGlobalResources(boolean useGlobalResources)
Whether to use global Reactor Netty resources via
HttpResources . |
public void setUseGlobalResources(boolean useGlobalResources)
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.
useGlobalResources
- whether to expose and manage the global resourcesaddGlobalResourcesConsumer(Consumer)
public boolean isUseGlobalResources()
HttpResources
holder.public void addGlobalResourcesConsumer(Consumer<reactor.netty.http.HttpResources> consumer)
setUseGlobalResources(boolean)
is also
enabled.consumer
- the consumer to applysetUseGlobalResources(boolean)
public void setConnectionProviderSupplier(Supplier<reactor.netty.resources.ConnectionProvider> supplier)
ConnectionProvider
.
By default, ConnectionProvider.elastic("http")
is used.
Note that this option is ignored if userGlobalResources=false
or
setConnectionProvider(ConnectionProvider)
is set.
supplier
- the supplier to usepublic void setConnectionProvider(reactor.netty.resources.ConnectionProvider connectionProvider)
ConnectionProvider
instance.connectionProvider
- the connection provider to use as ispublic reactor.netty.resources.ConnectionProvider getConnectionProvider()
ConnectionProvider
.public void setLoopResourcesSupplier(Supplier<reactor.netty.resources.LoopResources> supplier)
LoopResources
.
By default, LoopResources.create("reactor-http")
is used.
Note that this option is ignored if userGlobalResources=false
or
setLoopResources(LoopResources)
is set.
supplier
- the supplier to usepublic void setLoopResources(reactor.netty.resources.LoopResources loopResources)
LoopResources
instance.loopResources
- the loop resources to use as ispublic reactor.netty.resources.LoopResources getLoopResources()
LoopResources
.public void setShutdownQuietPeriod(Duration shutdownQuietPeriod)
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
.
setShutdownTimeout(Duration)
public void setShutdownTimeout(Duration shutdownTimeout)
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
.
setShutdownQuietPeriod(Duration)
public void afterPropertiesSet()
InitializingBean
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.
afterPropertiesSet
in interface InitializingBean
public void destroy()
DisposableBean
BeanFactory
on destruction of a bean.destroy
in interface DisposableBean