io.github.anicolaspp.Hx.commands.Command Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of HxFactory Show documentation
Show all versions of HxFactory Show documentation
Factory library to create and run Hystrix commands with simplicity
package io.github.anicolaspp.Hx.commands;
import io.github.anicolaspp.Hx.BreakerSupplier;
import io.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));
}
}
}
}