示例#1
0
 public BulkheadInvoker(IBreakerInvoker breakerInvoker, IBulkheadFactory bulkheadFactory, IMetricEvents metricEvents, MjolnirConfiguration config)
 {
     _breakerInvoker  = breakerInvoker ?? throw new ArgumentNullException(nameof(breakerInvoker));
     _bulkheadFactory = bulkheadFactory ?? throw new ArgumentNullException(nameof(bulkheadFactory));
     _metricEvents    = metricEvents ?? throw new ArgumentNullException(nameof(metricEvents));
     _config          = config ?? throw new ArgumentNullException(nameof(config));
 }
示例#2
0
        // Internal constructor with a few extra arguments used by tests to inject mocks.
        internal CommandInvoker(
            MjolnirConfiguration config = null,
            IMjolnirLogFactory logFactory = null,
            IMetricEvents metricEvents = null,
            IBreakerExceptionHandler breakerExceptionHandler = null,
            IBulkheadInvoker bulkheadInvoker = null)
        {
            _config = config ?? new MjolnirConfiguration
            {
                IsEnabled = true,
                UseCircuitBreakers = false,
                IgnoreTimeouts = false
            };
            _logFactory = logFactory ?? new DefaultMjolnirLogFactory();
            _log = _logFactory.CreateLog<CommandInvoker>();
            if (_log == null)
            {
                throw new InvalidOperationException($"{nameof(IMjolnirLogFactory)} implementation returned null from {nameof(IMjolnirLogFactory.CreateLog)} for name {nameof(CommandInvoker)}, please make sure the implementation returns a non-null log for all calls to {nameof(IMjolnirLogFactory.CreateLog)}");
            }

            _metricEvents = metricEvents ?? new IgnoringMetricEvents();
            _breakerExceptionHandler = breakerExceptionHandler ?? new IgnoredExceptionHandler(new HashSet<Type>());

            _circuitBreakerFactory = new CircuitBreakerFactory(
                _metricEvents,
                new FailurePercentageCircuitBreakerConfig(_config),
                _logFactory);

            _bulkheadFactory = new BulkheadFactory(
                _metricEvents,
                _config,
                _logFactory);

            var breakerInvoker = new BreakerInvoker(_circuitBreakerFactory, _metricEvents, _breakerExceptionHandler);
            _bulkheadInvoker = bulkheadInvoker ?? new BulkheadInvoker(breakerInvoker, _bulkheadFactory, _metricEvents, _config);
        }