public void ScheduleTransitionTo(TimeSpan delay, ConsumerState expectedCurrent, ConsumerState state) { var currentState = _currentState; if (currentState == expectedCurrent) { RunAfterDelay(); } else { _log.Warning( "Skipping scheduled state transition to {nextState} because expected current to be {expectedState}, but it's actually {currentState}", state, expectedCurrent, currentState); } async void RunAfterDelay() { try { await Task.Delay(delay).ConfigureAwait(false); TransitionTo(expectedCurrent, state); } catch (Exception ex) { _log.Error("Error while executing scheduled transition"); } } }
public void TestConsumerState() { ConsumerState state = new ConsumerState(CreateConsumerInfo(1)); Assert.IsNotNull(state.Info); Assert.AreEqual(1, state.Info.ConsumerId.Value); }
private void SetState(ConsumerState state) { lock (_lock) { if (!_hasDisconnected) { _stateManager.SetState(state); } } }
private async void RunSafe(Func <Task> func) { try { await func().ConfigureAwait(false); } catch (Exception ex) { _log.Error("Unexpected consumer state machine error", ex); _currentState = CorruptedState.Instance; } }
public void TransitionTo(ConsumerState expectedCurrent, ConsumerState state) { var originalState = Interlocked.CompareExchange(ref _currentState, state, expectedCurrent); if (originalState == expectedCurrent) { _log.Debug("Entering state {stateType}", state); state.OnEnter(this); } else { _log.Warning( "Transition to state {nextState} not completed because expected state is {expectedState} but actual original is {originalState}", state, expectedCurrent, originalState); } }
public void SetState(ConsumerState state) { switch (state) { case ConsumerState.Watered: anim.SetTrigger("Watered"); break; case ConsumerState.Reset: anim.SetTrigger("Reset"); break; default: break; } }
public async ValueTask <ConsumerState> StateChangedFrom(ConsumerState state, CancellationToken cancellationToken) => await _state.StateChangedFrom(state, cancellationToken);
public HeartBeatResponseBodyConsumerObject(string consumerName, ConsumerState state) { ConsumerName = consumerName; State = state; }
public RunningConsumer(ConnectionName connectionName, ConsumerState state) { ConnectionName = connectionName; State = state; }
/// <summary> /// Wait for the state to change from a specific state. /// </summary> /// <returns> /// The current state. /// </returns> /// <remarks> /// If the state change to a final state, then all awaiting tasks will complete. /// </remarks> public static async ValueTask <ConsumerStateChanged> StateChangedFrom(this IConsumer consumer, ConsumerState state, CancellationToken cancellationToken = default) { var newState = await consumer.OnStateChangeFrom(state, cancellationToken).ConfigureAwait(false); return(new ConsumerStateChanged(consumer, newState)); }
public void Stop() { _currentState = InitialState.Instance; }
public async ValueTask <ConsumerState> StateChangedTo(ConsumerState state, CancellationToken cancellationToken) => await _stateManager.StateChangedTo(state, cancellationToken);
public async ValueTask <ConsumerState> OnStateChangeFrom(ConsumerState state, CancellationToken cancellationToken) => await _state.StateChangedFrom(state, cancellationToken).ConfigureAwait(false);
public bool IsFinalState(ConsumerState state) => _state.IsFinalState(state);
internal ConsumerStateChanged(IConsumer consumer, ConsumerState consumerState) { Consumer = consumer; ConsumerState = consumerState; }
public async ValueTask <ConsumerStateChanged> StateChangedFrom(ConsumerState state, CancellationToken cancellationToken) { var newState = await _state.StateChangedFrom(state, cancellationToken).ConfigureAwait(false); return(new ConsumerStateChanged(this, newState)); }