Exemplo n.º 1
0
        public KillSwitch(KillSwitchOptions options, IReceiveEndpoint receiveEndpoint)
        {
            _options         = options;
            _receiveEndpoint = receiveEndpoint;

            LogContext = Context.LogContext.Current;

            _state = new StartedKillSwitchState(this);
        }
Exemplo n.º 2
0
        public void Restart(Exception exception, IKillSwitchState previousState)
        {
            var restarting = new RestartingKillSwitchState(this, exception);

            Interlocked.CompareExchange(ref _state, restarting, previousState);
            if (_state != restarting)
            {
                return;
            }

            Task.Run(() => RestartReceiveEndpoint());
        }
Exemplo n.º 3
0
        public void Started(IKillSwitchState previousState)
        {
            var started = new StartedKillSwitchState(this);

            Interlocked.CompareExchange(ref _state, started, previousState);
            if (_state != started)
            {
                return;
            }

            started.Activate();
        }
Exemplo n.º 4
0
        public void Stop(Exception exception, IKillSwitchState previousState)
        {
            var stopped = new StoppedKillSwitchState(this, exception);

            Interlocked.CompareExchange(ref _state, stopped, previousState);
            if (_state != stopped)
            {
                return;
            }

            if (previousState is StartedKillSwitchState started)
            {
                started.LogThreshold();
            }

            Task.Run(() => StopReceiveEndpoint(stopped));
        }