Skip to content

Commit

Permalink
Moves client protocol ID caching from HttpClientRequest to WebClient …
Browse files Browse the repository at this point in the history
…level for proper sharing.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
  • Loading branch information
spericas committed Jul 1, 2024
1 parent 8a95d96 commit 741a65f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,7 @@
public class HttpClientRequest extends ClientRequestBase<HttpClientRequest, HttpClientResponse> {
private static final System.Logger LOGGER = System.getLogger(HttpClientRequest.class.getName());

private final LruCache<EndpointKey, HttpClientSpi> clientSpiCache = LruCache.create();
private final LruCache<EndpointKey, HttpClientSpi> clientSpiCache;
private final WebClient webClient;
private final Map<String, LoomClient.ProtocolSpi> clients;
private final List<LoomClient.ProtocolSpi> tcpProtocols;
Expand All @@ -50,13 +50,15 @@ public class HttpClientRequest extends ClientRequestBase<HttpClientRequest, Http
Map<String, LoomClient.ProtocolSpi> protocolsToClients,
List<LoomClient.ProtocolSpi> protocols,
List<LoomClient.ProtocolSpi> tcpProtocols,
List<String> tcpProtocolIds) {
List<String> tcpProtocolIds,
LruCache<EndpointKey, HttpClientSpi> clientSpiCache) {
super(clientConfig, webClient.cookieManager(), "any", method, clientUri, clientConfig.properties());
this.webClient = webClient;
this.clients = protocolsToClients;
this.protocols = protocols;
this.tcpProtocols = tcpProtocols;
this.tcpProtocolIds = tcpProtocolIds;
this.clientSpiCache = clientSpiCache;
}

/**
Expand Down Expand Up @@ -189,10 +191,9 @@ private ClientRequest<?> discoverHttpImplementation() {
+ "willing to handle it. HTTP versions supported: " + clients.keySet());
}

private record EndpointKey(String scheme, // http/https
String authority, // myserver:80
Tls tlsConfig, // TLS configuration (may be disabled, never null)
Proxy proxy) { // proxy, never null

record EndpointKey(String scheme, // http/https
String authority, // myserver:80
Tls tlsConfig, // TLS configuration (may be disabled, never null)
Proxy proxy) { // proxy, never null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import io.helidon.common.HelidonServiceLoader;
import io.helidon.common.LazyValue;
import io.helidon.common.configurable.LruCache;
import io.helidon.http.Method;
import io.helidon.webclient.spi.ClientProtocolProvider;
import io.helidon.webclient.spi.HttpClientSpi;
Expand All @@ -39,11 +40,10 @@
*/
@SuppressWarnings("rawtypes")
class LoomClient implements WebClient {
static final LazyValue<ExecutorService> EXECUTOR = LazyValue.create(() -> {
return Executors.newThreadPerTaskExecutor(Thread.ofVirtual()
.name("helidon-client-", 0)
.factory());
});
static final LazyValue<ExecutorService> EXECUTOR =
LazyValue.create(() -> Executors.newThreadPerTaskExecutor(Thread.ofVirtual()
.name("helidon-client-", 0)
.factory()));
private static final List<HttpClientSpiProvider> PROVIDERS =
HelidonServiceLoader.create(ServiceLoader.load(HttpClientSpiProvider.class))
.asList();
Expand All @@ -64,6 +64,7 @@ class LoomClient implements WebClient {
private final ProtocolConfigs protocolConfigs;
private final List<String> tcpProtocolIds;
private final WebClientCookieManager cookieManager;
private final LruCache<HttpClientRequest.EndpointKey, HttpClientSpi> clientSpiLruCache = LruCache.create();

/**
* Construct this instance from a subclass of builder.
Expand Down Expand Up @@ -143,7 +144,8 @@ public HttpClientRequest method(Method method) {
clientSpiByProtocol,
protocols,
tcpProtocols,
tcpProtocolIds);
tcpProtocolIds,
clientSpiLruCache);
}

@Override
Expand Down

0 comments on commit 741a65f

Please sign in to comment.