public KillSwitch(KillSwitchOptions options, IReceiveEndpoint receiveEndpoint) { _options = options; _receiveEndpoint = receiveEndpoint; LogContext = Context.LogContext.Current; _state = new StartedKillSwitchState(this); }
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()); }
public void Started(IKillSwitchState previousState) { var started = new StartedKillSwitchState(this); Interlocked.CompareExchange(ref _state, started, previousState); if (_state != started) { return; } started.Activate(); }
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)); }