use of org.springframework.retry.policy.ExpressionRetryPolicy in project ArachneCentralAPI by OHDSI.
the class AntivirusConfig method antivirusRetryTemplate.
@Bean(name = "antivirusRetryTemplate")
public RetryTemplate antivirusRetryTemplate(AntivirusProperties properties) {
RetryTemplate retryTemplate = new RetryTemplate();
AntivirusProperties.RetryConfig retryConfig = properties.getRetry();
Map<Class<? extends Throwable>, Boolean> retryableExceptions = new HashMap<>();
retryableExceptions.put(CommunicationException.class, true);
RetryPolicy policy = new ExpressionRetryPolicy(retryConfig.getMaxAttempts(), retryableExceptions, true, "#{message.contains('Error while communicating with the server')}");
retryTemplate.setRetryPolicy(policy);
AntivirusProperties.BackOffPolicyConfig backOffPolicyConfig = retryConfig.getBackoff();
ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
backOffPolicy.setInitialInterval(backOffPolicyConfig.getInitialInterval());
backOffPolicy.setMaxInterval(backOffPolicyConfig.getMaxInterval());
backOffPolicy.setMultiplier(backOffPolicyConfig.getMultiplier());
retryTemplate.setBackOffPolicy(backOffPolicy);
return retryTemplate;
}
Aggregations