zoukankan      html  css  js  c++  java
  • SimpleRetryTemplateSupplier

    import java.util.Map;
    
    import org.springframework.retry.backoff.FixedBackOffPolicy;
    import org.springframework.retry.policy.SimpleRetryPolicy;
    import org.springframework.retry.support.RetryTemplate;
    
    import com.citi.simpliciti.tempest.util.RawSerializableSupplier;
    
    public class SimpleRetryTemplateSupplier implements RawSerializableSupplier<RetryTemplate> {
    
      private int maxAttempts;
      private int backOffPeriod;
      private Map<Class<? extends Throwable>, Boolean> retryableExceptions;
    
      private transient RetryTemplate retryTemplate;
    
      public SimpleRetryTemplateSupplier(int maxAttempts, int backOffPeriod,
          Map<Class<? extends Throwable>, Boolean> retryableExceptions) {
        this.maxAttempts = maxAttempts;
        this.backOffPeriod = backOffPeriod;
        this.retryableExceptions = retryableExceptions;
      }
    
    
      @Override
      public RetryTemplate get() {
        if (retryTemplate == null) {
          SimpleRetryPolicy policy = new SimpleRetryPolicy(maxAttempts, retryableExceptions);
    
          FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
          fixedBackOffPolicy.setBackOffPeriod(backOffPeriod);
    
          retryTemplate = new RetryTemplate();
          retryTemplate.setRetryPolicy(policy);
          retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
        }
        return retryTemplate;
    
      }
    }
     @Bean
      public SimpleRetryTemplateSupplier tpsPositionRetryTemplateSupplier() {
        return new SimpleRetryTemplateSupplier(maxAttempts, backOffPeriod,
            ImmutableMap.of(RestClientException.class, true, JsonSyntaxException.class, true));
      }
  • 相关阅读:
    HDU 4081 Peach Blossom Spring (最小生成树+dfs)
    查看u盘格式
    eclipse使用外部maven时multiModuleProjectDirectory错误解决
    Centos更换yum源,安装ssh server
    gerrit push配置
    netstat
    java多维数组
    RESTful架构3--开发实战
    RESTful架构2--架构详解
    RESTful架构1--架构理解
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/9254307.html
Copyright © 2011-2022 走看看