public override void Update( EventBean[] newData, EventBean[] oldData) { _agentInstanceContext.AuditProvider.View(newData, oldData, _agentInstanceContext, _rankWindowViewFactory); _agentInstanceContext.InstrumentationProvider.QViewProcessIRStream( _rankWindowViewFactory, newData, oldData); var removedEvents = new OneEventCollection(); // Remove old data if (oldData != null) { for (var i = 0; i < oldData.Length; i++) { var uniqueKey = GetUniqueKey(oldData[i]); var existingSortKey = _uniqueKeySortKeys.Get(uniqueKey); if (existingSortKey == null) { continue; } var @event = RemoveFromSortedEvents(existingSortKey, uniqueKey); if (@event != null) { _numberOfEvents--; _uniqueKeySortKeys.Remove(uniqueKey); removedEvents.Add(@event); InternalHandleRemovedKey(existingSortKey, oldData[i]); } } } // Add new data if (newData != null) { for (var i = 0; i < newData.Length; i++) { var uniqueKey = GetUniqueKey(newData[i]); var newSortKey = GetSortValues(newData[i]); var existingSortKey = _uniqueKeySortKeys.Get(uniqueKey); // not currently found: its a new entry if (existingSortKey == null) { CompareAndAddOrPassthru(newData[i], uniqueKey, newSortKey, removedEvents); } else { // same unique-key event found already, remove and add again // key did not change, perform in-place substitute of event if (existingSortKey.Equals(newSortKey)) { var replaced = InplaceReplaceSortedEvents(existingSortKey, uniqueKey, newData[i]); if (replaced != null) { removedEvents.Add(replaced); } InternalHandleReplacedKey(newSortKey, newData[i], replaced); } else { var removed = RemoveFromSortedEvents(existingSortKey, uniqueKey); if (removed != null) { _numberOfEvents--; removedEvents.Add(removed); InternalHandleRemovedKey(existingSortKey, removed); } CompareAndAddOrPassthru(newData[i], uniqueKey, newSortKey, removedEvents); } } } } // Remove data that sorts to the bottom of the window while (_numberOfEvents > _sortWindowSize) { var lastKey = _sortedEvents.Keys.Last(); var existing = _sortedEvents.Get(lastKey); if (existing is IList<EventBean> existingList) { while (_numberOfEvents > _sortWindowSize && !existingList.IsEmpty()) { var newestEvent = existingList.DeleteAt(0); var uniqueKey = GetUniqueKey(newestEvent); _uniqueKeySortKeys.Remove(uniqueKey); _numberOfEvents--; removedEvents.Add(newestEvent); InternalHandleRemovedKey(existing, newestEvent); } if (existingList.IsEmpty()) { _sortedEvents.Remove(lastKey); } } else { var lastSortedEvent = (EventBean) existing; var uniqueKey = GetUniqueKey(lastSortedEvent); _uniqueKeySortKeys.Remove(uniqueKey); _numberOfEvents--; removedEvents.Add(lastSortedEvent); _sortedEvents.Remove(lastKey); InternalHandleRemovedKey(lastKey, lastSortedEvent); } } // If there are child views, fireStatementStopped update method _optionalRankedRandomAccess?.Refresh(_sortedEvents, _numberOfEvents, _sortWindowSize); if (Child != null) { EventBean[] expiredArr = null; if (!removedEvents.IsEmpty()) { expiredArr = removedEvents.ToArray(); } _agentInstanceContext.InstrumentationProvider.QViewIndicate( _rankWindowViewFactory, newData, expiredArr); Child.Update(newData, expiredArr); _agentInstanceContext.InstrumentationProvider.AViewIndicate(); } _agentInstanceContext.InstrumentationProvider.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(); }
public override void Update( EventBean[] newData, EventBean[] oldData) { agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, factory); agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(factory, newData, oldData); OneEventCollection removedEvents = null; // Remove old data if (oldData != null) { for (var i = 0; i < oldData.Length; i++) { var oldDataItem = oldData[i]; var sortValues = GetSortValues(oldDataItem); var result = CollectionUtil.RemoveEventByKeyLazyListMap(sortValues, oldDataItem, sortedEvents); if (result) { eventCount--; if (removedEvents == null) { removedEvents = new OneEventCollection(); } removedEvents.Add(oldDataItem); InternalHandleRemoved(sortValues, oldDataItem); } } } // Add new data if (newData != null) { for (var i = 0; i < newData.Length; i++) { var newDataItem = newData[i]; var sortValues = GetSortValues(newDataItem); CollectionUtil.AddEventByKeyLazyListMapFront(sortValues, newDataItem, sortedEvents); eventCount++; InternalHandleAdd(sortValues, newDataItem); } } // Remove data that sorts to the bottom of the window if (eventCount > sortWindowSize) { var removeCount = eventCount - sortWindowSize; for (var i = 0; i < removeCount; i++) { // Remove the last element of the last key - sort order is key and then natural order of arrival var lastKey = sortedEvents.Keys.Last(); var lastEntry = sortedEvents.Get(lastKey); if (lastEntry is IList<EventBean>) { var events = (IList<EventBean>) lastEntry; var theEvent = events.DeleteAt(events.Count - 1); // remove oldest event, newest events are first in list eventCount--; if (events.IsEmpty()) { sortedEvents.Remove(lastKey); } if (removedEvents == null) { removedEvents = new OneEventCollection(); } removedEvents.Add(theEvent); InternalHandleRemoved(lastKey, theEvent); } else { var theEvent = (EventBean) lastEntry; eventCount--; sortedEvents.Remove(lastKey); if (removedEvents == null) { removedEvents = new OneEventCollection(); } removedEvents.Add(theEvent); InternalHandleRemoved(lastKey, theEvent); } } } // If there are child views, fireStatementStopped update method optionalSortedRandomAccess?.Refresh(sortedEvents, eventCount, sortWindowSize); if (child != null) { EventBean[] expiredArr = null; if (removedEvents != null) { expiredArr = removedEvents.ToArray(); } agentInstanceContext.InstrumentationProvider.QViewIndicate(factory, newData, expiredArr); child.Update(newData, expiredArr); agentInstanceContext.InstrumentationProvider.AViewIndicate(); } agentInstanceContext.InstrumentationProvider.AViewProcessIRStream(); }