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

functionalj.promise.RetryConfig Maven / Gradle / Ivy

package functionalj.promise;

import java.util.function.Function;

import functionalj.lens.lenses.AnyAccess;
import functionalj.promise.DeferActionBuilder.RetryBuilderTimes;
import functionalj.promise.DeferActionBuilder.WaitRetryBuilder;
import functionalj.promise.DeferActionBuilder.WaitRetryBuilderUnit;

public class RetryConfig implements AnyAccess, RetryBuilderTimes> {
    
    private final int retryTimes;
    
    public WaitConfig times = new WaitConfig<>(this);
    
    RetryConfig(int times) { this.retryTimes = times; }
    
    @Override
    public RetryBuilderTimes applyUnsafe(DeferActionBuilder input) throws Exception {
        return input.retry(retryTimes);
    }
    
    public static class WaitConfig implements AnyAccess, WaitRetryBuilder> {
        
        private final RetryConfig retryConfig;
        
        WaitConfig(RetryConfig retryConfig) {
            this.retryConfig = retryConfig;
        }
        
        @Override
        public WaitRetryBuilder applyUnsafe(DeferActionBuilder input) throws Exception {
            return retryConfig.apply(input).times();
        }
        
        public WaitForConfig waitFor(long period) {
            return new WaitForConfig(this, period);
        }
        
    }
    public static class WaitForConfig implements AnyAccess, WaitRetryBuilderUnit> {
        
        private final WaitConfig waitConfig;
        private final long period;
        
        WaitForConfig(WaitConfig waitConfig, long period) {
            this.waitConfig = waitConfig;
            this.period     = period;
        }
        
        @Override
        public WaitRetryBuilderUnit applyUnsafe(DeferActionBuilder input) throws Exception {
            return waitConfig.apply(input).waitFor(period);
        }
        
        public Function, DeferActionBuilder> seconds = builder -> this.apply(builder).seconds();
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy