Search in sources :

Example 1 with NoBackOffPolicy

use of cn.taketoday.retry.backoff.NoBackOffPolicy in project today-infrastructure by TAKETODAY.

the class AnnotationAwareRetryOperationsInterceptor method getStatefulInterceptor.

private MethodInterceptor getStatefulInterceptor(Object target, Method method, Retryable retryable) {
    RetryTemplate template = createTemplate(retryable.listeners());
    template.setRetryContextCache(this.retryContextCache);
    CircuitBreaker circuit = AnnotatedElementUtils.findMergedAnnotation(method, CircuitBreaker.class);
    if (circuit == null) {
        circuit = findAnnotationOnTarget(target, method, CircuitBreaker.class);
    }
    if (circuit != null) {
        RetryPolicy policy = getRetryPolicy(circuit);
        CircuitBreakerRetryPolicy breaker = new CircuitBreakerRetryPolicy(policy);
        breaker.setOpenTimeout(getOpenTimeout(circuit));
        breaker.setResetTimeout(getResetTimeout(circuit));
        template.setRetryPolicy(breaker);
        template.setBackOffPolicy(new NoBackOffPolicy());
        String label = circuit.label();
        if (!StringUtils.hasText(label)) {
            label = method.toGenericString();
        }
        return RetryInterceptorBuilder.circuitBreaker().keyGenerator(new FixedKeyGenerator("circuit")).retryOperations(template).recoverer(getRecoverer(target, method)).label(label).build();
    }
    RetryPolicy policy = getRetryPolicy(retryable);
    template.setRetryPolicy(policy);
    template.setBackOffPolicy(getBackoffPolicy(retryable.backoff()));
    String label = retryable.label();
    return RetryInterceptorBuilder.stateful().keyGenerator(this.methodArgumentsKeyGenerator).newMethodArgumentsIdentifier(this.newMethodArgumentsIdentifier).retryOperations(template).label(label).recoverer(getRecoverer(target, method)).build();
}
Also used : FixedKeyGenerator(cn.taketoday.retry.interceptor.FixedKeyGenerator) RetryTemplate(cn.taketoday.retry.support.RetryTemplate) NoBackOffPolicy(cn.taketoday.retry.backoff.NoBackOffPolicy) CircuitBreakerRetryPolicy(cn.taketoday.retry.policy.CircuitBreakerRetryPolicy) RetryPolicy(cn.taketoday.retry.RetryPolicy) ExpressionRetryPolicy(cn.taketoday.retry.policy.ExpressionRetryPolicy) SimpleRetryPolicy(cn.taketoday.retry.policy.SimpleRetryPolicy) CircuitBreakerRetryPolicy(cn.taketoday.retry.policy.CircuitBreakerRetryPolicy)

Example 2 with NoBackOffPolicy

use of cn.taketoday.retry.backoff.NoBackOffPolicy in project today-infrastructure by TAKETODAY.

the class RetryTemplateBuilder method noBackoff.

/**
 * Do not pause between attempts, retry immediately.
 *
 * @return this
 * @see NoBackOffPolicy
 */
public RetryTemplateBuilder noBackoff() {
    Assert.isNull(this.backOffPolicy, "You have already selected backoff policy");
    this.backOffPolicy = new NoBackOffPolicy();
    return this;
}
Also used : NoBackOffPolicy(cn.taketoday.retry.backoff.NoBackOffPolicy)

Example 3 with NoBackOffPolicy

use of cn.taketoday.retry.backoff.NoBackOffPolicy in project today-infrastructure by TAKETODAY.

the class RetryTemplateBuilder method build.

/* ---------------- Building -------------- */
/**
 * Finish configuration and build resulting {@link RetryTemplate}. For default
 * behaviour and concurrency note see class-level doc of {@link RetryTemplateBuilder}.
 * The {@code retryPolicy} of the returned {@link RetryTemplate} is always an instance
 * of {@link CompositeRetryPolicy}, that consists of one base policy, and of
 * {@link BinaryExceptionClassifierRetryPolicy}. The motivation is: whatever base
 * policy we use, exception classification is extremely recommended.
 *
 * @return new instance of {@link RetryTemplate}
 */
public RetryTemplate build() {
    RetryTemplate retryTemplate = new RetryTemplate();
    // Exception classifier
    BinaryExceptionClassifier exceptionClassifier = classifierBuilder != null ? classifierBuilder.build() : BinaryExceptionClassifier.defaultClassifier();
    if (this.baseRetryPolicy == null) {
        this.baseRetryPolicy = new MaxAttemptsRetryPolicy();
    }
    CompositeRetryPolicy finalPolicy = new CompositeRetryPolicy();
    finalPolicy.setPolicies(new RetryPolicy[] { baseRetryPolicy, new BinaryExceptionClassifierRetryPolicy(exceptionClassifier) });
    retryTemplate.setRetryPolicy(finalPolicy);
    if (this.backOffPolicy == null) {
        this.backOffPolicy = new NoBackOffPolicy();
    }
    retryTemplate.setBackOffPolicy(this.backOffPolicy);
    if (this.listeners != null) {
        retryTemplate.setListeners(this.listeners.toArray(new RetryListener[0]));
    }
    return retryTemplate;
}
Also used : BinaryExceptionClassifier(cn.taketoday.classify.BinaryExceptionClassifier) MaxAttemptsRetryPolicy(cn.taketoday.retry.policy.MaxAttemptsRetryPolicy) BinaryExceptionClassifierRetryPolicy(cn.taketoday.retry.policy.BinaryExceptionClassifierRetryPolicy) NoBackOffPolicy(cn.taketoday.retry.backoff.NoBackOffPolicy) CompositeRetryPolicy(cn.taketoday.retry.policy.CompositeRetryPolicy) RetryListener(cn.taketoday.retry.RetryListener)

