All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mageddo.kafka.client.RetryPolicyConverter Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.mageddo.kafka.client;

import java.time.Duration;
import java.util.ArrayList;

public class RetryPolicyConverter {
  public static net.jodah.failsafe.RetryPolicy retryPolicyToFailSafeRetryPolicy(RetryPolicy retryPolicy) {
    final net.jodah.failsafe.RetryPolicy failSafeRetryPolicy = new net.jodah.failsafe.RetryPolicy<>();
    failSafeRetryPolicy.withMaxRetries(retryPolicy.getMaxTries());
    if(retryPolicy.getMaxDelay() != null && !retryPolicy.getMaxDelay().equals(Duration.ZERO)){
        failSafeRetryPolicy.withDelay(retryPolicy.getDelay());
    }

    if(retryPolicy.getMaxDelay() != null){
      failSafeRetryPolicy.withMaxDuration(retryPolicy.getMaxDelay());
    }
    if(!retryPolicy.getRetryableExceptions().isEmpty()){
        failSafeRetryPolicy.handle(new ArrayList<>(retryPolicy.getRetryableExceptions()));
    }
    return failSafeRetryPolicy;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy