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

netflix.ocelli.functions.Retrys Maven / Gradle / Ivy

There is a newer version: 0.1.0-rc.2
Show newest version
package netflix.ocelli.functions;

import java.util.concurrent.TimeUnit;

import netflix.ocelli.retrys.ExponentialBackoff;
import rx.Observable;
import rx.functions.Func1;

public abstract class Retrys {
    public static Func1 ALWAYS = new Func1() {
        @Override
        public Boolean call(Throwable t1) {
            return true;
        }
    };
    
    public static Func1 NEVER = new Func1() {
        @Override
        public Boolean call(Throwable t1) {
            return false;
        }
    };
    
    /**
     * Exponential backoff 
     * @param maxRetrys
     * @param timeslice
     * @param units
     * @return
     */
    public static Func1, Observable> exponentialBackoff(final int maxRetrys, final long timeslice, final TimeUnit units) {
        return new ExponentialBackoff(maxRetrys, timeslice, -1, units, ALWAYS);
    }

    /**
     * Bounded exponential backoff
     * @param maxRetrys
     * @param timeslice
     * @param units
     * @return
     */
    public static Func1, Observable> exponentialBackoff(final int maxRetrys, final long timeslice, final TimeUnit units, final long maxDelay) {
        return new ExponentialBackoff(maxRetrys, timeslice, maxDelay, units, ALWAYS);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy