Exemplo n.º 1
0
        /// <summary>
        /// TBD
        /// </summary>
        public override void HeartBeat()
        {
            var timestamp = _clock();
            var oldState  = state;
            HeartbeatHistory newHistory = null;

            if (!oldState.TimeStamp.HasValue)
            {
                //this is a heartbeat for a new resource
                //add starter records for this new resource
                newHistory = FirstHeartBeat;
            }
            else
            {
                //this is a known connection
                var interval = timestamp - oldState.TimeStamp.Value;
                //don't use the first heartbeat after failure for the history, since a long pause will skew the stats
                if (IsTimeStampAvailable(timestamp))
                {
                    newHistory = (oldState.History + interval);
                }
                else
                {
                    newHistory = oldState.History;
                }
            }

            var newState = new State(newHistory, timestamp);

            //if we won the race then update else try again
            if (!_state.CompareAndSet(oldState, newState))
            {
                HeartBeat();
            }
        }
Exemplo n.º 2
0
 private static HeartbeatHistory DropOldest(HeartbeatHistory history)
 {
     return(new HeartbeatHistory(history._maxSampleSize, history._intervals.Skip(1).ToList(), history._intervalSum - history._intervals.First(), history._squaredIntervalSum - Pow2(history._intervals.First())));
 }
 private static HeartbeatHistory DropOldest(HeartbeatHistory history)
 {
     return new HeartbeatHistory(history._maxSampleSize, history._intervals.Skip(1).ToList(), history._intervalSum - history._intervals.First(), history._squaredIntervalSum - Pow2(history._intervals.First()));
 }
Exemplo n.º 4
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="history">TBD</param>
 /// <param name="timeStamp">TBD</param>
 public State(HeartbeatHistory history, long?timeStamp)
 {
     TimeStamp = timeStamp;
     History   = history;
 }
 public State(HeartbeatHistory history, long? timeStamp)
 {
     TimeStamp = timeStamp;
     History = history;
 }