Search in sources :

Example 1 with ExpressionRetryPolicy

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;
}
Also used : AntivirusProperties(com.odysseusinc.arachne.portal.config.properties.AntivirusProperties) RetryTemplate(org.springframework.retry.support.RetryTemplate) ExponentialBackOffPolicy(org.springframework.retry.backoff.ExponentialBackOffPolicy) HashMap(java.util.HashMap) ExpressionRetryPolicy(org.springframework.retry.policy.ExpressionRetryPolicy) ExpressionRetryPolicy(org.springframework.retry.policy.ExpressionRetryPolicy) RetryPolicy(org.springframework.retry.RetryPolicy) Bean(org.springframework.context.annotation.Bean)

Aggregations

AntivirusProperties (com.odysseusinc.arachne.portal.config.properties.AntivirusProperties)1 HashMap (java.util.HashMap)1 Bean (org.springframework.context.annotation.Bean)1 RetryPolicy (org.springframework.retry.RetryPolicy)1 ExponentialBackOffPolicy (org.springframework.retry.backoff.ExponentialBackOffPolicy)1 ExpressionRetryPolicy (org.springframework.retry.policy.ExpressionRetryPolicy)1 RetryTemplate (org.springframework.retry.support.RetryTemplate)1