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));
      }
  • 相关阅读:
    iframe显示高度自适应 兼容多浏览器
    Asp.Net在Global.asax中实现URL 的重写
    文件流下载 ASP.NET
    Asp.Net实现全局定时器功能
    C#中获取本机IP地址,子网掩码,网关地址
    Asp.Net缓存实例
    Google API 天气数据缓存到一个XML中
    获取服务器信息
    C# NET 中英混合字符串截断实例
    Asp.Net实现长文章分页显示功能
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/9254307.html
Copyright © 2011-2022 走看看