Merge branch '6.1.x'

This commit is contained in:
Juergen Hoeller
2024-06-27 12:04:59 +02:00
2 changed files with 55 additions and 2 deletions

View File

@@ -46,6 +46,7 @@ import org.springframework.util.Assert;
* @author Brian Clozel
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
* @author Juergen Hoeller
* @since 5.0
* @see reactor.netty.http.client.HttpClient
*/
@@ -72,6 +73,8 @@ public class ReactorClientHttpConnector implements ClientHttpConnector, SmartLif
@Nullable
private volatile HttpClient httpClient;
private boolean lazyStart = false;
private final Object lifecycleMonitor = new Object();
@@ -121,6 +124,9 @@ public class ReactorClientHttpConnector implements ClientHttpConnector, SmartLif
if (resourceFactory.isRunning()) {
this.httpClient = createHttpClient(resourceFactory, mapper);
}
else {
this.lazyStart = true;
}
}
private static HttpClient createHttpClient(ReactorResourceFactory factory, Function<HttpClient, HttpClient> mapper) {
@@ -136,7 +142,21 @@ public class ReactorClientHttpConnector implements ClientHttpConnector, SmartLif
HttpClient httpClient = this.httpClient;
if (httpClient == null) {
Assert.state(this.resourceFactory != null && this.mapper != null, "Illegal configuration");
httpClient = createHttpClient(this.resourceFactory, this.mapper);
if (this.resourceFactory.isRunning()) {
// Retain HttpClient instance if resource factory has been started in the meantime,
// considering this connector instance as lazily started as well.
synchronized (this.lifecycleMonitor) {
httpClient = this.httpClient;
if (httpClient == null && this.lazyStart) {
httpClient = createHttpClient(this.resourceFactory, this.mapper);
this.httpClient = httpClient;
this.lazyStart = false;
}
}
}
if (httpClient == null) {
httpClient = createHttpClient(this.resourceFactory, this.mapper);
}
}
HttpClient.RequestSender requestSender = httpClient
@@ -185,6 +205,7 @@ public class ReactorClientHttpConnector implements ClientHttpConnector, SmartLif
synchronized (this.lifecycleMonitor) {
if (this.httpClient == null) {
this.httpClient = createHttpClient(this.resourceFactory, this.mapper);
this.lazyStart = false;
}
}
}
@@ -199,6 +220,7 @@ public class ReactorClientHttpConnector implements ClientHttpConnector, SmartLif
if (this.resourceFactory != null && this.mapper != null) {
synchronized (this.lifecycleMonitor) {
this.httpClient = null;
this.lazyStart = false;
}
}
}