Example 4 with NoBackOffPolicy

use of cn.taketoday.retry.backoff.NoBackOffPolicy in project today-framework by TAKETODAY.

the class RetryTemplateBuilder method noBackoff.

/**
 * Do not pause between attempts, retry immediately.
 *
 * @return this
 * @see NoBackOffPolicy
 */
public RetryTemplateBuilder noBackoff() {
    Assert.isNull(this.backOffPolicy, "You have already selected backoff policy");
    this.backOffPolicy = new NoBackOffPolicy();
    return this;
}
Also used : NoBackOffPolicy(cn.taketoday.retry.backoff.NoBackOffPolicy)

Example 5 with NoBackOffPolicy

use of cn.taketoday.retry.backoff.NoBackOffPolicy in project today-framework by TAKETODAY.

the class RetryTemplateBuilder method build.

/* ---------------- Building -------------- */
/**
 * Finish configuration and build resulting {@link RetryTemplate}. For default
 * behaviour and concurrency note see class-level doc of {@link RetryTemplateBuilder}.
 * The {@code retryPolicy} of the returned {@link RetryTemplate} is always an instance
 * of {@link CompositeRetryPolicy}, that consists of one base policy, and of
 * {@link BinaryExceptionClassifierRetryPolicy}. The motivation is: whatever base
 * policy we use, exception classification is extremely recommended.
 *
 * @return new instance of {@link RetryTemplate}
 */
public RetryTemplate build() {
    RetryTemplate retryTemplate = new RetryTemplate();
    // Exception classifier
    BinaryExceptionClassifier exceptionClassifier = classifierBuilder != null ? classifierBuilder.build() : BinaryExceptionClassifier.defaultClassifier();
    if (this.baseRetryPolicy == null) {
        this.baseRetryPolicy = new MaxAttemptsRetryPolicy();
    }
    CompositeRetryPolicy finalPolicy = new CompositeRetryPolicy();
    finalPolicy.setPolicies(new RetryPolicy[] { baseRetryPolicy, new BinaryExceptionClassifierRetryPolicy(exceptionClassifier) });
    retryTemplate.setRetryPolicy(finalPolicy);
    if (this.backOffPolicy == null) {
        this.backOffPolicy = new NoBackOffPolicy();
    }
    retryTemplate.setBackOffPolicy(this.backOffPolicy);
    if (this.listeners != null) {
        retryTemplate.setListeners(this.listeners.toArray(new RetryListener[0]));
    }
    return retryTemplate;
}
Also used : BinaryExceptionClassifier(cn.taketoday.classify.BinaryExceptionClassifier) MaxAttemptsRetryPolicy(cn.taketoday.retry.policy.MaxAttemptsRetryPolicy) BinaryExceptionClassifierRetryPolicy(cn.taketoday.retry.policy.BinaryExceptionClassifierRetryPolicy) NoBackOffPolicy(cn.taketoday.retry.backoff.NoBackOffPolicy) CompositeRetryPolicy(cn.taketoday.retry.policy.CompositeRetryPolicy) RetryListener(cn.taketoday.retry.RetryListener)

Aggregations

NoBackOffPolicy (cn.taketoday.retry.backoff.NoBackOffPolicy)6 BinaryExceptionClassifier (cn.taketoday.classify.BinaryExceptionClassifier)2 RetryListener (cn.taketoday.retry.RetryListener)2 RetryPolicy (cn.taketoday.retry.RetryPolicy)2 FixedKeyGenerator (cn.taketoday.retry.interceptor.FixedKeyGenerator)2 BinaryExceptionClassifierRetryPolicy (cn.taketoday.retry.policy.BinaryExceptionClassifierRetryPolicy)2 CircuitBreakerRetryPolicy (cn.taketoday.retry.policy.CircuitBreakerRetryPolicy)2 CompositeRetryPolicy (cn.taketoday.retry.policy.CompositeRetryPolicy)2 ExpressionRetryPolicy (cn.taketoday.retry.policy.ExpressionRetryPolicy)2 MaxAttemptsRetryPolicy (cn.taketoday.retry.policy.MaxAttemptsRetryPolicy)2 SimpleRetryPolicy (cn.taketoday.retry.policy.SimpleRetryPolicy)2 RetryTemplate (cn.taketoday.retry.support.RetryTemplate)2