public CircuitBreaker(ICircuitBreakerStateStore circuitBreakerStateStore, IEventLogger eventLogger)
 {
     _circuitBreakerStateStore = circuitBreakerStateStore;
     _eventLogger                  = eventLogger;
     OpenToHalfOpenWaitTime        = TimeSpan.FromMilliseconds(500);
     SuccessfulOperationsThreshold = 5;
 }
Example #2
0
 public CircuitBreaker(string resource, int openToHalfOpenWaitTimeInMilliseconds, ILogger logger)
 {
     stateStore             = CircuitBreakerStateStoreFactory.GetCircuitBreakerStateStore(resource);
     resourceName           = resource;
     _logger                = logger;
     openToHalfOpenWaitTime = new TimeSpan(0, 0, 0, 0, openToHalfOpenWaitTimeInMilliseconds);
 }
Example #3
0
        /// <summary>
        /// A breaker that will govern an ICircuit
        /// </summary>
        /// <param name="circuit"></param>
        public Breaker(ICircuit circuit)
        {
            Circuit = circuit;

            stateStore =
                CircuitBreakerStateStoreFactory
                .GetCircuitBreakerStateStore(Circuit);
        }
Example #4
0
        public Luffy UseCircuitBreaker(CircuitBreakerOptions circuitBreakerOptions, ICircuitBreakerStateStore stateStore = null)
        {
            _circuitBreakerOptions = circuitBreakerOptions;

            if (stateStore != null)
            {
                _circuitBreakerStateStore = stateStore;
            }

            return(this);
        }
Example #5
0
        public CircuitSwitchTests()
        {
            ICircuitBreakerStateStore circuitBreakerStateStore = CircuitBreakerStateStoreFactory.GetCircuitBreakerStateStore();
            IEventLogger eventLogger = new EventLogger();

            circuitBreaker = new CircuitBreaker(circuitBreakerStateStore, eventLogger);

            failingAction  = () => { throw new Exception(); };
            secondryAction = () => { Console.WriteLine("Nothing to see here"); };

            sut = new CircuitSwitch(circuitBreaker, eventLogger);
        }
Example #6
0
        public CircuitSwitchIntegrationTests()
        {
            ICircuitBreakerStateStore circuitBreakerStateStore = CircuitBreakerStateStoreFactory.GetCircuitBreakerStateStore();
            IEventLogger eventLogger = new EventLogger();

            circuitBreaker = new CircuitBreaker(circuitBreakerStateStore, eventLogger);

            sut = new CircuitSwitch(circuitBreaker, eventLogger);

            var conn = ConnectionMultiplexer.Connect("localhost");

            redisService     = (IDummyService) new RedisParameterCachingService(conn);
            dummyServiceMock = new Mock <IDummyService>();
        }
Example #7
0
        public CircuitBreaker(ICircuitBreakerStateStore stateStore,
                              CircuitBreakerOptions circuitBreakerOptions,
                              ILogger <CircuitBreaker> logger,
                              ICircuitBreakerExceptionEvaluator exceptionEvaluator)
        {
            if (circuitBreakerOptions is null)
            {
                throw new ArgumentNullException(nameof(circuitBreakerOptions));
            }

            _stateStore                                = stateStore ?? throw new ArgumentNullException(nameof(stateStore));
            _logger                                    = logger ?? throw new ArgumentNullException(nameof(logger));
            _exceptionEvaluator                        = exceptionEvaluator ?? throw new ArgumentNullException(nameof(exceptionEvaluator));
            _openToHalfOpenWaitTime                    = TimeSpan.FromSeconds(circuitBreakerOptions.OpenToHalfOpenWaitTimeInSeconds);
            _concurrentHalfOpenAttempts                = circuitBreakerOptions.ConcurrentHalfOpenAttempts;
            _numberOfFailuresBeforeOpen                = circuitBreakerOptions.NumberOfFailuresBeforeOpen;
            _numberOfHalfOpenSuccessesToClose          = circuitBreakerOptions.NumberOfHalfOpenSuccessesToClose;
            _timeOpenBeforeCriticalFailureNotification = TimeSpan.FromSeconds(circuitBreakerOptions.SecondsOpenBeforeCriticalFailureNotification);
            _halfOpenSemaphore                         = new SemaphoreSlim(_concurrentHalfOpenAttempts, _concurrentHalfOpenAttempts);
            _timer = new Timer(CriticalFailureNotification);
        }
Example #8
0
 public CircuitBreaker(ICircuitBreakerStateStore circuitBreakerStateStore)
 {
     _circuitBreakerStateStore = circuitBreakerStateStore;
 }
Example #9
0
 public CircuitBreakerHelper(CircuitBreakerOptions circuitBreakerOptions, ICircuitBreakerStateStore stateStore)
 {
     _circuitBreakerOptions = circuitBreakerOptions;
     _stateStore            = stateStore;
 }
Example #10
0
 /// <summary>
 /// The type you feed to this constructor will be allocated to a thread-safe, static collection, where the corresponding type's circuit state will be managed.
 /// </summary>
 /// <param name="sharedResource"></param>
 /// TODO: I'm not crazy about feeding the breaker a type. It "might" be better to feed it a method, and then derive the method's class/type.
 public Breaker(Type sharedResource)
 {
     stateStore =
         CircuitBreakerStateStoreFactory
         .GetCircuitBreakerStateStore(sharedResource.ToString());
 }
 public CircuitBreaker(ICircuitBreakerStateStore stateStore, TimeSpan openToHalfOpenWaitTime, int halfOpenSuccessResetThreshold)
 {
     _stateStore = stateStore;
     _openToHalfOpenWaitTime = openToHalfOpenWaitTime;
     _halfOpenSuccessResetThreshold = halfOpenSuccessResetThreshold;
 }
 public CircuitBreaker(ICircuitBreakerStateStore stateStore) : this(stateStore, TimeSpan.FromSeconds(15), 10)
 {
     _stateStore = stateStore;
 }
 public CircuitBreakerService(string resource, int openToHalfOpenWaitTime)
 {
     _stateStore             = CircuitBreakerStateStoreFactory.GetCircuitBreakerStateStore(resource);
     _resourceName           = resource;
     _openToHalfOpenWaitTime = new TimeSpan(0, 0, 0, 0, openToHalfOpenWaitTime);
 }