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

com.github.anicolaspp.Hx.commands.Command Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package com.github.anicolaspp.Hx.commands;

import com.github.anicolaspp.Hx.BreakerSupplier;
import com.github.anicolaspp.Hx.Setters.CommandSetter;
import com.netflix.hystrix.HystrixCommand;

import java.util.function.Supplier;

public class Command {
    
    private Command() { }
    
    public static  HystrixCommand create(String name, BreakerSupplier fn) {
        return new SingleCommand<>(fn, CommandSetter.getSetterFor(name));
    }
    
    public static  HystrixCommand create(String name, BreakerSupplier fn, int timeoutInMilliseconds) {
        return new SingleCommand<>(fn, CommandSetter.getSetterFor(name, timeoutInMilliseconds));
    }
    
    public static  HystrixCommand fromSetter(HystrixCommand.Setter setter, BreakerSupplier fn) {
        return new SingleCommand<>(fn, setter);
    }
    
    public static class WithFallback {
        public static  HystrixCommand create(String name, BreakerSupplier fn, Supplier fallback) {
            return new CommandWithFallback<>(fn, fallback, CommandSetter.getSetterFor(name));
        }
    
        public static  HystrixCommand create(String name, BreakerSupplier fn, Supplier fallback, int timeoutInMilliseconds) {
            return new CommandWithFallback<>(fn, fallback, CommandSetter.getSetterFor(name, timeoutInMilliseconds));
        }
    }
    
    public static class WithCacheContext {
        
        public static class WithCacheKey {
            
            public static   HystrixCommand create(String cacheKey,
                                                                  String commandName,
                                                                  BreakerSupplier supplier) {
                
                return new CacheCommand<>(cacheKey, supplier, CommandSetter.getSetterFor(commandName));
            }
    
            public static  HystrixCommand create(String cacheKey,
                                                                      String commandName,
                                                                      BreakerSupplier supplier,
                                                                      Supplier fallback) {
                
                return new CacheCommandWithFallback<>(cacheKey, supplier, fallback, CommandSetter.getSetterFor(commandName));
            }
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy