From dd32f80aef1479750e2a001828473f2116538905 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Wed, 26 Jul 2023 21:45:13 +0200 Subject: [PATCH] Allow use virtual threads in Wave client Signed-off-by: Paolo Di Tommaso --- .../main/io/seqera/wave/plugin/WaveClient.groovy | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy b/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy index c7b3554590..bf91dcc053 100644 --- a/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy +++ b/plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy @@ -27,6 +27,7 @@ import java.time.Duration import java.time.OffsetDateTime import java.time.temporal.ChronoUnit import java.util.concurrent.Callable +import java.util.concurrent.Executors import java.util.concurrent.TimeUnit import java.util.function.Predicate @@ -56,6 +57,7 @@ import nextflow.processor.Architecture import nextflow.processor.TaskRun import nextflow.script.bundle.ResourcesBundle import nextflow.util.SysHelper +import nextflow.util.Threads import org.slf4j.Logger import org.slf4j.LoggerFactory /** @@ -127,12 +129,20 @@ class WaveClient { // the cookie manager cookieManager = new CookieManager() // create http client - this.httpClient = HttpClient.newBuilder() + this.httpClient = newHttpClient() + } + + protected HttpClient newHttpClient() { + final builder = HttpClient.newBuilder() .version(HttpClient.Version.HTTP_1_1) .followRedirects(HttpClient.Redirect.NEVER) .cookieHandler(cookieManager) .connectTimeout(config.httpOpts().connectTimeout()) - .build() + // use virtual threads executor if enabled + if( Threads.useVirtual() ) + builder.executor(Executors.newVirtualThreadPerTaskExecutor()) + // build and return the new client + return builder.build() } WaveConfig config() { return config }