Zero-allocation Circuit Breaker pattern for isolating faulty handlers or peripheral links. Thread-safe lock-free state transitions.
More...
#include <CircuitBreaker.hpp>
|
| bool | allowExecution () noexcept |
| | Check if execution is permitted under current circuit state. Automatically transitions from Open to HalfOpen if recovery cooldown has elapsed.
|
| |
| | CircuitBreaker () noexcept=default |
| |
| template<typename Callable > |
| bool | execute (Callable &&fn) |
| | Execute a protected callable through the circuit breaker.
|
| |
| uint32_t | failureCount () const noexcept |
| | Current consecutive failure count.
|
| |
| void | recordFailure () noexcept |
| | Record a failed operation. Increments failure counter and trips circuit Open if threshold is reached.
|
| |
| void | recordSuccess () noexcept |
| | Record a successful operation execution. Resets consecutive failure counter and restores Closed state from HalfOpen.
|
| |
| void | reset () noexcept |
| | Manually reset the circuit breaker to normal Closed state.
|
| |
| CircuitState | state () const noexcept |
| | Current state of the circuit breaker.
|
| |
| void | trip () noexcept |
| | Manually trip the circuit breaker open.
|
| |
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
class corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >
Zero-allocation Circuit Breaker pattern for isolating faulty handlers or peripheral links. Thread-safe lock-free state transitions.
- Template Parameters
-
| FailureThreshold | Consecutive failures before tripping open (default: 3). |
| RecoveryTimeoutMs | Cooldown duration in milliseconds before moving to HalfOpen (default: 500ms). |
◆ CircuitBreaker()
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
◆ allowExecution()
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
Check if execution is permitted under current circuit state. Automatically transitions from Open to HalfOpen if recovery cooldown has elapsed.
◆ execute()
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
template<typename Callable >
Execute a protected callable through the circuit breaker.
- Template Parameters
-
| Callable | Function or lambda returning bool (true = success, false = failure). |
- Parameters
-
| fn | Callable to invoke if circuit is not open. |
- Returns
- true if executed and succeeded, false if rejected or failed.
◆ failureCount()
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
Current consecutive failure count.
◆ recordFailure()
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
Record a failed operation. Increments failure counter and trips circuit Open if threshold is reached.
◆ recordSuccess()
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
Record a successful operation execution. Resets consecutive failure counter and restores Closed state from HalfOpen.
◆ reset()
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
Manually reset the circuit breaker to normal Closed state.
◆ state()
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
Current state of the circuit breaker.
◆ trip()
template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
Manually trip the circuit breaker open.
The documentation for this class was generated from the following file: