forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue ReactiveX#197: Option to auto transition to half open (Reactive…
…X#216) * Issue ReactiveX#197: Option to auto transition to half open * Issue ReactiveX#197: Option to auto transition, tidy up * Issue ReactiveX#197: Option to auto transition, reduce number of cb instances * Issue ReactiveX#197 Open to auto transition to half open, PR changes * Issue ReactiveX#197 Open to auto transition to half open, PR changes 2 * Issue ReactiveX#197 tidy up config after rebase
- Loading branch information
Showing
4 changed files
with
341 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...reaker/src/main/java/io/github/resilience4j/circuitbreaker/internal/AutoTransitioner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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<ScheduledExecutorService> executorService = Lazy.of( | ||
Executors::newSingleThreadScheduledExecutor); | ||
|
||
private AutoTransitioner() { | ||
} | ||
|
||
public static void scheduleAutoTransition(Runnable transition, Duration waitDurationInOpenState) { | ||
executorService.get().schedule( | ||
transition, | ||
waitDurationInOpenState.toMillis(), | ||
TimeUnit.MILLISECONDS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.