Skip to content

Commit b6f502d

Browse files
committed
Polishing
1 parent 8cf70fe commit b6f502d

File tree

1 file changed

+52
-40
lines changed

1 file changed

+52
-40
lines changed

spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public class ReactorResourceFactory implements InitializingBean, DisposableBean
5050
@SuppressWarnings("deprecation")
5151
private Supplier<ConnectionProvider> connectionProviderSupplier = () -> ConnectionProvider.fixed("webflux", 500);
5252

53-
private Supplier<LoopResources> loopResourcesSupplier = () -> LoopResources.create("webflux-http");
54-
5553
@Nullable
5654
private ConnectionProvider connectionProvider;
5755

56+
private Supplier<LoopResources> loopResourcesSupplier = () -> LoopResources.create("webflux-http");
57+
5858
@Nullable
5959
private LoopResources loopResources;
6060

@@ -88,29 +88,6 @@ public boolean isUseGlobalResources() {
8888
return this.useGlobalResources;
8989
}
9090

91-
/**
92-
* Configure the amount of time we'll wait before shutting down resources. If a task is
93-
* submitted during the {@code quietPeriod}, it is guaranteed to be accepted and the
94-
* {@code quietPeriod} will start over.
95-
* @since 5.2.4
96-
* @see #setShutdownTimeout(Duration)
97-
*/
98-
public void setShutdownQuietPeriod(Duration shutdownQuietPeriod) {
99-
Assert.notNull(shutdownQuietPeriod, "shutdownQuietPeriod should not be null");
100-
this.shutdownQuietPeriod = shutdownQuietPeriod;
101-
}
102-
103-
/**
104-
* Configure the maximum amount of time to wait until the disposal of the underlying
105-
* resources regardless if a task was submitted during the {@code shutdownQuietPeriod}.
106-
* @since 5.2.4
107-
* @see #setShutdownTimeout(Duration)
108-
*/
109-
public void setShutdownTimeout(Duration shutdownTimeout) {
110-
Assert.notNull(shutdownTimeout, "shutdownQuietPeriod should not be null");
111-
this.shutdownTimeout = shutdownTimeout;
112-
}
113-
11491
/**
11592
* Add a Consumer for configuring the global Reactor Netty resources on
11693
* startup. When this option is used, {@link #setUseGlobalResources} is also
@@ -125,7 +102,7 @@ public void addGlobalResourcesConsumer(Consumer<HttpResources> consumer) {
125102
}
126103

127104
/**
128-
* Use this option when you don't want to participate in global resources and
105+
* Use this when you don't want to participate in global resources and
129106
* you want to customize the creation of the managed {@code ConnectionProvider}.
130107
* <p>By default, {@code ConnectionProvider.elastic("http")} is used.
131108
* <p>Note that this option is ignored if {@code userGlobalResources=false} or
@@ -137,19 +114,7 @@ public void setConnectionProviderSupplier(Supplier<ConnectionProvider> supplier)
137114
}
138115

139116
/**
140-
* Use this option when you don't want to participate in global resources and
141-
* you want to customize the creation of the managed {@code LoopResources}.
142-
* <p>By default, {@code LoopResources.create("reactor-http")} is used.
143-
* <p>Note that this option is ignored if {@code userGlobalResources=false} or
144-
* {@link #setLoopResources(LoopResources)} is set.
145-
* @param supplier the supplier to use
146-
*/
147-
public void setLoopResourcesSupplier(Supplier<LoopResources> supplier) {
148-
this.loopResourcesSupplier = supplier;
149-
}
150-
151-
/**
152-
* Use this option when you want to provide an externally managed
117+
* Use this when you want to provide an externally managed
153118
* {@link ConnectionProvider} instance.
154119
* @param connectionProvider the connection provider to use as is
155120
*/
@@ -165,6 +130,18 @@ public ConnectionProvider getConnectionProvider() {
165130
return this.connectionProvider;
166131
}
167132

133+
/**
134+
* Use this when you don't want to participate in global resources and
135+
* you want to customize the creation of the managed {@code LoopResources}.
136+
* <p>By default, {@code LoopResources.create("reactor-http")} is used.
137+
* <p>Note that this option is ignored if {@code userGlobalResources=false} or
138+
* {@link #setLoopResources(LoopResources)} is set.
139+
* @param supplier the supplier to use
140+
*/
141+
public void setLoopResourcesSupplier(Supplier<LoopResources> supplier) {
142+
this.loopResourcesSupplier = supplier;
143+
}
144+
168145
/**
169146
* Use this option when you want to provide an externally managed
170147
* {@link LoopResources} instance.
@@ -182,6 +159,40 @@ public LoopResources getLoopResources() {
182159
return this.loopResources;
183160
}
184161

162+
/**
163+
* Configure the amount of time we'll wait before shutting down resources.
164+
* If a task is submitted during the {@code quietPeriod}, it is guaranteed
165+
* to be accepted and the {@code quietPeriod} will start over.
166+
* <p>By default, this is set to
167+
* {@link LoopResources#DEFAULT_SHUTDOWN_QUIET_PERIOD} which is 2 seconds but
168+
* can also be overridden with the system property
169+
* {@link reactor.netty.ReactorNetty#SHUTDOWN_QUIET_PERIOD
170+
* ReactorNetty.SHUTDOWN_QUIET_PERIOD}.
171+
* @since 5.2.4
172+
* @see #setShutdownTimeout(Duration)
173+
*/
174+
public void setShutdownQuietPeriod(Duration shutdownQuietPeriod) {
175+
Assert.notNull(shutdownQuietPeriod, "shutdownQuietPeriod should not be null");
176+
this.shutdownQuietPeriod = shutdownQuietPeriod;
177+
}
178+
179+
/**
180+
* Configure the maximum amount of time to wait until the disposal of the
181+
* underlying resources regardless if a task was submitted during the
182+
* {@code shutdownQuietPeriod}.
183+
* <p>By default, this is set to
184+
* {@link LoopResources#DEFAULT_SHUTDOWN_TIMEOUT} which is 15 seconds but
185+
* can also be overridden with the system property
186+
* {@link reactor.netty.ReactorNetty#SHUTDOWN_TIMEOUT
187+
* ReactorNetty.SHUTDOWN_TIMEOUT}.
188+
* @since 5.2.4
189+
* @see #setShutdownQuietPeriod(Duration)
190+
*/
191+
public void setShutdownTimeout(Duration shutdownTimeout) {
192+
Assert.notNull(shutdownTimeout, "shutdownQuietPeriod should not be null");
193+
this.shutdownTimeout = shutdownTimeout;
194+
}
195+
185196

186197
@Override
187198
public void afterPropertiesSet() {
@@ -210,7 +221,8 @@ public void afterPropertiesSet() {
210221
@Override
211222
public void destroy() {
212223
if (this.useGlobalResources) {
213-
HttpResources.disposeLoopsAndConnectionsLater(this.shutdownQuietPeriod, this.shutdownTimeout).block();
224+
HttpResources.disposeLoopsAndConnectionsLater(
225+
this.shutdownQuietPeriod, this.shutdownTimeout).block();
214226
}
215227
else {
216228
try {

0 commit comments

Comments
 (0)