diff --git a/common/reactive/src/main/java/io/helidon/common/reactive/Awaitable.java b/common/reactive/src/main/java/io/helidon/common/reactive/Awaitable.java
index 5b2a0e606ea..3a3c621b740 100644
--- a/common/reactive/src/main/java/io/helidon/common/reactive/Awaitable.java
+++ b/common/reactive/src/main/java/io/helidon/common/reactive/Awaitable.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2020, 2022 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.
@@ -63,7 +63,9 @@ default T await() {
* @throws java.util.concurrent.CancellationException if this future was cancelled
* @throws java.util.concurrent.CompletionException if this future completed exceptionally,
* was interrupted while waiting or the wait timed out
+ * @deprecated use {@link #await(Duration)} instead
*/
+ @Deprecated(since = "4.0.0")
default T await(long timeout, TimeUnit unit) {
try {
return this.toCompletableFuture().get(timeout, unit);
diff --git a/common/reactive/src/main/java/io/helidon/common/reactive/IoMulti.java b/common/reactive/src/main/java/io/helidon/common/reactive/IoMulti.java
index 11c1bdf0cd3..67f9502f083 100644
--- a/common/reactive/src/main/java/io/helidon/common/reactive/IoMulti.java
+++ b/common/reactive/src/main/java/io/helidon/common/reactive/IoMulti.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2020, 2022 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.
@@ -446,12 +446,26 @@ private OutputStreamMultiBuilder() {
* @param timeout the maximum time to block
* @param unit the time unit of the timeout argument
* @return this builder
+ * @deprecated use {@link #timeout(Duration)} instead
*/
+ @Deprecated(since = "4.0.0")
public OutputStreamMultiBuilder timeout(long timeout, TimeUnit unit) {
this.timeout = Duration.of(timeout, unit.toChronoUnit());
return this;
}
+ /**
+ * Set max timeout for which is allowed to block write methods,
+ * in case there is no demand from downstream.
+ *
+ * @param timeout the maximum time to block
+ * @return this builder
+ */
+ public OutputStreamMultiBuilder timeout(Duration timeout) {
+ this.timeout = timeout;
+ return this;
+ }
+
/**
* Callback executed when request signal from downstream arrive.
*
diff --git a/config/config/src/main/java/io/helidon/config/FileSystemWatcher.java b/config/config/src/main/java/io/helidon/config/FileSystemWatcher.java
index b784b106117..b91c8986eaa 100644
--- a/config/config/src/main/java/io/helidon/config/FileSystemWatcher.java
+++ b/config/config/src/main/java/io/helidon/config/FileSystemWatcher.java
@@ -24,6 +24,7 @@
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
+import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
@@ -413,8 +414,10 @@ public Builder executor(ScheduledExecutorService executor) {
* @param initialDelay initial delay before regular scheduling starts
* @param delay delay between schedules
* @param timeUnit time unit of the delays
- * @return updated builer instance
+ * @return updated builder instance
+ * @deprecated use {@link #initialDelay(Duration)} and {@link #delay(Duration)} instead
*/
+ @Deprecated(since = "4.0.0")
public Builder schedule(long initialDelay, long delay, TimeUnit timeUnit) {
this.initialDelay = initialDelay;
this.delay = delay;
@@ -422,6 +425,30 @@ public Builder schedule(long initialDelay, long delay, TimeUnit timeUnit) {
return this;
}
+ /**
+ * Configure an initial delay before regular scheduling starts.
+ *
+ * @param initialDelay initial delay
+ * @return updated builder instance
+ */
+ public Builder initialDelay(Duration initialDelay) {
+ this.initialDelay = initialDelay.toMillis();
+ this.timeUnit = TimeUnit.MILLISECONDS;
+ return this;
+ }
+
+ /**
+ * Configure a delay between schedules.
+ *
+ * @param delay delay between schedules
+ * @return updated builder instance
+ */
+ public Builder delay(Duration delay) {
+ this.delay = delay.toMillis();
+ this.timeUnit = TimeUnit.MILLISECONDS;
+ return this;
+ }
+
/**
* Add a modifier of the watch service.
* Currently only implementation specific modifier are available, such as
diff --git a/integrations/microstream/health/src/main/java/io/helidon/integrations/microstream/health/MicrostreamHealthCheck.java b/integrations/microstream/health/src/main/java/io/helidon/integrations/microstream/health/MicrostreamHealthCheck.java
index 79c4c2e18bb..e94b0263db7 100644
--- a/integrations/microstream/health/src/main/java/io/helidon/integrations/microstream/health/MicrostreamHealthCheck.java
+++ b/integrations/microstream/health/src/main/java/io/helidon/integrations/microstream/health/MicrostreamHealthCheck.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Oracle and/or its affiliates.
+ * Copyright (c) 2021, 2022 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.
@@ -16,6 +16,7 @@
package io.helidon.integrations.microstream.health;
+import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@@ -129,11 +130,26 @@ public Builder name(String name) {
* @param duration the maximum time to wait for statement execution response
* @param timeUnit the time unit of the timeout argument
* @return updated builder instance
+ * @deprecated use {@link #timeout(Duration)} instead
*/
+ @Deprecated(since = "4.0.0")
public Builder timeout(long duration, TimeUnit timeUnit) {
this.timeoutDuration = duration;
this.timeoutUnit = timeUnit;
return this;
}
+
+ /**
+ * Set custom timeout to wait for statement execution response. Default value is
+ * 10 seconds.
+ *
+ * @param duration the maximum time to wait for statement execution response
+ * @return updated builder instance
+ */
+ public Builder timeout(Duration duration) {
+ this.timeoutDuration = duration.toNanos();
+ this.timeoutUnit = TimeUnit.NANOSECONDS;
+ return this;
+ }
}
}
diff --git a/lra/coordinator/client/narayana-client/src/main/java/io/helidon/lra/coordinator/client/narayana/NarayanaClient.java b/lra/coordinator/client/narayana-client/src/main/java/io/helidon/lra/coordinator/client/narayana/NarayanaClient.java
index 178a78126e0..7dfc4872277 100644
--- a/lra/coordinator/client/narayana-client/src/main/java/io/helidon/lra/coordinator/client/narayana/NarayanaClient.java
+++ b/lra/coordinator/client/narayana-client/src/main/java/io/helidon/lra/coordinator/client/narayana/NarayanaClient.java
@@ -20,7 +20,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.Level;
@@ -61,17 +60,15 @@ public class NarayanaClient implements CoordinatorClient {
private static final Pattern LRA_ID_PATTERN = Pattern.compile("(.*)/([^/?]+).*");
private Supplier coordinatorUriSupplier;
- private Long coordinatorTimeout;
- private TimeUnit coordinatorTimeoutUnit;
+ private Duration coordinatorTimeout;
private Retry retry;
@Override
- public void init(Supplier coordinatorUriSupplier, long timeout, TimeUnit timeoutUnit) {
+ public void init(Supplier coordinatorUriSupplier, Duration timeout) {
this.coordinatorUriSupplier = coordinatorUriSupplier;
this.coordinatorTimeout = timeout;
- this.coordinatorTimeoutUnit = timeoutUnit;
this.retry = Retry.builder()
- .overallTimeout(Duration.ofMillis(timeoutUnit.toMillis(timeout)))
+ .overallTimeout(timeout)
.retryPolicy(Retry.JitterRetryPolicy.builder()
.calls(RETRY_ATTEMPTS)
.build())
@@ -289,8 +286,8 @@ private WebClient prepareWebClient(URI uri) {
.baseUri(uri)
// Workaround for #3242
.keepAlive(false)
- .connectTimeout(coordinatorTimeout, coordinatorTimeoutUnit)
- .readTimeout(coordinatorTimeout, coordinatorTimeoutUnit)
+ .connectTimeout(coordinatorTimeout)
+ .readTimeout(coordinatorTimeout)
.addReader(new LraStatusReader())
.build();
}
diff --git a/lra/coordinator/client/spi/src/main/java/io/helidon/lra/coordinator/client/CoordinatorClient.java b/lra/coordinator/client/spi/src/main/java/io/helidon/lra/coordinator/client/CoordinatorClient.java
index 01ab239c17f..1a1e135f514 100644
--- a/lra/coordinator/client/spi/src/main/java/io/helidon/lra/coordinator/client/CoordinatorClient.java
+++ b/lra/coordinator/client/spi/src/main/java/io/helidon/lra/coordinator/client/CoordinatorClient.java
@@ -17,6 +17,7 @@
package io.helidon.lra.coordinator.client;
import java.net.URI;
+import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
@@ -59,8 +60,20 @@ public interface CoordinatorClient {
* @param coordinatorUriSupplier url of the coordinator
* @param timeout general timeout for coordinator calls
* @param timeoutUnit timeout unit for coordinator calls
+ * @deprecated use {@link #init(Supplier, Duration)} instead
*/
- void init(Supplier coordinatorUriSupplier, long timeout, TimeUnit timeoutUnit);
+ @Deprecated(forRemoval = true, since = "4.0.0")
+ default void init(Supplier coordinatorUriSupplier, long timeout, TimeUnit timeoutUnit){
+ init(coordinatorUriSupplier, Duration.ofMillis(timeoutUnit.toMillis(timeout)));
+ }
+
+ /**
+ * Initialization of the properties provided by LRA client.
+ *
+ * @param coordinatorUriSupplier url of the coordinator
+ * @param timeout general timeout for coordinator calls
+ */
+ void init(Supplier coordinatorUriSupplier, Duration timeout);
/**
* Ask coordinator to start new LRA and return its id.
diff --git a/reactive/dbclient/health/src/main/java/io/helidon/reactive/dbclient/health/DbClientHealthCheck.java b/reactive/dbclient/health/src/main/java/io/helidon/reactive/dbclient/health/DbClientHealthCheck.java
index ad03300b5ba..9f49db50ab0 100644
--- a/reactive/dbclient/health/src/main/java/io/helidon/reactive/dbclient/health/DbClientHealthCheck.java
+++ b/reactive/dbclient/health/src/main/java/io/helidon/reactive/dbclient/health/DbClientHealthCheck.java
@@ -483,13 +483,28 @@ public Builder statement(final String statement) {
* @param duration the maximum time to wait for statement execution response
* @param timeUnit the time unit of the timeout argument
* @return updated builder instance
+ * @deprecated use {@link #timeout(Duration)} instead
*/
+ @Deprecated(since = "4.0.0")
public Builder timeout(final long duration, final TimeUnit timeUnit) {
this.timeoutDuration = duration;
this.timeoutUnit = timeUnit;
return this;
}
+ /**
+ * Set custom timeout to wait for statement execution response.
+ * Default value is {@code 10} seconds.
+ *
+ * @param timeout the maximum time to wait for statement execution response
+ * @return updated builder instance
+ */
+ public Builder timeout(final Duration timeout) {
+ this.timeoutDuration = timeout.toNanos();
+ this.timeoutUnit = TimeUnit.NANOSECONDS;
+ return this;
+ }
+
// Getters for local usage and jUnit tests
String name() {
diff --git a/reactive/health/src/main/java/io/helidon/reactive/health/HealthSupport.java b/reactive/health/src/main/java/io/helidon/reactive/health/HealthSupport.java
index a5152c29e0b..45a838cfb31 100644
--- a/reactive/health/src/main/java/io/helidon/reactive/health/HealthSupport.java
+++ b/reactive/health/src/main/java/io/helidon/reactive/health/HealthSupport.java
@@ -113,7 +113,7 @@ private HealthSupport(Builder builder) {
}
// Lazy values to prevent early init of maybe-not-yet-configured FT thread pools
- this.timeout = LazyValue.create(() -> Timeout.create(Duration.ofMillis(builder.timeoutMillis)));
+ this.timeout = LazyValue.create(() -> Timeout.create(builder.timeout));
this.async = LazyValue.create(Async::create);
}
@@ -369,7 +369,7 @@ public static final class Builder extends HelidonRestServiceSupport.Builder excludedHealthChecks = new HashSet<>();
private boolean details = true;
private boolean enabled = true;
- private long timeoutMillis = DEFAULT_TIMEOUT_MILLIS;
+ private Duration timeout = Duration.ofMillis(DEFAULT_TIMEOUT_MILLIS);
private Builder() {
super(DEFAULT_WEB_CONTEXT);
@@ -454,7 +454,7 @@ public Builder config(Config config) {
}
private void timeoutMillis(long aLong) {
- this.timeoutMillis = aLong;
+ this.timeout = Duration.ofMillis(aLong);
}
/**
@@ -463,16 +463,29 @@ private void timeoutMillis(long aLong) {
* @param timeout timeout value
* @param unit timeout time unit
* @return updated builder instance
+ * @deprecated use {@link #timeout(Duration)} instead
*/
@ConfiguredOption(key = TIMEOUT_CONFIG_KEY,
description = "health endpoint timeout (ms)",
type = Long.class,
value = "10000")
+ @Deprecated(since = "4.0.0")
public Builder timeout(long timeout, TimeUnit unit) {
timeoutMillis(unit.toMillis(timeout));
return this;
}
+ /**
+ * Configure overall timeout of health check call.
+ *
+ * @param timeout timeout value
+ * @return updated builder instance
+ */
+ public Builder timeout(Duration timeout) {
+ this.timeout = timeout;
+ return this;
+ }
+
/**
* A class may be excluded from invoking health checks on it.
* This allows configurable approach to disabling broken health-checks.
diff --git a/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClient.java b/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClient.java
index ef640a2519c..616d8e79329 100644
--- a/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClient.java
+++ b/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClient.java
@@ -269,7 +269,9 @@ public Builder config(Config config) {
* @param amount amount of time
* @param unit time unit
* @return updated builder instance
+ * @deprecated use {@link #connectTimeout(Duration)} instead
*/
+ @Deprecated(since = "4.0.0")
public Builder connectTimeout(long amount, TimeUnit unit) {
return connectTimeout(Duration.of(amount, unit.toChronoUnit()));
}
@@ -291,7 +293,9 @@ public Builder connectTimeout(Duration timeout) {
* @param amount amount of time
* @param unit time unit
* @return updated builder instance
+ * @deprecated use {@link #readTimeout(Duration)} instead
*/
+ @Deprecated(since = "4.0.0")
public Builder readTimeout(long amount, TimeUnit unit) {
return readTimeout(Duration.of(amount, unit.toChronoUnit()));
}
diff --git a/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClientRequestBuilder.java b/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClientRequestBuilder.java
index c6079343211..a09bf76636a 100644
--- a/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClientRequestBuilder.java
+++ b/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClientRequestBuilder.java
@@ -17,6 +17,7 @@
import java.net.URI;
import java.net.URL;
+import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionStage;
@@ -270,18 +271,38 @@ default WebClientRequestBuilder addHeaders(Headers parameters){
* @param amount amount of time
* @param unit time unit
* @return updated builder instance
+ * @deprecated use {@link #connectTimeout(Duration)} instead
*/
+ @Deprecated(since = "4.0.0")
WebClientRequestBuilder connectTimeout(long amount, TimeUnit unit);
+ /**
+ * Sets new connection timeout for this request.
+ *
+ * @param connectionTimeout amount of time
+ * @return updated builder instance
+ */
+ WebClientRequestBuilder connectTimeout(Duration connectionTimeout);
+
/**
* Sets new read timeout for this request.
*
* @param amount amount of time
* @param unit time unit
* @return updated builder instance
+ * @deprecated use {@link #readTimeout(Duration)} instead
*/
+ @Deprecated(since = "4.0.0")
WebClientRequestBuilder readTimeout(long amount, TimeUnit unit);
+ /**
+ * Sets new read timeout for this request.
+ *
+ * @param readTimeout amount of time
+ * @return updated builder instance
+ */
+ WebClientRequestBuilder readTimeout(Duration readTimeout);
+
/**
* Fragment of the request.
*
diff --git a/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClientRequestBuilderImpl.java b/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClientRequestBuilderImpl.java
index 2e7284597b1..7bac0002b22 100644
--- a/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClientRequestBuilderImpl.java
+++ b/reactive/webclient/webclient/src/main/java/io/helidon/reactive/webclient/WebClientRequestBuilderImpl.java
@@ -342,12 +342,24 @@ public WebClientRequestBuilder connectTimeout(long amount, TimeUnit unit) {
return this;
}
+ @Override
+ public WebClientRequestBuilder connectTimeout(Duration connectTimeout) {
+ this.connectTimeout = connectTimeout;
+ return this;
+ }
+
@Override
public WebClientRequestBuilder readTimeout(long amount, TimeUnit unit) {
this.readTimeout = Duration.of(amount, unit.toChronoUnit());
return this;
}
+ @Override
+ public WebClientRequestBuilder readTimeout(Duration readTimeout) {
+ this.readTimeout = readTimeout;
+ return this;
+ }
+
@Override
public WebClientRequestBuilder fragment(String fragment) {
this.fragment = fragment;