forked from Netflix/Hystrix
-
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.
Hystrix.reset for lifecycle management
I'm changing the design from the previous commits so it's more abstract and can handle any type of resources needing cleanup, not just threadpools. ReactiveX/RxJava#45
- Loading branch information
1 parent
324d03f
commit 976f2fb
Showing
5 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.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,48 @@ | ||
package com.netflix.hystrix; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Lifecycle management of Hystrix. | ||
*/ | ||
public class Hystrix { | ||
|
||
/** | ||
* Reset state and release resources in use (such as thread-pools). | ||
* <p> | ||
* NOTE: This can result in race conditions if HystrixCommands are concurrently being executed. | ||
* </p> | ||
*/ | ||
public static void reset() { | ||
// shutdown thread-pools | ||
HystrixThreadPool.Factory.shutdown(); | ||
_reset(); | ||
} | ||
|
||
/** | ||
* Reset state and release resources in use (such as threadpools) and wait for completion. | ||
* <p> | ||
* NOTE: This can result in race conditions if HystrixCommands are concurrently being executed. | ||
* </p> | ||
* | ||
* @param time time to wait for thread-pools to shutdown | ||
* @param unit {@link TimeUnit} for <pre>time</pre> to wait for thread-pools to shutdown | ||
*/ | ||
public static void reset(long time, TimeUnit unit) { | ||
// shutdown thread-pools | ||
HystrixThreadPool.Factory.shutdown(time, unit); | ||
_reset(); | ||
} | ||
|
||
/** | ||
* Reset logic that doesn't have time/TimeUnit arguments. | ||
*/ | ||
private static void _reset() { | ||
// clear metrics | ||
HystrixCommandMetrics.reset(); | ||
// clear collapsers | ||
HystrixCollapser.reset(); | ||
// clear circuit breakers | ||
HystrixCircuitBreaker.Factory.reset(); | ||
} | ||
} |
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
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
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
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