Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs > Class Template Reference

Zero-allocation Circuit Breaker pattern for isolating faulty handlers or peripheral links. Thread-safe lock-free state transitions. More...

#include <CircuitBreaker.hpp>

+ Collaboration diagram for corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >:

Public Member Functions

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.
 

Detailed Description

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
FailureThresholdConsecutive failures before tripping open (default: 3).
RecoveryTimeoutMsCooldown duration in milliseconds before moving to HalfOpen (default: 500ms).

Constructor & Destructor Documentation

◆ CircuitBreaker()

template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >::CircuitBreaker ( )
defaultnoexcept

Member Function Documentation

◆ allowExecution()

template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
bool corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >::allowExecution ( )
inlinenoexcept

Check if execution is permitted under current circuit state. Automatically transitions from Open to HalfOpen if recovery cooldown has elapsed.

+ Here is the caller graph for this function:

◆ execute()

template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
template<typename Callable >
bool corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >::execute ( Callable &&  fn)
inline

Execute a protected callable through the circuit breaker.

Template Parameters
CallableFunction or lambda returning bool (true = success, false = failure).
Parameters
fnCallable to invoke if circuit is not open.
Returns
true if executed and succeeded, false if rejected or failed.
+ Here is the call graph for this function:

◆ failureCount()

template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
uint32_t corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >::failureCount ( ) const
inlinenoexcept

Current consecutive failure count.

◆ recordFailure()

template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
void corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >::recordFailure ( )
inlinenoexcept

Record a failed operation. Increments failure counter and trips circuit Open if threshold is reached.

+ Here is the caller graph for this function:

◆ recordSuccess()

template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
void corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >::recordSuccess ( )
inlinenoexcept

Record a successful operation execution. Resets consecutive failure counter and restores Closed state from HalfOpen.

+ Here is the caller graph for this function:

◆ reset()

template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
void corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >::reset ( )
inlinenoexcept

Manually reset the circuit breaker to normal Closed state.

◆ state()

template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
CircuitState corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >::state ( ) const
inlinenoexcept

Current state of the circuit breaker.

◆ trip()

template<uint32_t FailureThreshold = 3, uint32_t RecoveryTimeoutMs = 500>
void corium::safety::CircuitBreaker< FailureThreshold, RecoveryTimeoutMs >::trip ( )
inlinenoexcept

Manually trip the circuit breaker open.


The documentation for this class was generated from the following file: