public override void Update( EventBean[] newData, EventBean[] oldData) { AgentInstanceContext agentInstanceContext = agentInstanceViewFactoryContext.AgentInstanceContext; agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, factory); agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(factory, 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 - timePeriodProvide.DeltaSubtract(timestamp, null, true, agentInstanceViewFactoryContext) + 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); } } viewUpdatedCollection?.Update(newData, oldDataUpdate); // If there are child views, fireStatementStopped update method if (Child != null) { agentInstanceContext.InstrumentationProvider.QViewIndicate(factory, newData, oldDataUpdate); Child.Update(newData, oldDataUpdate); agentInstanceContext.InstrumentationProvider.AViewIndicate(); } agentInstanceContext.InstrumentationProvider.AViewProcessIRStream(); }
public override void Update(EventBean[] newData, EventBean[] oldData) { using (Instrument.With( i => i.QViewProcessIRStream(this, _viewFactory.ViewName, newData, oldData), i => i.AViewProcessIRStream())) { EventBean[] postOldEventsArray = null; // Remove old data if (oldData != null) { for (int i = 0; i < oldData.Length; i++) { var oldDataItem = oldData[i]; var sortValues = GetTimestamp(oldDataItem); var result = CollectionUtil.RemoveEventByKeyLazyListMap(sortValues, oldDataItem, _sortedEvents); if (result) { _eventCount--; if (postOldEventsArray == null) { postOldEventsArray = oldData; } else { postOldEventsArray = CollectionUtil.AddArrayWithSetSemantics( postOldEventsArray, oldData); } InternalHandleRemoved(sortValues, oldDataItem); } } } if ((newData != null) && (newData.Length > 0)) { // figure out the current tail time long engineTime = _agentInstanceContext.StatementContext.SchedulingService.Time; long windowTailTime = engineTime - _timeDeltaComputation.DeltaAdd(engineTime) + 1; long oldestEvent = long.MaxValue; if (_sortedEvents.IsNotEmpty()) { oldestEvent = (long)_sortedEvents.Keys.First(); } bool addedOlderEvent = false; // add events or post events as remove stream if already older then tail time List <EventBean> postOldEvents = null; for (int i = 0; i < newData.Length; i++) { // get timestamp of event var newEvent = newData[i]; var timestamp = GetTimestamp(newEvent); // if the event timestamp indicates its older then the tail of the window, release it if (timestamp < windowTailTime) { if (postOldEvents == null) { postOldEvents = new List <EventBean>(2); } postOldEvents.Add(newEvent); } else { if (timestamp < oldestEvent) { addedOlderEvent = true; oldestEvent = timestamp.Value; } // add to list CollectionUtil.AddEventByKeyLazyListMapBack(timestamp, newEvent, _sortedEvents); _eventCount++; InternalHandleAdd(timestamp, newEvent); } } // If we do have data, check the callback if (_sortedEvents.IsNotEmpty()) { // If we haven't scheduled a callback yet, schedule it now if (!_isCallbackScheduled) { long callbackWait = oldestEvent - windowTailTime + 1; _agentInstanceContext.StatementContext.SchedulingService.Add( callbackWait, _handle, _scheduleSlot); _isCallbackScheduled = true; } else { // We may need to reschedule, and older event may have been added if (addedOlderEvent) { oldestEvent = (long)_sortedEvents.Keys.First(); long callbackWait = oldestEvent - windowTailTime + 1; _agentInstanceContext.StatementContext.SchedulingService.Remove(_handle, _scheduleSlot); _agentInstanceContext.StatementContext.SchedulingService.Add( callbackWait, _handle, _scheduleSlot); _isCallbackScheduled = true; } } } if (postOldEvents != null) { postOldEventsArray = postOldEvents.ToArray(); } if (_optionalSortedRandomAccess != null) { _optionalSortedRandomAccess.Refresh(_sortedEvents, _eventCount, _eventCount); } } // Update child views if (HasViews) { Instrument.With( i => i.QViewIndicate(this, _viewFactory.ViewName, newData, postOldEventsArray), i => i.AViewIndicate(), () => UpdateChildren(newData, postOldEventsArray)); } } }
public override void Update(EventBean[] newData, EventBean[] oldData) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QViewProcessIRStream(this, _lengthWindowViewFactory.ViewName, newData, oldData); } EventBean[] expiredArr = null; if (oldData != null) { foreach (EventBean anOldData in oldData) { _indexedEvents.Remove(anOldData); InternalHandleRemoved(anOldData); } if (expiredArr == null) { expiredArr = oldData; } else { expiredArr = CollectionUtil.AddArrayWithSetSemantics(expiredArr, oldData); } } // add data points to the window // we don't care about removed data from a prior view if (newData != null) { foreach (EventBean newEvent in newData) { _indexedEvents.Add(newEvent); InternalHandleAdded(newEvent); } } // Check for any events that get pushed out of the window int expiredCount = _indexedEvents.Count - _size; if (expiredCount > 0) { expiredArr = _indexedEvents.Take(expiredCount).ToArray(); foreach (EventBean anExpired in expiredArr) { _indexedEvents.Remove(anExpired); InternalHandleExpired(anExpired); } } // If there are child views, call Update method if (HasViews) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QViewIndicate(this, _lengthWindowViewFactory.ViewName, newData, expiredArr); } UpdateChildren(newData, expiredArr); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AViewIndicate(); } } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AViewProcessIRStream(); } }
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(); } }
public override void Update( EventBean[] newData, EventBean[] oldData) { agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, factory); agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(factory, newData, oldData); EventBean[] postOldEventsArray = null; // Remove old data if (oldData != null) { for (var i = 0; i < oldData.Length; i++) { var oldDataItem = oldData[i]; object sortValues = GetTimestamp(oldDataItem); var result = CollectionUtil.RemoveEventByKeyLazyListMap(sortValues, oldDataItem, sortedEvents); if (result) { eventCount--; if (postOldEventsArray == null) { postOldEventsArray = oldData; } else { postOldEventsArray = CollectionUtil.AddArrayWithSetSemantics(postOldEventsArray, oldData); } } } } if (newData != null && newData.Length > 0) { // figure out the current tail time var runtimeTime = agentInstanceContext.StatementContext.SchedulingService.Time; var windowTailTime = runtimeTime - timePeriodProvide.DeltaAdd(runtimeTime, null, true, agentInstanceContext) + 1; var oldestEvent = long.MaxValue; if (!sortedEvents.IsEmpty()) { oldestEvent = sortedEvents.First().Key.AsInt64(); } var addedOlderEvent = false; // add events or post events as remove stream if already older then tail time List<EventBean> postOldEvents = null; for (var i = 0; i < newData.Length; i++) { // get timestamp of event var newEvent = newData[i]; var timestamp = GetTimestamp(newEvent); // if the event timestamp indicates its older then the tail of the window, release it if (timestamp < windowTailTime) { if (postOldEvents == null) { postOldEvents = new List<EventBean>(2); } postOldEvents.Add(newEvent); } else { if (timestamp < oldestEvent) { addedOlderEvent = true; oldestEvent = timestamp.Value; } // add to list CollectionUtil.AddEventByKeyLazyListMapBack(timestamp, newEvent, sortedEvents); eventCount++; } } // If we do have data, check the callback if (!sortedEvents.IsEmpty()) { // If we haven't scheduled a callback yet, schedule it now if (!isCallbackScheduled) { var callbackWait = oldestEvent - windowTailTime + 1; agentInstanceContext.AuditProvider.ScheduleAdd( callbackWait, agentInstanceContext, handle, ScheduleObjectType.view, factory.ViewName); agentInstanceContext.StatementContext.SchedulingService.Add(callbackWait, handle, scheduleSlot); isCallbackScheduled = true; } else { // We may need to reschedule, and older event may have been added if (addedOlderEvent) { oldestEvent = sortedEvents.First().Key.AsInt64(); var callbackWait = oldestEvent - windowTailTime + 1; agentInstanceContext.AuditProvider.ScheduleRemove( agentInstanceContext, handle, ScheduleObjectType.view, factory.ViewName); agentInstanceContext.StatementContext.SchedulingService.Remove(handle, scheduleSlot); agentInstanceContext.AuditProvider.ScheduleAdd( callbackWait, agentInstanceContext, handle, ScheduleObjectType.view, factory.ViewName); agentInstanceContext.StatementContext.SchedulingService.Add( callbackWait, handle, scheduleSlot); isCallbackScheduled = true; } } } if (postOldEvents != null) { postOldEventsArray = postOldEvents.ToArray(); } optionalSortedRandomAccess?.Refresh(sortedEvents, eventCount, eventCount); } // update child views if (Child != null) { agentInstanceContext.InstrumentationProvider.QViewIndicate(factory, newData, postOldEventsArray); Child.Update(newData, postOldEventsArray); agentInstanceContext.InstrumentationProvider.AViewIndicate(); } agentInstanceContext.InstrumentationProvider.AViewProcessIRStream(); }