Skip to content

Commit

Permalink
Merge branch 'refs/heads/feature/ACS-8124-rename-package-prediction-a…
Browse files Browse the repository at this point in the history
…pplier-to-hxi-extension' into feature/ACS-8278-bye-bye-xml-config

# Conflicts:
#	prediction-applier-extension/src/main/java/org/alfresco/hxi_connector/hxi_extension/client/HxInsightAuthClient.java
  • Loading branch information
krdabrowski committed Jun 27, 2024
2 parents 946b2b0 + feef33e commit 7b5fcb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Class<? extends Throwable>> 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<Class<? extends Throwable>> reasons)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.function.Supplier;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import org.alfresco.hxi_connector.common.adapters.auth.AuthenticationResult;
Expand Down Expand Up @@ -57,7 +56,7 @@ private static <T> T retryWithBackoff(Supplier<T> supplier, Retry retryPropertie
{
int attempt = 0;
int maxAttempts = retryProperties.attempts();
long delay = retryProperties.initialDelay();
double delay = retryProperties.initialDelay();
while (true)
{
try
Expand All @@ -66,24 +65,24 @@ private static <T> T retryWithBackoff(Supplier<T> 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
{
Expand Down

0 comments on commit 7b5fcb4

Please sign in to comment.