io.github.resilience4j.circuitbreaker.internal.AutoTransitioner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resilience4j-circuitbreaker Show documentation
Show all versions of resilience4j-circuitbreaker Show documentation
Resilience4j is a lightweight, easy-to-use fault tolerance library designed for Java8 and functional programming
package io.github.resilience4j.circuitbreaker.internal;
import io.vavr.Lazy;
import java.time.Duration;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* Schedules tasks to be completed after a duration. E.g. to automatically transition from open to half open state
* when automaticTransitionFromOpenToHalfOpenEnabled config property is set to true.
*/
public class AutoTransitioner {
private static final Lazy executorService = Lazy.of(
Executors::newSingleThreadScheduledExecutor);
private AutoTransitioner() {
}
public static void scheduleAutoTransition(Runnable transition, Duration waitDurationInOpenState) {
executorService.get().schedule(
transition,
waitDurationInOpenState.toMillis(),
TimeUnit.MILLISECONDS);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy