public void setRetryPolicy(RetryPolicy retryPolicy) { this.retryPolicy = retryPolicy; delegate.setRetryPolicy(retryPolicy); regular.setRetryPolicy(retryPolicy); }
/** * Apply the retry policy - cannot be used if a custom retry template has been * provided, or the max attempts or back off options or policy have been applied. * @param policy The policy. * @return this. */ public RetryInterceptorBuilder<T> retryPolicy(RetryPolicy policy) { Assert.isNull(this.retryOperations, "cannot set the retry policy when a custom retryOperations has been set"); Assert.isTrue(!this.templateAltered, "cannot set the retry policy if max attempts or back off policy or options changed"); this.retryTemplate.setRetryPolicy(policy); this.retryPolicySet = true; this.templateAltered = true; return this; }
public StatefulRetryOperationsInterceptor() { RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new NeverRetryPolicy()); this.retryOperations = retryTemplate; }
/** * Apply the max attempts - a SimpleRetryPolicy will be used. Cannot be used if a custom retry operations * or retry policy has been set. * @param maxAttempts the max attempts (including the initial attempt). * @return this. */ public RetryInterceptorBuilder<T> maxAttempts(int maxAttempts) { Assert.isNull(this.retryOperations, "cannot alter the retry policy when a custom retryOperations has been set"); Assert.isTrue(!this.retryPolicySet, "cannot alter the retry policy when a custom retryPolicy has been set"); this.simpleRetryPolicy.setMaxAttempts(maxAttempts); this.retryTemplate.setRetryPolicy(this.simpleRetryPolicy); this.templateAltered = true; return this; }
@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; }
/** * Execute a single simulation * @return The sleeps which occurred within the single simulation. */ public List<Long> executeSingleSimulation() { StealingSleeper stealingSleeper = new StealingSleeper(); SleepingBackOffPolicy<?> stealingBackoff = backOffPolicy.withSleeper(stealingSleeper); RetryTemplate template = new RetryTemplate(); template.setBackOffPolicy(stealingBackoff); template.setRetryPolicy(retryPolicy); try { template.execute(new FailingRetryCallback()); } catch(FailingRetryException e) { } catch(Throwable e) { throw new RuntimeException("Unexpected exception", e); } return stealingSleeper.getSleeps(); }
assertInitialState(); retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
private MethodInterceptor getStatelessInterceptor(Object target, Method method, Retryable retryable) { RetryTemplate template = createTemplate(retryable.listeners()); template.setRetryPolicy(getRetryPolicy(retryable)); template.setBackOffPolicy(getBackoffPolicy(retryable.backoff())); return RetryInterceptorBuilder.stateless() .retryOperations(template) .label(retryable.label()) .recoverer(getRecoverer(target, method)) .build(); }
breaker.setOpenTimeout(getOpenTimeout(circuit)); breaker.setResetTimeout(getResetTimeout(circuit)); template.setRetryPolicy(breaker); template.setBackOffPolicy(new NoBackOffPolicy()); String label = circuit.label(); template.setRetryPolicy(policy); template.setBackOffPolicy(getBackoffPolicy(retryable.backoff())); String label = retryable.label();
@Test public void testFailureAndRecovery() throws Exception { final RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new NeverRetryPolicy()); container.setMessageListener(new MessageListener() { @Override
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; }); }
retryableExceptions.put(MessagingException.class, true); retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3, retryableExceptions));
private RetryTemplate createRetryTemplate(String serviceName, HttpRequest request, LoadBalancedRetryPolicy retryPolicy) { RetryTemplate template = new RetryTemplate(); BackOffPolicy backOffPolicy = lbRetryFactory.createBackOffPolicy(serviceName); template.setBackOffPolicy(backOffPolicy == null ? new NoBackOffPolicy() : backOffPolicy); template.setThrowLastExceptionOnExhausted(true); RetryListener[] retryListeners = lbRetryFactory.createRetryListeners(serviceName); if (retryListeners != null && retryListeners.length != 0) { template.setListeners(retryListeners); } template.setRetryPolicy( !lbProperties.isEnabled() || retryPolicy == null ? new NeverRetryPolicy() : new InterceptorRetryPolicy(request, retryPolicy, loadBalancer, serviceName)); return template; } }
advice.setRecoveryCallback(recoverer); RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new SimpleRetryPolicy() {
public StatefulRetryOperationsInterceptor() { RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(new NeverRetryPolicy()); this.retryOperations = retryTemplate; }
@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; }
private void waitFor(BiConsumer<String, CouchbaseBuildDefinition> function, String host, CouchbaseBuildDefinition buildDefinition) { TimeoutRetryPolicy retryPolicy = new TimeoutRetryPolicy(); retryPolicy.setTimeout(THIRTY_SECONDS); FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(ONE_SECOND); RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(retryPolicy); retryTemplate.setThrowLastExceptionOnExhausted(true); retryTemplate.setBackOffPolicy(backOffPolicy); retryTemplate.execute(rc -> { function.accept(host, buildDefinition); return null; }); }
/** * Do not have Spring AMQP re-try messages upon failure, leave it to Camel * @return An advice chain populated with a NeverRetryPolicy */ public final Advice[] getAdviceChain() { RetryTemplate retryRule = new RetryTemplate(); retryRule.setRetryPolicy(new NeverRetryPolicy()); StatefulRetryOperationsInterceptorFactoryBean retryOperation = new StatefulRetryOperationsInterceptorFactoryBean(); retryOperation.setRetryOperations(retryRule); retryOperation.setMessageKeyGenerator(new DefaultKeyGenerator()); return new Advice[] { retryOperation.getObject() }; }
private void waitForContainerToStart() { TimeoutRetryPolicy retryPolicy = new TimeoutRetryPolicy(); retryPolicy.setTimeout(THIRTY_SECONDS); FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(ONE_SECOND); RetryTemplate retryTemplate = new RetryTemplate(); retryTemplate.setRetryPolicy(retryPolicy); retryTemplate.setThrowLastExceptionOnExhausted(true); retryTemplate.setBackOffPolicy(backOffPolicy); retryTemplate.execute(rc -> portInUse(dockerHostname, firstExternalPort())); }
private MethodInterceptor getStatelessInterceptor(Object target, Method method, Retryable retryable) { RetryTemplate template = createTemplate(retryable.listeners()); template.setRetryPolicy(getRetryPolicy(retryable)); template.setBackOffPolicy(getBackoffPolicy(retryable.backoff())); return RetryInterceptorBuilder.stateless() .retryOperations(template) .label(retryable.label()) .recoverer(getRecoverer(target, method)) .build(); }