Class ReactorResourceFactory
- All Implemented Interfaces:
- Aware,- DisposableBean,- InitializingBean,- ApplicationContextAware,- Lifecycle,- Phased,- SmartLifecycle
- 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 SmartLifecycle and is expected typically
 to be declared as a Spring-managed bean.
 
Notice that after a SmartLifecycle 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, Juergen Hoeller
- 
Field SummaryFields inherited from interface org.springframework.context.SmartLifecycleDEFAULT_PHASE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddGlobalResourcesConsumer(Consumer<reactor.netty.http.HttpResources> consumer) Add a Consumer for configuring the global Reactor Netty resources on startup.voidStarts the resources if initialized outside an ApplicationContext.voiddestroy()Stops the resources if initialized outside an ApplicationContext.reactor.netty.resources.ConnectionProviderReturn the configuredConnectionProvider.reactor.netty.resources.LoopResourcesReturn the configuredLoopResources.intgetPhase()Return the phase that this lifecycle object is supposed to run in.booleanCheck whether this component is currently running.booleanWhether this factory exposes the globalHttpResourcesholder.voidsetApplicationContext(ApplicationContext applicationContext) Setting anApplicationContextis optional: If set, Reactor resources will be initialized in thelifecycle startphase and closed in thelifecycle stopphase.voidsetConnectionProvider(reactor.netty.resources.ConnectionProvider connectionProvider) Use this when you want to provide an externally managedConnectionProviderinstance.voidsetConnectionProviderSupplier(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.voidsetLoopResources(reactor.netty.resources.LoopResources loopResources) Use this option when you want to provide an externally managedLoopResourcesinstance.voidsetLoopResourcesSupplier(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.voidsetShutdownQuietPeriod(Duration shutdownQuietPeriod) Configure the amount of time we'll wait before shutting down resources.voidsetShutdownTimeout(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.voidsetUseGlobalResources(boolean useGlobalResources) Whether to use global Reactor Netty resources viaHttpResources.voidstart()Start this component.voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycleisAutoStartup, stop
- 
Constructor Details- 
ReactorResourceFactorypublic ReactorResourceFactory()
 
- 
- 
Method Details- 
setUseGlobalResourcespublic 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 ApplicationContextlifecycle. 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:
 
- 
isUseGlobalResourcespublic boolean isUseGlobalResources()Whether this factory exposes the globalHttpResourcesholder.
- 
addGlobalResourcesConsumerAdd 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:
 
- 
setConnectionProviderSupplierpublic 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 supplier is ignored if isUseGlobalResources()istrueor once theConnectionProvideris set.- Parameters:
- supplier- the supplier to use
 
- 
setConnectionProviderpublic void setConnectionProvider(reactor.netty.resources.ConnectionProvider connectionProvider) Use this when you want to provide an externally managedConnectionProviderinstance.- Parameters:
- connectionProvider- the connection provider to use as is
 
- 
getConnectionProviderpublic reactor.netty.resources.ConnectionProvider getConnectionProvider()Return the configuredConnectionProvider.Lazily tries to start the resources on demand if not initialized yet. - See Also:
 
- 
setLoopResourcesSupplierUse 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("webflux-http")is used.Note that this supplier is ignored if isUseGlobalResources()istrueor once theLoopResourcesis set.- Parameters:
- supplier- the supplier to use
 
- 
setLoopResourcespublic void setLoopResources(reactor.netty.resources.LoopResources loopResources) Use this option when you want to provide an externally managedLoopResourcesinstance.- Parameters:
- loopResources- the loop resources to use as is
 
- 
getLoopResourcespublic reactor.netty.resources.LoopResources getLoopResources()Return the configuredLoopResources.Lazily tries to start the resources on demand if not initialized yet. - See Also:
 
- 
setShutdownQuietPeriodConfigure 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 theshutdownQuietPeriodwill start over.By default, this is set to LoopResources.DEFAULT_SHUTDOWN_QUIET_PERIODwhich is 2 seconds but can also be overridden with the system propertyReactorNetty.SHUTDOWN_QUIET_PERIOD.- See Also:
 
- 
setShutdownTimeoutConfigure 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_TIMEOUTwhich is 15 seconds but can also be overridden with the system propertyReactorNetty.SHUTDOWN_TIMEOUT.- See Also:
 
- 
setApplicationContextSetting anApplicationContextis optional: If set, Reactor resources will be initialized in thelifecycle startphase and closed in thelifecycle stopphase. If not set, it will happen inafterPropertiesSet()anddestroy(), respectively.- Specified by:
- setApplicationContextin interface- ApplicationContextAware
- Parameters:
- applicationContext- the ApplicationContext object to be used by this object
- See Also:
 
- 
afterPropertiesSetpublic void afterPropertiesSet()Starts the resources if initialized outside an ApplicationContext. This is for backwards compatibility; the preferred way is to rely on the ApplicationContext'slifecycle management.- Specified by:
- afterPropertiesSetin interface- InitializingBean
- See Also:
 
- 
destroypublic void destroy()Stops the resources if initialized outside an ApplicationContext. This is for backwards compatibility; the preferred way is to rely on the ApplicationContext'slifecycle management.- Specified by:
- destroyin interface- DisposableBean
- See Also:
 
- 
startpublic void start()Description copied from interface:LifecycleStart 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. 
- 
stoppublic void stop()Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecyclebeans 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. 
- 
isRunningpublic boolean isRunning()Description copied from interface:LifecycleCheck whether this component is currently running.In the case of a container, this will return trueonly if all components that apply are currently running.
- 
getPhasepublic int getPhase()Description copied from interface:SmartLifecycleReturn the phase that this lifecycle object is supposed to run in.The default implementation returns SmartLifecycle.DEFAULT_PHASEin order to letstop()callbacks execute before regularLifecycleimplementations.- Specified by:
- getPhasein interface- Phased
- Specified by:
- getPhasein interface- SmartLifecycle
- See Also:
 
 
-