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

public Class ReactorNetty2ResourceFactory

extends Object
implements InitializingBean, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean
Imports
java.time.Duration, java.util.function.Consumer, .Supplier, reactor.netty5.http.HttpResources, reactor.netty5.resources.ConnectionProvider, .LoopResources, org.springframework.beans.factory.DisposableBean, .InitializingBean, org.springframework.http.client.ReactorResourceFactory, 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 and DisposableBean and is expected typically to be declared as a Spring-managed bean.

This class is based on ReactorResourceFactory.

Author
Violeta Georgieva
Since
6.0

Field Summary

Modifier and TypeField and Description
private ConnectionProvider
private Supplier<ConnectionProvider>
private Consumer<HttpResources>
private LoopResources
private Supplier<LoopResources>
private boolean
private 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
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.

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
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
shutdownQuietPeriodback to summary
private Duration shutdownQuietPeriod
shutdownTimeoutback to summary
private Duration shutdownTimeout
useGlobalResourcesback to summary
private boolean useGlobalResources

Constructor Detail

ReactorNetty2ResourceFactoryback to summary
public ReactorNetty2ResourceFactory()

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.

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.

Since
5.2.4
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.

Since
5.2.4
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)