/// <summary> /// This method removes (expires) objects from the window and schedules a new callback for the /// time when the next oldest message would expire from the window. /// </summary> public void Expire() { long current = _agentInstanceContext.StatementContext.SchedulingService.Time; long expireBeforeTimestamp = current - _timeDeltaComputation.DeltaMillisecondsSubtract(current) + 1; // Remove from the timeWindow any events that have an older or timestamp then the given timestamp // The window : from X to (X - timeDeltaComputation + 1) var expired = _timeWindow.ExpireEvents(expireBeforeTimestamp); // If there are child views, fireStatementStopped Update method if (HasViews) { if ((expired != null) && (expired.IsNotEmpty())) { EventBean[] oldEvents = expired.ToArray(); if (_viewUpdatedCollection != null) { _viewUpdatedCollection.Update(null, oldEvents); } Instrument.With( i => i.QViewIndicate(this, _timeWindowViewFactory.ViewName, null, oldEvents), i => i.AViewIndicate(), () => UpdateChildren(null, oldEvents)); } } ScheduleExpiryCallback(); }
/// <summary> /// Returns the number of milliseconds. /// </summary> /// <returns></returns> public long GetScheduleBackwardDelta(long fromTime, AgentInstanceContext agentInstanceContext) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QRegIntervalValue(TimePeriodExpr); } if (_timeDeltaComputation == null) { _timeDeltaComputation = TimePeriodExpr.ConstEvaluator(new ExprEvaluatorContextStatement(agentInstanceContext.StatementContext, false)); } long result = _timeDeltaComputation.DeltaMillisecondsSubtract(fromTime); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().ARegIntervalValue(result); } return(result); }
public override void Update(EventBean[] newData, EventBean[] oldData) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get() .QViewProcessIRStream(this, _externallyTimedWindowViewFactory.ViewName, newData, oldData); } long timestamp = -1; // add data points to the window // we don't care about removed data from a prior view if (newData != null) { for (int i = 0; i < newData.Length; i++) { timestamp = GetLongValue(newData[i]); _timeWindow.Add(timestamp, newData[i]); } } // Remove from the window any events that have an older timestamp then the last event's timestamp ArrayDeque <EventBean> expired = null; if (timestamp != -1) { expired = _timeWindow.ExpireEvents(timestamp - _timeDeltaComputation.DeltaMillisecondsSubtract(timestamp) + 1); } EventBean[] oldDataUpdate = null; if ((expired != null) && (!expired.IsEmpty())) { oldDataUpdate = expired.ToArray(); } if ((oldData != null) && (AgentInstanceViewFactoryContext.IsRemoveStream)) { foreach (EventBean anOldData in oldData) { _timeWindow.Remove(anOldData); } if (oldDataUpdate == null) { oldDataUpdate = oldData; } else { oldDataUpdate = CollectionUtil.AddArrayWithSetSemantics(oldData, oldDataUpdate); } } if (_viewUpdatedCollection != null) { _viewUpdatedCollection.Update(newData, oldDataUpdate); } // If there are child views, fireStatementStopped update method if (HasViews) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QViewIndicate(this, _externallyTimedWindowViewFactory.ViewName, newData, oldDataUpdate); } UpdateChildren(newData, oldDataUpdate); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AViewIndicate(); } } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AViewProcessIRStream(); } }
/// <summary> /// This method removes (expires) objects from the window and schedules a new callback for the /// time when the next oldest message would expire from the window. /// </summary> protected void Expire() { long currentTime = _agentInstanceContext.StatementContext.SchedulingService.Time; long expireBeforeTimestamp = currentTime - _timeDeltaComputation.DeltaMillisecondsSubtract(currentTime) + 1; _isCallbackScheduled = false; IList <EventBean> releaseEvents = null; long?oldestKey; while (true) { if (_sortedEvents.IsEmpty()) { oldestKey = null; break; } oldestKey = (long)_sortedEvents.Keys.First(); if (oldestKey >= expireBeforeTimestamp) { break; } var released = _sortedEvents.Pluck(oldestKey); if (released != null) { if (released is IList <EventBean> ) { var releasedEventList = (IList <EventBean>)released; if (releaseEvents == null) { releaseEvents = releasedEventList; } else { releaseEvents.AddAll(releasedEventList); } _eventCount -= releasedEventList.Count; InternalHandleExpired(oldestKey, releasedEventList); } else { var releasedEvent = (EventBean)released; if (releaseEvents == null) { releaseEvents = new List <EventBean>(4); } releaseEvents.Add(releasedEvent); _eventCount--; InternalHandleExpired(oldestKey, releasedEvent); } } } if (_optionalSortedRandomAccess != null) { _optionalSortedRandomAccess.Refresh(_sortedEvents, _eventCount, _eventCount); } // If there are child views, do the Update method if (HasViews) { if ((releaseEvents != null) && (releaseEvents.IsNotEmpty())) { EventBean[] oldEvents = releaseEvents.ToArray(); Instrument.With( i => i.QViewIndicate(this, _timeOrderViewFactory.ViewName, null, oldEvents), i => i.AViewIndicate(), () => UpdateChildren(null, oldEvents)); } } // If we still have events in the window, schedule new callback if (oldestKey == null) { return; } // Next callback long callbackWait = oldestKey.Value - expireBeforeTimestamp + 1; _agentInstanceContext.StatementContext.SchedulingService.Add(callbackWait, _handle, _scheduleSlot); _isCallbackScheduled = true; }