Fault tolerance library for java
<dependency>
<groupId>io.github.hadielmougy</groupId>
<artifactId>shield</artifactId>
<version>0.1.2</version>
</dependency>
final Supplier<Void> throttler = Shield.decorate(target)
.with(Interceptor.throttler()
.requests(1)
.maxWaitMillis(500))
.build();
final Supplier<Void> limiter = Shield.decorate(target)
.with(Interceptor.rateLimiter()
.rate(1))
.build();
final Supplier<Void> decorated = Shield.decorate(target)
.with(Interceptor.timeout().waitMillis(1100))
.with(Interceptor.retry().delayMillis(1000).maxRetries(5))
.build();
final Retry retry = Interceptor.retry()
.delayMillis(500)
.maxRetries(3)
.onException(IllegalArgumentException.class);
// count based
final Supplier<Void> comp = Shield.decorate( component)
.with(Interceptor.circuitBreaker()
.failureRateThreshold(50)
.slidingWindowSize(4)
.waitDurationInOpenState(Duration.ofSeconds(1))
.slidingWindowType(CircuitBreaker.WindowType.COUNT_BASED))
.build();
// time based
final Supplier<Void> comp = Shield.decorate(target)
.with(Interceptor.circuitBreaker()
.failureRateThreshold(50)
.slidingWindowSize(1)
.waitDurationInOpenState(Duration.ofSeconds(1))
.slidingWindowType(CircuitBreaker.WindowType.TIME_BASED))
.build();
final Supplier<Void> decorated = Shield.decorate(() -> ...)
.with(retry)
.with(...)
.build();
decorated.get();