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

io.github.resilience4j.circuitbreaker.internal.AutoTransitioner Maven / Gradle / Ivy

Go to download

Resilience4j is a lightweight, easy-to-use fault tolerance library designed for Java8 and functional programming

There is a newer version: 2.2.0
Show newest version
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