/** * Apply the backoff options. Cannot be used if a custom retry operations, or back off * policy has been set. * @param initialInterval The initial interval. * @param multiplier The multiplier. * @param maxInterval The max interval. * @return this. */ public RetryInterceptorBuilder<T> backOffOptions(long initialInterval, double multiplier, long maxInterval) { Assert.isNull(this.retryOperations, "cannot set the back off policy when a custom retryOperations has been set"); Assert.isTrue(!this.backOffPolicySet, "cannot set the back off options when a back off policy has been set"); ExponentialBackOffPolicy policy = new ExponentialBackOffPolicy(); policy.setInitialInterval(initialInterval); policy.setMultiplier(multiplier); policy.setMaxInterval(maxInterval); this.retryTemplate.setBackOffPolicy(policy); this.backOffOptionsSet = true; this.templateAltered = true; return this; }
protected void cloneValues(ExponentialBackOffPolicy target) { target.setInitialInterval(getInitialInterval()); target.setMaxInterval(getMaxInterval()); target.setMultiplier(getMultiplier()); target.setSleeper(sleeper); }
@Bean @ConditionalOnMissingBean(name = "statsRetryTemplate") public RetryTemplate statsRetryTemplate() { RetryTemplate retryTemplate = new RetryTemplate(); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(3000L); backOffPolicy.setMultiplier(3); SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy( this.statsProperties.getElastic().getMaxAttempts(), Collections.singletonMap(Exception.class, true)); retryTemplate.setBackOffPolicy(backOffPolicy); retryTemplate.setRetryPolicy(retryPolicy); return retryTemplate; }
/** * Get RetryTemplate. * * @param noOfRetries number of retries * @param initialInterval initial interval for the back-off policy * @param maxInterval maximum interval for the back-off policy * @return The retry template to use */ @Bean(name = "genieRetryTemplate") public RetryTemplate retryTemplate( @Value("${genie.retry.noOfRetries:5}") final int noOfRetries, @Value("${genie.retry.initialInterval:10000}") final int initialInterval, @Value("${genie.retry.maxInterval:60000}") final int maxInterval ) { final RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new SimpleRetryPolicy(noOfRetries, Collections.singletonMap(Exception.class, true))); final ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(initialInterval); backOffPolicy.setMaxInterval(maxInterval); retryTemplate.setBackOffPolicy(backOffPolicy); return retryTemplate; }
protected ExponentialBackOffPolicy newInstance() { return new ExponentialBackOffPolicy(); }
protected ExponentialBackOffPolicy createBackOffPolicy() { ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setMultiplier(5.0D); return backOffPolicy; }
protected void cloneValues(ExponentialBackOffPolicy target) { target.setInitialInterval(getInitialInterval()); target.setMaxInterval(getMaxInterval()); target.setMultiplier(getMultiplier()); target.setSleeper(sleeper); }
@Bean @ConditionalOnMissingBean(name = "statsRetryTemplate") public RetryTemplate statsRetryTemplate() { RetryTemplate retryTemplate = new RetryTemplate(); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(3000L); backOffPolicy.setMultiplier(3); SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy( this.statsProperties.getElastic().getMaxAttempts(), Collections.singletonMap(Exception.class, true)); retryTemplate.setBackOffPolicy(backOffPolicy); retryTemplate.setRetryPolicy(retryPolicy); return retryTemplate; }
/** * Constructor. * @param dataServiceRetryProperties retry properties */ @Autowired public DataServiceRetryAspect(final DataServiceRetryProperties dataServiceRetryProperties) { retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new SimpleRetryPolicy(dataServiceRetryProperties.getNoOfRetries(), new ImmutableMap.Builder<Class<? extends Throwable>, Boolean>() .put(CannotGetJdbcConnectionException.class, true) .put(CannotAcquireLockException.class, true) .put(DeadlockLoserDataAccessException.class, true) .put(OptimisticLockingFailureException.class, true) .put(PessimisticLockingFailureException.class, true) .put(ConcurrencyFailureException.class, true) // Will this work for cases where the write queries timeout on the client? .put(QueryTimeoutException.class, true) .put(TransientDataAccessResourceException.class, true) .put(JpaSystemException.class, true) .build())); final ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(dataServiceRetryProperties.getInitialInterval()); backOffPolicy.setMaxInterval(dataServiceRetryProperties.getMaxInterval()); retryTemplate.setBackOffPolicy(backOffPolicy); }
protected ExponentialBackOffPolicy newInstance() { return new ExponentialBackOffPolicy(); }
protected ExponentialBackOffPolicy createBackOffPolicy() { ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setMultiplier(5.0D); return backOffPolicy; }
ExponentialBackOffPolicy policy = new ExponentialBackOffPolicy(); if (backoff.random()) { policy = new ExponentialRandomBackOffPolicy(); policy.setInitialInterval(min); policy.setMultiplier(multiplier); policy.setMaxInterval(max > min ? max : ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL); if (this.sleeper != null) { policy.setSleeper(this.sleeper);
//import the necessary classes import org.springframework.batch.retry.RetryCallback; import org.springframework.batch.retry.RetryContext; import org.springframework.batch.retry.backoff.ExponentialBackOffPolicy; import org.springframework.batch.retry.policy.SimpleRetryPolicy; import org.springframework.batch.retry.support.RetryTemplate; ... // create the retry template final RetryTemplate template = new RetryTemplate(); template.setRetryPolicy(new SimpleRetryPolicy(5)); final ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(1000L); template.setBackOffPolicy(backOffPolicy); // execute the operation using the retry template template.execute(new RetryCallback<Remote>() { @Override public Remote doWithRetry(final RetryContext context) throws Exception { return (Remote) Naming.lookup("rmi://somehost:2106/MyApp"); } });
public void restart(final int index) throws Exception { //NOSONAR // retry restarting repeatedly, first attempts may fail SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(10, // NOSONAR magic # Collections.singletonMap(Exception.class, true)); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(100); // NOSONAR magic # backOffPolicy.setMaxInterval(1000); // NOSONAR magic # backOffPolicy.setMultiplier(2); // NOSONAR magic # RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(retryPolicy); retryTemplate.setBackOffPolicy(backOffPolicy); retryTemplate.execute(context -> { this.kafkaServers.get(index).startup(); return null; }); }
/** * Constructor. * * @param runAsUserEnabled Flag that tells if job should be run as user specified in the request * @param userCreationEnabled Flag that tells if the user specified should be created * @param executor An executor object used to run jobs * @param hostname Hostname for the node the job is running on * @param registry The metrics registry to use */ public JobKickoffTask( final boolean runAsUserEnabled, final boolean userCreationEnabled, @NotNull final Executor executor, @NotNull final String hostname, @NotNull final Registry registry ) { super(registry); this.isRunAsUserEnabled = runAsUserEnabled; this.isUserCreationEnabled = userCreationEnabled; this.executor = executor; this.hostname = hostname; this.timerId = registry.createId("genie.jobs.tasks.jobKickoffTask.timer"); retryTemplate = new RetryTemplate(); retryTemplate.setBackOffPolicy(new ExponentialBackOffPolicy()); }
@Override public BackOffPolicy createBackOffPolicy(String service) { final ExponentialBackOffPolicy backoffPolicy = new ExponentialBackOffPolicy(); backoffPolicy.setMultiplier(backoffMultiplier); backoffPolicy.setInitialInterval(initialBackoffInterval); backoffPolicy.setMaxInterval(maxInterval); return backoffPolicy; } };
@Configuration public class RetryConfiguration { @Bean RetryTemplate retryTemplate() { RetryTemplate template = new RetryTemplate(); TimeoutRetryPolicy policy = new TimeoutRetryPolicy(); policy.setTimeout(30000L); template.setRetryPolicy(policy); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); template.setBackOffPolicy(backOffPolicy); return template; } }
private ExponentialBackOffPolicy exponentialBackOffPolicy() { ExponentialBackOffPolicy exponentialBackOffPolicy = new ExponentialBackOffPolicy(); exponentialBackOffPolicy.setInitialInterval(initialInterval); exponentialBackOffPolicy.setMaxInterval(maxInterval); exponentialBackOffPolicy.setMultiplier(multiplier); return exponentialBackOffPolicy; }
/** * @return {@link RabbitTemplate} with automatic retry, published confirms * and {@link Jackson2JsonMessageConverter}. */ @Bean public RabbitTemplate rabbitTemplate() { final RabbitTemplate rabbitTemplate = new RabbitTemplate(rabbitConnectionFactory); rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter()); final RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setBackOffPolicy(new ExponentialBackOffPolicy()); rabbitTemplate.setRetryTemplate(retryTemplate); rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> { if (ack) { LOGGER.debug("Message with {} confirmed by broker.", correlationData); } else { LOGGER.error("Broker is unable to handle message with {} : {}", correlationData, cause); } }); return rabbitTemplate; }
@Bean public RetryOperations retryOperations() { RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3, Collections.<Class<? extends Throwable>, Boolean>singletonMap(RedisConnectionFailureException.class, true))); ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); backOffPolicy.setInitialInterval(1000L); backOffPolicy.setMaxInterval(1000L); backOffPolicy.setMultiplier(2); retryTemplate.setBackOffPolicy(backOffPolicy); return retryTemplate; }