private void Flush() { lock (_flushLock) { if (Log.IsDebugEnabled) { Log.DebugFormat("Flush started for {0} actions", _actionList.Count); } List <AppMetrAction> copyActions; lock (_actionList) { copyActions = new List <AppMetrAction>(_actionList); _actionList.Clear(); _eventSize = 0; } if (copyActions.Count > 0) { _batchPersister.Persist(copyActions); _uploadTimer.Trigger(); } else { Log.Info("Nothing to flush"); } } }
public void Track(AppMetrAction action) { if (_stopped) { throw new Exception("Trying to track after stop!"); } try { bool flushNeeded; lock (_actionList) { Interlocked.Add(ref _eventSize, action.CalcApproximateSize()); _actionList.Add(action); flushNeeded = IsNeedToFlush(); } if (flushNeeded) { _flushTimer.Trigger(); } } catch (Exception e) { Log.Error("Track failed", e); } }
public void Track(AppMetrAction action) { if (_stopped) { throw new Exception("Trying to track after stop!"); } try { var currentEventSize = action.CalcApproximateSize(); bool flushNeeded; lock (_actionList) { _eventSize += currentEventSize; _actionList.Add(action); flushNeeded = _eventSize >= MaxEventsSize; } if (flushNeeded) { _flushTimer.Trigger(); } } catch (Exception e) { _log.Error("Track failed", e); } }