diff --git a/common/src/main/java/org/alfresco/hxi_connector/common/config/properties/Retry.java b/common/src/main/java/org/alfresco/hxi_connector/common/config/properties/Retry.java index 7926e09ed..4d5048545 100644 --- a/common/src/main/java/org/alfresco/hxi_connector/common/config/properties/Retry.java +++ b/common/src/main/java/org/alfresco/hxi_connector/common/config/properties/Retry.java @@ -61,24 +61,24 @@ public class Retry MismatchedInputException.class); @Min(-1) - private int attempts = RETRY_ATTEMPTS_DEFAULT; + private int attempts; @PositiveOrZero - private int initialDelay = RETRY_INITIAL_DELAY_DEFAULT; - @Positive private double delayMultiplier = RETRY_DELAY_MULTIPLIER_DEFAULT; + private int initialDelay; + @Positive private double delayMultiplier; @NotNull private Set> reasons; public Retry() { - this.reasons = Stream.concat(RETRY_REASONS_BASIC.stream(), Stream.of(HttpHostConnectException.class, NoHttpResponseException.class, MalformedChunkCodingException.class)) - .collect(Collectors.toSet()); + this(RETRY_ATTEMPTS_DEFAULT, RETRY_INITIAL_DELAY_DEFAULT, RETRY_DELAY_MULTIPLIER_DEFAULT); } public Retry(int attempts, int initialDelay, double delayMultiplier) { - this(); - this.attempts = attempts; - this.initialDelay = initialDelay; - this.delayMultiplier = delayMultiplier; + this(attempts, initialDelay, delayMultiplier, + Stream.concat(RETRY_REASONS_BASIC.stream(), Stream.of( + HttpHostConnectException.class, + NoHttpResponseException.class, + MalformedChunkCodingException.class)).collect(Collectors.toSet())); } public Retry(int attempts, int initialDelay, double delayMultiplier, Set> reasons) diff --git a/prediction-applier-extension/src/main/java/org/alfresco/hxi_connector/hxi_extension/client/HxInsightAuthClient.java b/prediction-applier-extension/src/main/java/org/alfresco/hxi_connector/hxi_extension/client/HxInsightAuthClient.java index 16a722d0a..e0f5df81c 100644 --- a/prediction-applier-extension/src/main/java/org/alfresco/hxi_connector/hxi_extension/client/HxInsightAuthClient.java +++ b/prediction-applier-extension/src/main/java/org/alfresco/hxi_connector/hxi_extension/client/HxInsightAuthClient.java @@ -29,7 +29,6 @@ import java.util.function.Supplier; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; import org.alfresco.hxi_connector.common.adapters.auth.AuthenticationResult; import org.alfresco.hxi_connector.common.adapters.auth.DefaultAuthenticationClient; @@ -55,7 +54,7 @@ private static T retryWithBackoff(Supplier supplier, Retry retryPropertie { int attempt = 0; int maxAttempts = retryProperties.attempts(); - long delay = retryProperties.initialDelay(); + double delay = retryProperties.initialDelay(); while (true) { try @@ -64,24 +63,24 @@ private static T retryWithBackoff(Supplier supplier, Retry retryPropertie } catch (Exception e) { - if (CollectionUtils.isNotEmpty(retryProperties.reasons()) && retryProperties.reasons().contains(e.getClass())) + if (retryProperties.reasons() != null && retryProperties.reasons().contains(e.getClass())) { attempt++; if (attempt >= maxAttempts) { - log.info("Attempt {} of {} failed", attempt, maxAttempts); + log.atInfo().log("Attempt {} of {} failed", attempt, maxAttempts); throw e; } - log.info("Attempt {} of {} failed, retrying after {}ms", attempt, maxAttempts, delay); + log.atInfo().log("Attempt {} of {} failed, retrying after {}ms", attempt, maxAttempts, delay); try { - TimeUnit.MILLISECONDS.sleep(delay); + TimeUnit.MILLISECONDS.sleep(Math.round(delay)); } catch (InterruptedException ex) { - log.warn("Cannot pause retryable operation due to InterruptedException: %s".formatted(ex.getMessage()), e); + log.atWarn().log("Cannot pause retryable operation due to InterruptedException: %s".formatted(ex.getMessage()), e); } - delay = Math.round(delay * retryProperties.delayMultiplier()); + delay *= retryProperties.delayMultiplier(); } else {