private static bool ShouldLogStateChange(BondCallState toState) { // Here we decide which states are logged for bond calls. Most states are not logged to // reduce log spam but states may be added back if they are considered necessary. // Also consider this decision being based on verbosity/diagnostic keywords. switch (toState) { case BondCallState.Started: case BondCallState.Failed: case BondCallState.Succeeded: case BondCallState.Canceled: case BondCallState.HeartbeatSuccess: case BondCallState.HeartbeatDeactivateTimer: case BondCallState.RecreateConnection: return(true); case BondCallState.WaitingForChildCall: case BondCallState.Converted: case BondCallState.Converting: case BondCallState.InitiatedRequest: case BondCallState.WaitingForConnection: case BondCallState.CompletedWaitForConnection: case BondCallState.HeartbeatTimerShutdown: case BondCallState.HeartbeatTimerInactive: case BondCallState.HeartbeatBeforeCall: case BondCallState.HeartbeatAfterCall: case BondCallState.HeartbeatAfterActivateConnection: case BondCallState.HeartbeatQueueTimer: default: return(false); } }
/// <summary> /// Called when a bond call changes state /// </summary> public void OnStateChanged(BondCallState toState) { var currentTime = m_stopwatch.Elapsed; StateDuration = currentTime - m_lastStateTime; TotalDuration = currentTime - m_startTime; OnStateChanged(m_lastState, toState, stateTime: StateDuration, totalTime: TotalDuration); m_lastStateTime = currentTime; m_lastState = toState; }
protected override void OnStateChanged(BondCallState fromState, BondCallState toState, TimeSpan stateTime, TimeSpan totalTime) { switch (toState) { case BondCallState.Started: LogMessage("Starting call({1}) (try count {0})", TryCount, m_description ?? string.Empty); return; } if (ShouldLogStateChange(toState)) { LogMessage("CallState: {0}, StateTime: {1}, TotalTime: {2}", toState.AsString(), stateTime, totalTime); } }
public static string AsString(this BondCallState callState) { switch (callState) { case BondCallState.Canceled: return(nameof(BondCallState.Canceled)); case BondCallState.CompletedWaitForConnection: return(nameof(BondCallState.CompletedWaitForConnection)); case BondCallState.Converted: return(nameof(BondCallState.Converted)); case BondCallState.Converting: return(nameof(BondCallState.Converting)); case BondCallState.Failed: return(nameof(BondCallState.Failed)); case BondCallState.HeartbeatAfterActivateConnection: return(nameof(BondCallState.HeartbeatAfterActivateConnection)); case BondCallState.HeartbeatAfterCall: return(nameof(BondCallState.HeartbeatAfterCall)); case BondCallState.HeartbeatBeforeCall: return(nameof(BondCallState.HeartbeatBeforeCall)); case BondCallState.HeartbeatDeactivateTimer: return(nameof(BondCallState.HeartbeatDeactivateTimer)); case BondCallState.HeartbeatQueueTimer: return(nameof(BondCallState.HeartbeatQueueTimer)); case BondCallState.HeartbeatSuccess: return(nameof(BondCallState.HeartbeatSuccess)); case BondCallState.HeartbeatTimerInactive: return(nameof(BondCallState.HeartbeatTimerInactive)); case BondCallState.HeartbeatTimerShutdown: return(nameof(BondCallState.HeartbeatTimerShutdown)); case BondCallState.InitiatedRequest: return(nameof(BondCallState.InitiatedRequest)); case BondCallState.RecreateConnection: return(nameof(BondCallState.RecreateConnection)); case BondCallState.Started: return(nameof(BondCallState.Started)); case BondCallState.Succeeded: return(nameof(BondCallState.Succeeded)); case BondCallState.WaitingForChildCall: return(nameof(BondCallState.WaitingForChildCall)); case BondCallState.WaitingForConnection: return(nameof(BondCallState.WaitingForConnection)); default: throw new NotImplementedException("Unknown BondCallState type: " + callState); } }
/// <summary> /// Called when a bond call changes state /// </summary> /// <param name="fromState">the current state</param> /// <param name="toState">the new state</param> /// <param name="stateTime">the amount of time spent in the old state</param> /// <param name="totalTime">the total amount of time the call has been active</param> protected virtual void OnStateChanged(BondCallState fromState, BondCallState toState, TimeSpan stateTime, TimeSpan totalTime) { }