org.springframework.http.client.reactive

Class ReactorResourceFactory

  • java.lang.Object
    • org.springframework.http.client.reactive.ReactorResourceFactory
  • All Implemented Interfaces:
    DisposableBean, InitializingBean


    public class ReactorResourceFactory
    extends java.lang.Object
    implements InitializingBean, DisposableBean
    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.

    Since:
    5.1
    Author:
    Rossen Stoyanchev
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addGlobalResourcesConsumer(java.util.function.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 option when you want to provide an externally managed ConnectionProvider instance.
      void setConnectionProviderSupplier(java.util.function.Supplier<reactor.netty.resources.ConnectionProvider> supplier)
      Use this option 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(java.util.function.Supplier<reactor.netty.resources.LoopResources> supplier)
      Use this option when you don't want to participate in global resources and you want to customize the creation of the managed LoopResources.
      void setUseGlobalResources(boolean useGlobalResources)
      Whether to use global Reactor Netty resources via HttpResources.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReactorResourceFactory

        public ReactorResourceFactory()
    • Method Detail

      • setUseGlobalResources

        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 - whether to expose and manage the global resources
        See Also:
        addGlobalResourcesConsumer(Consumer)
      • isUseGlobalResources

        public boolean isUseGlobalResources()
        Whether this factory exposes the global HttpResources holder.
      • addGlobalResourcesConsumer

        public void addGlobalResourcesConsumer(java.util.function.Consumer<reactor.netty.http.HttpResources> consumer)
        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:
        setUseGlobalResources(boolean)
      • setConnectionProviderSupplier

        public void setConnectionProviderSupplier(java.util.function.Supplier<reactor.netty.resources.ConnectionProvider> supplier)
        Use this option 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 - the supplier to use
      • setLoopResourcesSupplier

        public void setLoopResourcesSupplier(java.util.function.Supplier<reactor.netty.resources.LoopResources> supplier)
        Use this option 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 - the supplier to use
      • setConnectionProvider

        public void setConnectionProvider(reactor.netty.resources.ConnectionProvider connectionProvider)
        Use this option when you want to provide an externally managed ConnectionProvider instance.
        Parameters:
        connectionProvider - the connection provider to use as is
      • getConnectionProvider

        public reactor.netty.resources.ConnectionProvider getConnectionProvider()
        Return the configured ConnectionProvider.
      • setLoopResources

        public void setLoopResources(reactor.netty.resources.LoopResources loopResources)
        Use this option when you want to provide an externally managed LoopResources instance.
        Parameters:
        loopResources - the loop resources to use as is
      • getLoopResources

        public reactor.netty.resources.LoopResources getLoopResources()
        Return the configured LoopResources.
      • afterPropertiesSet

        public void afterPropertiesSet()
        Description copied from interface: InitializingBean
        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.

        Specified by:
        afterPropertiesSet in interface InitializingBean
      • destroy

        public void destroy()
        Description copied from interface: DisposableBean
        Invoked by the containing BeanFactory on destruction of a bean.
        Specified by:
        destroy in interface DisposableBean