https://github.com/battila7/chains
Dead simple circuit breaker written just for fun.
https://github.com/battila7/chains
Last synced: about 2 months ago
JSON representation
Dead simple circuit breaker written just for fun.
- Host: GitHub
- URL: https://github.com/battila7/chains
- Owner: battila7
- Created: 2017-07-14T19:35:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-15T13:53:50.000Z (almost 8 years ago)
- Last Synced: 2025-02-16T14:53:27.402Z (4 months ago)
- Language: Java
- Size: 56.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Chains
Dead simple circuit breaker written just for fun.
Chains features a three-state circuit breaker mechanism with the ability to run calls synchronously or asynchronously.
## Usage
First create a `CircuitDescriptor` that describes the attributes of a circuit, most importantly a `ThrowingRunnable`:
~~~~Java
final CircuitDescriptor descriptor = CircuitDescriptor.wrapping(() -> { throw new NullPointerException(); })
.withThreshold(3)
.withDelay(Duration.of(1, MINUTES))
.build();
~~~~Then construct the actual `Circuit` using the previously created descriptor:
~~~~Java
final Circuit circuit = CircuitFactory.fromDescriptor(descriptor);
~~~~Yaaay! You're now able to dispatch calls through the circuit!
~~~~Java
circuit.executeSync().ifPresent(System.out::println);
~~~~If you're using async calls too (through `Circuit.executeAsync()`), then don't forget to call
~~~~Java
Chains.shutdown();
~~~~somewhere at the end of your application.