org.springframework.retry.backoff.BackOffPolicy Java Examples

The following examples show how to use org.springframework.retry.backoff.BackOffPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RetryLoadBalancerInterceptor.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
private RetryTemplate createRetryTemplate(String serviceName, HttpRequest request,
		LoadBalancedRetryPolicy retryPolicy) {
	RetryTemplate template = new RetryTemplate();
	BackOffPolicy backOffPolicy = this.lbRetryFactory
			.createBackOffPolicy(serviceName);
	template.setBackOffPolicy(
			backOffPolicy == null ? new NoBackOffPolicy() : backOffPolicy);
	template.setThrowLastExceptionOnExhausted(true);
	RetryListener[] retryListeners = this.lbRetryFactory
			.createRetryListeners(serviceName);
	if (retryListeners != null && retryListeners.length != 0) {
		template.setListeners(retryListeners);
	}
	template.setRetryPolicy(!this.lbProperties.isEnabled() || retryPolicy == null
			? new NeverRetryPolicy() : new InterceptorRetryPolicy(request,
					retryPolicy, this.loadBalancer, serviceName));
	return template;
}
 
Example #2
Source File: RetryLoadBalancerInterceptorTest.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public BackOffPolicy createBackOffPolicy(String service) {
	if (this.backOffPolicy == null) {
		return new NoBackOffPolicy();
	}
	else {
		return this.backOffPolicy;
	}
}
 
Example #3
Source File: ExponentialBackoffRetryFactory.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public BackOffPolicy createBackOffPolicy(String service) {
    ExponentialBackOffPolicy exponentialBackOffPolicy = new ExponentialBackOffPolicy();
    exponentialBackOffPolicy.setInitialInterval(1000);
    exponentialBackOffPolicy.setMultiplier(2);
    exponentialBackOffPolicy.setMaxInterval(10000);
    return exponentialBackOffPolicy;
}
 
Example #4
Source File: ExponentialRandomBackoffRetryFactory.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public BackOffPolicy createBackOffPolicy(String service) {
    ExponentialRandomBackOffPolicy exponentialRandomBackOffPolicy = new ExponentialRandomBackOffPolicy();
    exponentialRandomBackOffPolicy.setInitialInterval(1000);
    exponentialRandomBackOffPolicy.setMultiplier(2);
    exponentialRandomBackOffPolicy.setMaxInterval(10000);
    return exponentialRandomBackOffPolicy;
}
 
Example #5
Source File: SpringRetryConfigBuilder.java    From spring-cloud-circuitbreaker with Apache License 2.0 4 votes vote down vote up
BackOffPolicy getBackOffPolicy() {
	return backOffPolicy;
}
 
Example #6
Source File: SpringRetryConfigBuilder.java    From spring-cloud-circuitbreaker with Apache License 2.0 4 votes vote down vote up
void setBackOffPolicy(BackOffPolicy backOffPolicy) {
	this.backOffPolicy = backOffPolicy;
}
 
Example #7
Source File: RetryLoadBalancerInterceptorTest.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
MyLoadBalancedRetryFactory(LoadBalancedRetryPolicy loadBalancedRetryPolicy,
		BackOffPolicy backOffPolicy) {
	this(loadBalancedRetryPolicy);
	this.backOffPolicy = backOffPolicy;
}
 
Example #8
Source File: RetryLoadBalancerInterceptorTest.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
MyLoadBalancedRetryFactory(LoadBalancedRetryPolicy loadBalancedRetryPolicy,
		BackOffPolicy backOffPolicy, RetryListener[] retryListeners) {
	this(loadBalancedRetryPolicy, backOffPolicy);
	this.retryListeners = retryListeners;
}
 
Example #9
Source File: FixedBackoffRetryFactory.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public BackOffPolicy createBackOffPolicy(String service) {
    FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
    fixedBackOffPolicy.setBackOffPeriod(2000);
    return fixedBackOffPolicy;
}
 
Example #10
Source File: LoadBalancedRetryFactory.java    From spring-cloud-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@link BackOffPolicy} for a given service.
 * @param service The service to create the {@link BackOffPolicy} for.
 * @return The {@link BackOffPolicy}.
 */
default BackOffPolicy createBackOffPolicy(String service) {
	return new NoBackOffPolicy();
}