public CircuitBreakerFilter(CircuitBreakerSettings settings, IExceptionFilter exceptionFilter) { _settings = settings; _exceptionFilter = exceptionFilter; _behavior = new ClosedBehavior(this); }
void ICircuitBreaker.Open(Exception exception, ICircuitBreakerBehavior behavior, IEnumerator <TimeSpan> timeoutEnumerator) { if (timeoutEnumerator == null) { timeoutEnumerator = _settings.ResetTimeout.GetEnumerator(); } Interlocked.CompareExchange(ref _behavior, new OpenBehavior(this, exception, timeoutEnumerator), behavior); }
Task ICircuitBreaker.Close(ICircuitBreakerBehavior behavior) { var closedBehavior = new ClosedBehavior(this); Interlocked.CompareExchange(ref _behavior, closedBehavior, behavior); if (_behavior == closedBehavior) { return(_settings.Router?.PublishCircuitBreakerClosed() ?? TaskUtil.Completed); } return(TaskUtil.Completed); }
Task ICircuitBreaker.Open(Exception exception, ICircuitBreakerBehavior behavior, IEnumerator <TimeSpan> timeoutEnumerator) { if (timeoutEnumerator == null) { timeoutEnumerator = _settings.ResetTimeout.GetEnumerator(); } var openBehavior = new OpenBehavior(this, exception, timeoutEnumerator); Interlocked.CompareExchange(ref _behavior, openBehavior, behavior); if (_behavior == openBehavior) { return(_settings.Router?.PublishCircuitBreakerOpened(exception) ?? TaskUtil.Completed); } return(TaskUtil.Completed); }
void ICircuitBreaker.ClosePartially(Exception exception, IEnumerator <TimeSpan> timeoutEnumerator, ICircuitBreakerBehavior behavior) { Interlocked.CompareExchange(ref _behavior, new HalfOpenBehavior(this, exception, timeoutEnumerator), behavior); }
void ICircuitBreaker.Close(ICircuitBreakerBehavior behavior) { Interlocked.CompareExchange(ref _behavior, new ClosedBehavior(this), behavior); }
public CircuitBreakerFilter(CircuitBreakerSettings settings) { _settings = settings; _behavior = new ClosedBehavior(this); }