From b6f502db4e262a42ceb9076e16d455afd3ac3dbf Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 24 Feb 2020 20:43:27 +0000 Subject: [PATCH] Polishing --- .../reactive/ReactorResourceFactory.java | 92 +++++++++++-------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java index 39f1b582bb03..94da122f99d6 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java @@ -50,11 +50,11 @@ public class ReactorResourceFactory implements InitializingBean, DisposableBean @SuppressWarnings("deprecation") private Supplier connectionProviderSupplier = () -> ConnectionProvider.fixed("webflux", 500); - private Supplier loopResourcesSupplier = () -> LoopResources.create("webflux-http"); - @Nullable private ConnectionProvider connectionProvider; + private Supplier loopResourcesSupplier = () -> LoopResources.create("webflux-http"); + @Nullable private LoopResources loopResources; @@ -88,29 +88,6 @@ public boolean isUseGlobalResources() { return this.useGlobalResources; } - /** - * Configure the amount of time we'll wait before shutting down resources. If a task is - * submitted during the {@code quietPeriod}, it is guaranteed to be accepted and the - * {@code quietPeriod} will start over. - * @since 5.2.4 - * @see #setShutdownTimeout(Duration) - */ - public void setShutdownQuietPeriod(Duration shutdownQuietPeriod) { - Assert.notNull(shutdownQuietPeriod, "shutdownQuietPeriod should not be null"); - this.shutdownQuietPeriod = shutdownQuietPeriod; - } - - /** - * Configure the maximum amount of time to wait until the disposal of the underlying - * resources regardless if a task was submitted during the {@code shutdownQuietPeriod}. - * @since 5.2.4 - * @see #setShutdownTimeout(Duration) - */ - public void setShutdownTimeout(Duration shutdownTimeout) { - Assert.notNull(shutdownTimeout, "shutdownQuietPeriod should not be null"); - this.shutdownTimeout = shutdownTimeout; - } - /** * Add a Consumer for configuring the global Reactor Netty resources on * startup. When this option is used, {@link #setUseGlobalResources} is also @@ -125,7 +102,7 @@ public void addGlobalResourcesConsumer(Consumer consumer) { } /** - * Use this option when you don't want to participate in global resources and + * Use this when you don't want to participate in global resources and * you want to customize the creation of the managed {@code ConnectionProvider}. *

By default, {@code ConnectionProvider.elastic("http")} is used. *

Note that this option is ignored if {@code userGlobalResources=false} or @@ -137,19 +114,7 @@ public void setConnectionProviderSupplier(Supplier supplier) } /** - * Use this option when you don't want to participate in global resources and - * you want to customize the creation of the managed {@code LoopResources}. - *

By default, {@code LoopResources.create("reactor-http")} is used. - *

Note that this option is ignored if {@code userGlobalResources=false} or - * {@link #setLoopResources(LoopResources)} is set. - * @param supplier the supplier to use - */ - public void setLoopResourcesSupplier(Supplier supplier) { - this.loopResourcesSupplier = supplier; - } - - /** - * Use this option when you want to provide an externally managed + * Use this when you want to provide an externally managed * {@link ConnectionProvider} instance. * @param connectionProvider the connection provider to use as is */ @@ -165,6 +130,18 @@ public ConnectionProvider getConnectionProvider() { return this.connectionProvider; } + /** + * Use this when you don't want to participate in global resources and + * you want to customize the creation of the managed {@code LoopResources}. + *

By default, {@code LoopResources.create("reactor-http")} is used. + *

Note that this option is ignored if {@code userGlobalResources=false} or + * {@link #setLoopResources(LoopResources)} is set. + * @param supplier the supplier to use + */ + public void setLoopResourcesSupplier(Supplier supplier) { + this.loopResourcesSupplier = supplier; + } + /** * Use this option when you want to provide an externally managed * {@link LoopResources} instance. @@ -182,6 +159,40 @@ public LoopResources getLoopResources() { return this.loopResources; } + /** + * Configure the amount of time we'll wait before shutting down resources. + * If a task is submitted during the {@code quietPeriod}, it is guaranteed + * to be accepted and the {@code quietPeriod} will start over. + *

By default, this is set to + * {@link LoopResources#DEFAULT_SHUTDOWN_QUIET_PERIOD} which is 2 seconds but + * can also be overridden with the system property + * {@link reactor.netty.ReactorNetty#SHUTDOWN_QUIET_PERIOD + * ReactorNetty.SHUTDOWN_QUIET_PERIOD}. + * @since 5.2.4 + * @see #setShutdownTimeout(Duration) + */ + public void setShutdownQuietPeriod(Duration shutdownQuietPeriod) { + Assert.notNull(shutdownQuietPeriod, "shutdownQuietPeriod should not be null"); + this.shutdownQuietPeriod = shutdownQuietPeriod; + } + + /** + * Configure the maximum amount of time to wait until the disposal of the + * underlying resources regardless if a task was submitted during the + * {@code shutdownQuietPeriod}. + *

By default, this is set to + * {@link LoopResources#DEFAULT_SHUTDOWN_TIMEOUT} which is 15 seconds but + * can also be overridden with the system property + * {@link reactor.netty.ReactorNetty#SHUTDOWN_TIMEOUT + * ReactorNetty.SHUTDOWN_TIMEOUT}. + * @since 5.2.4 + * @see #setShutdownQuietPeriod(Duration) + */ + public void setShutdownTimeout(Duration shutdownTimeout) { + Assert.notNull(shutdownTimeout, "shutdownQuietPeriod should not be null"); + this.shutdownTimeout = shutdownTimeout; + } + @Override public void afterPropertiesSet() { @@ -210,7 +221,8 @@ public void afterPropertiesSet() { @Override public void destroy() { if (this.useGlobalResources) { - HttpResources.disposeLoopsAndConnectionsLater(this.shutdownQuietPeriod, this.shutdownTimeout).block(); + HttpResources.disposeLoopsAndConnectionsLater( + this.shutdownQuietPeriod, this.shutdownTimeout).block(); } else { try {