Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid virtual thread pinning in RestClientsConfig
Browse files Browse the repository at this point in the history
mariofusco committed Jul 17, 2024
1 parent 731c915 commit a4433d1
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

import jakarta.enterprise.inject.CreationException;
@@ -37,7 +38,7 @@ public class RestClientsConfig {
// The @Deprecated annotation prevents this field from being included in generated docs. We only want the `configKey` field
// above to be included.
@Deprecated
private final Map<String, RestClientConfig> configs = new ConcurrentHashMap<>();
private final Map<String, CompletableFuture<RestClientConfig>> configs = new ConcurrentHashMap<>();

/**
* Mode in which the form data are encoded. Possible values are `HTML5`, `RFC1738` and `RFC3986`.
@@ -327,19 +328,27 @@ public RestClientConfig getClientConfig(String configKey) {
if (configKey == null) {
return RestClientConfig.EMPTY;
}
return configs.computeIfAbsent(configKey, RestClientConfig::load);
CompletableFuture<RestClientConfig> futureConfig = configs.computeIfAbsent(configKey, name -> new CompletableFuture<>());
if (!futureConfig.isDone()) {
futureConfig.complete(RestClientConfig.load(configKey));
}
return futureConfig.join();
}

public RestClientConfig getClientConfig(Class<?> clientInterface) {
return configs.computeIfAbsent(clientInterface.getName(), name -> RestClientConfig.load(clientInterface));
CompletableFuture<RestClientConfig> futureConfig = configs.computeIfAbsent(clientInterface.getName(), name -> new CompletableFuture<>());
if (!futureConfig.isDone()) {
futureConfig.complete(RestClientConfig.load(clientInterface));
}
return futureConfig.join();
}

public void putClientConfig(String configKey, RestClientConfig clientConfig) {
configs.put(configKey, clientConfig);
configs.put(configKey, CompletableFuture.completedFuture(clientConfig));
}

public void putClientConfig(Class<?> clientInterface, RestClientConfig clientConfig) {
configs.put(clientInterface.getName(), clientConfig);
configs.put(clientInterface.getName(), CompletableFuture.completedFuture(clientConfig));
}

public Set<String> getConfigKeys() {

0 comments on commit a4433d1

Please sign in to comment.