private object[] GetFilterValues( MatchedEventMap matchedEvents, ExprEvaluatorContext exprEvaluatorContext) { if (!_hasCollMapOrArray) { var constantsX = new object[_listOfValues.Count]; var countX = 0; foreach (var valuePlaceholder in _listOfValues) { constantsX[countX++] = valuePlaceholder.GetFilterValue(matchedEvents, exprEvaluatorContext); } return constantsX; } var constants = new ArrayDeque<object>(_listOfValues.Count); var count = 0; foreach (var valuePlaceholder in _listOfValues) { var value = valuePlaceholder.GetFilterValue(matchedEvents, exprEvaluatorContext); if (value != null) { _adders[count].Add(constants, value); } count++; } return constants.ToArray(); }
/// <summary> /// This method updates child views and clears the batch of events. /// </summary> protected void SendBatch() { // If there are child views and the batch was filled, fireStatementStopped update method if (child != null) { // Convert to object arrays EventBean[] newData = null; EventBean[] oldData = null; if (!currentBatch.IsEmpty()) { newData = currentBatch.ToArray(); } if (lastBatch != null && !lastBatch.IsEmpty()) { oldData = lastBatch.ToArray(); } // update view buffer to serve expressions require access to events held viewUpdatedCollection?.Update(newData, oldData); // Post new data (current batch) and old data (prior batch) if (newData != null || oldData != null) { agentInstanceContext.InstrumentationProvider.QViewIndicate( lengthBatchViewFactory, newData, oldData); child.Update(newData, oldData); agentInstanceContext.InstrumentationProvider.AViewIndicate(); } } lastBatch = currentBatch; currentBatch = new ArrayDeque<EventBean>(); }
public static EventBean[] GetNewDataNonRemoved( EventBean[] newData, ISet<EventBean> removedEvents) { var filter = false; for (var i = 0; i < newData.Length; i++) { if (removedEvents.Contains(newData[i])) { filter = true; } } if (!filter) { return newData; } if (newData.Length == 1) { return null; } var events = new ArrayDeque<EventBean>(newData.Length - 1); for (var i = 0; i < newData.Length; i++) { if (!removedEvents.Contains(newData[i])) { events.Add(newData[i]); } } if (events.IsEmpty()) { return null; } return events.ToArray(); }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// Returns the fragment for dynamic properties. /// </summary> /// <param name="object">to inspect</param> /// <param name="fragmentEventType">type</param> /// <param name="eventAdapterService">factory for event beans and event types</param> /// <returns>fragment</returns> public static Object ToFragmentIterable(Object @object, BeanEventType fragmentEventType, EventAdapterService eventAdapterService) { if (!(@object is IEnumerable)) { return null; } var enumerator = ((IEnumerable) @object).GetEnumerator(); if (!enumerator.MoveNext()) { return new EventBean[0]; } var events = new ArrayDeque<EventBean>(); do { var next = enumerator.Current; if (next == null) { continue; } events.Add(eventAdapterService.AdapterForTypedObject(next, fragmentEventType)); } while (enumerator.MoveNext()); return events.ToArray(); }
public static EventBean[] GetNewDataNonRemoved( EventBean[] newData, ISet<EventBean> removedEvents, EventBean[][] newEventsPerView) { if (newData == null || newData.Length == 0) { return null; } if (newData.Length == 1) { if (removedEvents.Contains(newData[0])) { return null; } var pass = FindEvent(newData[0], newEventsPerView); return pass ? newData : null; } var events = new ArrayDeque<EventBean>(newData.Length - 1); for (var i = 0; i < newData.Length; i++) { if (!removedEvents.Contains(newData[i])) { var pass = FindEvent(newData[i], newEventsPerView); if (pass) { events.Add(newData[i]); } } } if (events.IsEmpty()) { return null; } return events.ToArray(); }
/// <summary> /// NOTE: Code-generation-invoked method, method name and parameter order matters /// </summary> /// <param name="arrays">values</param> /// <returns>array</returns> public static EventBean[][] ToArrayEventsArray(ArrayDeque<EventBean[]> arrays) { if (arrays.IsEmpty()) { return EVENTBEANARRAYARRAY_EMPTY; } return arrays.ToArray(); }
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 EventBean[] GetProperty(EventBean theEvent, ExprEvaluatorContext exprEvaluatorContext) { var resultEvents = new ArrayDeque<EventBean>(); _eventsPerStream[0] = theEvent; PopulateEvents(theEvent, 0, resultEvents, exprEvaluatorContext); if (resultEvents.IsEmpty()) { return null; } return resultEvents.ToArray(); }
/// <summary> /// This method updates child views and clears the batch of events. /// We schedule a new callback at this time if there were events in the batch. /// </summary> public void SendBatch() { _isCallbackScheduled = false; // If there are child views and the batch was filled, fireStatementStopped update method if (HasViews) { // Convert to object arrays EventBean[] newData = null; EventBean[] oldData = null; if (!_currentBatch.IsEmpty()) { newData = _currentBatch.ToArray(); } if ((_lastBatch != null) && (!_lastBatch.IsEmpty())) { oldData = _lastBatch.ToArray(); } // Post new data (current batch) and old data (prior batch) if (_viewUpdatedCollection != null) { _viewUpdatedCollection.Update(newData, oldData); } if ((newData != null) || (oldData != null) || _isForceOutput) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QViewIndicate(this, _timeBatchViewFactory.ViewName, newData, oldData); } UpdateChildren(newData, oldData); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AViewIndicate(); } } } // Only if forceOutput is enabled or // there have been any events in this or the last interval do we schedule a callback, // such as to not waste resources when no events arrive. if ((!_currentBatch.IsEmpty()) || ((_lastBatch != null) && (!_lastBatch.IsEmpty())) || _isForceOutput) { ScheduleCallback(); _isCallbackScheduled = true; } _lastBatch = _currentBatch; _currentBatch = new ArrayDeque <EventBean>(); }
public override ExprNode Validate(ExprValidationContext validationContext) { _evaluators = ExprNodeUtility.GetEvaluators(ChildNodes); foreach (ExprNode childNode in ChildNodes) { Validate(childNode); } var list = new ArrayDeque <TimePeriodAdder>(); if (_hasYear) { list.Add(new TimePeriodAdderYear()); } if (_hasMonth) { list.Add(new TimePeriodAdderMonth()); } if (_hasWeek) { list.Add(new TimePeriodAdderWeek()); } if (_hasDay) { list.Add(new TimePeriodAdderDay()); } if (_hasHour) { list.Add(new TimePeriodAdderHour()); } if (_hasMinute) { list.Add(new TimePeriodAdderMinute()); } if (_hasSecond) { list.Add(new TimePeriodAdderSecond()); } if (_hasMillisecond) { list.Add(new TimePeriodAdderMSec()); } if (_hasMicrosecond) { list.Add(new TimePeriodAdderUSec()); } _adders = list.ToArray(); return(null); }
public override ExprNode Validate(ExprValidationContext validationContext) { var hasVariables = false; foreach (var childNode in ChildNodes) { hasVariables |= Validate(childNode); } var list = new ArrayDeque<TimePeriodAdder>(); if (HasYear) { list.Add(TimePeriodAdderYear.INSTANCE); } if (HasMonth) { list.Add(TimePeriodAdderMonth.INSTANCE); } if (HasWeek) { list.Add(TimePeriodAdderWeek.INSTANCE); } if (HasDay) { list.Add(TimePeriodAdderDay.INSTANCE); } if (HasHour) { list.Add(TimePeriodAdderHour.INSTANCE); } if (HasMinute) { list.Add(TimePeriodAdderMinute.INSTANCE); } if (HasSecond) { list.Add(TimePeriodAdderSecond.INSTANCE); } if (HasMillisecond) { list.Add(TimePeriodAdderMSec.INSTANCE); } if (HasMicrosecond) { list.Add(TimePeriodAdderUSec.INSTANCE); } var adders = list.ToArray(); forge = new ExprTimePeriodForge(this, hasVariables, adders); return null; }
private static void HandleAtom( RowRecogExprNodeAtom atom, ArrayDeque<RowRecogExprNode> path, IDictionary<string, ISet<string>> map) { var patharr = path.ToArray(); ISet<string> identifiers = null; for (var i = 0; i < patharr.Length; i++) { var parent = patharr[i]; if (!(parent is RowRecogExprNodeConcatenation)) { continue; } var concat = (RowRecogExprNodeConcatenation) parent; int indexWithinConcat; if (i == patharr.Length - 1) { indexWithinConcat = parent.ChildNodes.IndexOf(atom); } else { indexWithinConcat = parent.ChildNodes.IndexOf(patharr[i + 1]); } if (identifiers == null && indexWithinConcat > 0) { identifiers = new HashSet<string>(); } for (var j = 0; j < indexWithinConcat; j++) { var concatChildNode = concat.ChildNodes[j]; RecursiveCollectAtomsWExclude(concatChildNode, identifiers, atom.Tag); } } if (identifiers == null) { return; } var existingVisibility = map.Get(atom.Tag); if (existingVisibility == null) { map.Put(atom.Tag, identifiers); } else { existingVisibility.AddAll(identifiers); } }
/// <summary>This method updates child views and clears the batch of events. </summary> protected void SendBatch() { // If there are child views and the batch was filled, fireStatementStopped Update method if (HasViews) { // Convert to object arrays EventBean[] newData = null; EventBean[] oldData = null; if (CurrentBatch.IsNotEmpty()) { newData = CurrentBatch.ToArray(); } if ((LastBatch != null) && (LastBatch.IsNotEmpty())) { oldData = LastBatch.ToArray(); } // Update view buffer to serve expressions require access to events held if (_viewUpdatedCollection != null) { _viewUpdatedCollection.Update(newData, oldData); } // Post new data (current batch) and old data (prior batch) if ((newData != null) || (oldData != null)) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QViewIndicate(this, _lengthBatchViewFactory.ViewName, newData, oldData); } UpdateChildren(newData, oldData); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AViewIndicate(); } } } LastBatch = CurrentBatch; CurrentBatch = new ArrayDeque <EventBean>(); }
protected internal static FilterSpecParamForge[] SortRemoveDups(IList<FilterSpecParamForge> parameters) { if (parameters.IsEmpty()) { return FilterSpecParamForge.EMPTY_PARAM_ARRAY; } if (parameters.Count == 1) { return new FilterSpecParamForge[] {parameters[0]}; } ArrayDeque<FilterSpecParamForge> result = new ArrayDeque<FilterSpecParamForge>(); OrderedDictionary<FilterOperator, IList<FilterSpecParamForge>> map = new OrderedDictionary<FilterOperator, IList<FilterSpecParamForge>>(COMPARATOR_PARAMETERS); foreach (var parameter in parameters) { var list = map.Get(parameter.FilterOperator); if (list == null) { list = new List<FilterSpecParamForge>(); map.Put(parameter.FilterOperator, list); } var hasDuplicate = false; foreach (var existing in list) { if (existing.Lookupable.Equals(parameter.Lookupable)) { hasDuplicate = true; break; } } if (hasDuplicate) { continue; } list.Add(parameter); } foreach (KeyValuePair<FilterOperator, IList<FilterSpecParamForge>> entry in map) { result.AddAll(entry.Value); } return result.ToArray(); }
/// <summary> /// This method updates child views and clears the batch of events. /// We schedule a new callback at this time if there were events in the batch. /// </summary> private void SendBatch() { _isCallbackScheduled = false; // If there are child views and the batch was filled, fireStatementStopped update method if (Child != null) { // Convert to object arrays EventBean[] newData = null; EventBean[] oldData = null; if (!_currentBatch.IsEmpty()) { newData = _currentBatch.ToArray(); } if (_lastBatch != null && !_lastBatch.IsEmpty()) { oldData = _lastBatch.ToArray(); } // Post new data (current batch) and old data (prior batch) _viewUpdatedCollection?.Update(newData, oldData); if (newData != null || oldData != null || _factory.isForceUpdate) { _agentInstanceContext.InstrumentationProvider.QViewIndicate(_factory, newData, oldData); Child.Update(newData, oldData); _agentInstanceContext.InstrumentationProvider.AViewIndicate(); } } // Only if forceOutput is enabled or // there have been any events in this or the last interval do we schedule a callback, // such as to not waste resources when no events arrive. if (!_currentBatch.IsEmpty() || _lastBatch != null && !_lastBatch.IsEmpty() || _factory.isForceUpdate) { ScheduleCallback(); _isCallbackScheduled = true; } _lastBatch = _currentBatch; _currentBatch = new ArrayDeque<EventBean>(); }
private MultiKeyUntyped GetFilterValues(MatchedEventMap matchedEvents, AgentInstanceContext agentInstanceContext) { if (!_hasCollMapOrArray) { var constantsX = new Object[_listOfValues.Count]; int countX = 0; foreach (FilterSpecParamInValue valuePlaceholder in _listOfValues) { constantsX[countX++] = valuePlaceholder.GetFilterValue(matchedEvents, agentInstanceContext); } return new MultiKeyUntyped(constantsX); } var constants = new ArrayDeque<object>(_listOfValues.Count); int count = 0; foreach (FilterSpecParamInValue valuePlaceholder in _listOfValues) { Object value = valuePlaceholder.GetFilterValue(matchedEvents, agentInstanceContext); if (value != null) { _adders[count].Add(constants, value); } count++; } return new MultiKeyUntyped(constants.ToArray()); }
/// <summary> /// Executes the prepared query. /// </summary> /// <returns>query results</returns> public EPPreparedQueryResult Execute(ContextPartitionSelector[] contextPartitionSelectors) { try { if (contextPartitionSelectors != null && contextPartitionSelectors.Length != 1) { throw new ArgumentException("Number of context partition selectors must be one"); } var optionalSingleSelector = contextPartitionSelectors != null && contextPartitionSelectors.Length > 0 ? contextPartitionSelectors[0] : null; // validate context if (Processor.ContextName != null && StatementSpec.OptionalContextName != null && !Processor.ContextName.Equals(StatementSpec.OptionalContextName)) { throw new EPException("Context for named window is '" + Processor.ContextName + "' and query specifies context '" + StatementSpec.OptionalContextName + "'"); } // handle non-specified context if (StatementSpec.OptionalContextName == null) { FireAndForgetInstance processorInstance = Processor.GetProcessorInstanceNoContext(); if (processorInstance != null) { var rows = Executor.Execute(processorInstance); if (rows != null && rows.Length > 0) { Dispatch(); } return(new EPPreparedQueryResult(Processor.EventTypePublic, rows)); } } // context partition runtime query var agentInstanceIds = EPPreparedExecuteMethodHelper.GetAgentInstanceIds(Processor, optionalSingleSelector, Services.ContextManagementService, Processor.ContextName); // collect events and agent instances if (agentInstanceIds.IsEmpty()) { return(new EPPreparedQueryResult(Processor.EventTypeResultSetProcessor, CollectionUtil.EVENTBEANARRAY_EMPTY)); } if (agentInstanceIds.Count == 1) { int agentInstanceId = agentInstanceIds.First(); var processorInstance = Processor.GetProcessorInstanceContextById(agentInstanceId); var rows = Executor.Execute(processorInstance); if (rows.Length > 0) { Dispatch(); } return(new EPPreparedQueryResult(Processor.EventTypeResultSetProcessor, rows)); } var allRows = new ArrayDeque <EventBean>(); foreach (int agentInstanceId in agentInstanceIds) { var processorInstance = Processor.GetProcessorInstanceContextById(agentInstanceId); if (processorInstance != null) { var rows = Executor.Execute(processorInstance); allRows.AddAll(rows); } } if (allRows.Count > 0) { Dispatch(); } return(new EPPreparedQueryResult(Processor.EventTypeResultSetProcessor, allRows.ToArray())); } finally { if (HasTableAccess) { Services.TableService.TableExprEvaluatorContext.ReleaseAcquiredLocks(); } } }
public override void Update(EventBean[] newData, EventBean[] oldData) { _oldEvents.Clear(); EventBean[] newDataPosted = null; // handle remove stream if (oldData != null) { _isDiscardObserverEvents = true; // disable reaction logic in observer try { foreach (View view in _views) { view.Update(null, oldData); } } finally { _isDiscardObserverEvents = false; } for (int i = 0; i < oldData.Length; i++) { _oldEvents.Add(oldData[i]); } } if (newData != null) { _removalEvents.Clear(); // new events must go to all views // old events, such as when removing from a named window, get removed from all views _isHasRemovestreamData = false; // changed by observer logic to indicate new data _isRetainObserverEvents = true; // enable retain logic in observer try { foreach (View view in _views) { _newDataChildView = null; view.Update(newData, oldData); // first-X asymetric view post no insert stream for events that get dropped, remove these if (_newDataChildView != null) { for (int i = 0; i < newData.Length; i++) { bool found = false; for (int j = 0; j < _newDataChildView.Length; j++) { if (_newDataChildView[i] == newData[i]) { found = true; break; } } if (!found) { _removalEvents.Add(newData[i]); } } } else { for (int i = 0; i < newData.Length; i++) { _removalEvents.Add(newData[i]); } } } } finally { _isRetainObserverEvents = false; } if (_removalEvents.IsNotEmpty()) { _isDiscardObserverEvents = true; EventBean[] viewOldData = _removalEvents.ToArray(); try { for (int j = 0; j < _views.Length; j++) { _views[j].Update(null, viewOldData); } } finally { _isDiscardObserverEvents = false; } } // see if any child view has removed any events. // if there was an insert stream, handle pushed-out events if (_isHasRemovestreamData) { // process each buffer for (int i = 0; i < _oldEventsPerView.Length; i++) { if (_oldEventsPerView[i] == null) { continue; } EventBean[] viewOldData = _oldEventsPerView[i]; _oldEventsPerView[i] = null; // clear entry // add each event to the set of events removed foreach (EventBean oldEvent in viewOldData) { _removalEvents.Add(oldEvent); } _isDiscardObserverEvents = true; try { for (int j = 0; j < _views.Length; j++) { if (i != j) { _views[j].Update(null, viewOldData); } } } finally { _isDiscardObserverEvents = false; } } _oldEvents.AddAll(_removalEvents); } _newEvents.Clear(); for (int i = 0; i < newData.Length; i++) { if (!_removalEvents.Contains(newData[i])) { _newEvents.Add(newData[i]); } } if (_newEvents.IsNotEmpty()) { newDataPosted = _newEvents.ToArray(); } } // indicate new and, possibly, old data EventBean[] oldDataPosted = null; if (_oldEvents.IsNotEmpty()) { oldDataPosted = _oldEvents.ToArray(); } if ((newDataPosted != null) || (oldDataPosted != null)) { UpdateChildren(newDataPosted, oldDataPosted); } _oldEvents.Clear(); }
public override void Update(EventBean[] newData, EventBean[] oldData) { // handle remove stream OneEventCollection oldDataColl = null; EventBean[] newDataPosted = null; if (oldData != null) { _isDiscardObserverEvents = true; // disable reaction logic in observer try { foreach (var view in _views) { view.Update(null, oldData); } } finally { _isDiscardObserverEvents = false; } // remove from union foreach (var oldEvent in oldData) { _unionWindow.RemoveAll(oldEvent); } oldDataColl = new OneEventCollection(); oldDataColl.Add(oldData); } // add new event to union if (newData != null) { var removedByView = new bool[newData.Length, _views.Length]; foreach (var newEvent in newData) { _unionWindow.Add(newEvent, _views.Length); } // new events must go to all views // old events, such as when removing from a named window, get removed from all views _isHasRemovestreamData = false; // changed by observer logic to indicate new data _isRetainObserverEvents = true; // enable retain logic in observer try { for (var viewIndex = 0; viewIndex < _views.Length; viewIndex++) { var view = _views[viewIndex]; view.Update(newData, null); // first-X asymetric view post no insert stream for events that get dropped, remove these if (_newDataChildView != null) { for (var i = 0; i < newData.Length; i++) { var found = false; for (var j = 0; j < _newDataChildView.Length; j++) { if (_newDataChildView[i] == newData[i]) { found = true; break; } } if (!found) { removedByView[i, viewIndex] = true; } } } else { for (var i = 0; i < newData.Length; i++) { removedByView[i, viewIndex] = true; } } } } finally { _isRetainObserverEvents = false; } // determine removed events, those that have a "true" in the remove by view index for all views _removalEvents.Clear(); for (var i = 0; i < newData.Length; i++) { var allTrue = true; for (var j = 0; j < _views.Length; j++) { if (!removedByView[i, j]) { allTrue = false; break; } } if (allTrue) { _removalEvents.Add(newData[i]); _unionWindow.RemoveAll(newData[i]); } } // remove if any if (_removalEvents.IsNotEmpty()) { _isDiscardObserverEvents = true; var viewOldData = _removalEvents.ToArray(); try { for (var j = 0; j < _views.Length; j++) { _views[j].Update(null, viewOldData); } } finally { _isDiscardObserverEvents = false; } } // see if any child view has removed any events. // if there was an insert stream, handle pushed-out events if (_isHasRemovestreamData) { IList <EventBean> removedEvents = null; // process each buffer for (var i = 0; i < _oldEventsPerView.Length; i++) { if (_oldEventsPerView[i] == null) { continue; } var viewOldData = _oldEventsPerView[i]; _oldEventsPerView[i] = null; // clear entry // remove events for union, if the last event was removed then add it foreach (var old in viewOldData) { var isNoMoreRef = _unionWindow.Remove(old); if (isNoMoreRef) { if (removedEvents == null) { _removalEvents.Clear(); removedEvents = _removalEvents; } removedEvents.Add(old); } } } if (removedEvents != null) { if (oldDataColl == null) { oldDataColl = new OneEventCollection(); } foreach (var oldItem in removedEvents) { oldDataColl.Add(oldItem); } } } _newEvents.Clear(); for (var i = 0; i < newData.Length; i++) { if (!_removalEvents.Contains(newData[i])) { _newEvents.Add(newData[i]); } } if (_newEvents.IsNotEmpty()) { newDataPosted = _newEvents.ToArray(); } } // indicate new and, possibly, old data if (HasViews && ((newDataPosted != null) || (oldDataColl != null))) { UpdateChildren(newDataPosted, oldDataColl != null ? oldDataColl.ToArray() : null); } }
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, ViewFactory); agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(ViewFactory, newData, oldData); // handle remove stream OneEventCollection oldDataColl = null; EventBean[] newDataPosted = null; if (oldData != null) { isDiscardObserverEvents = true; // disable reaction logic in observer try { foreach (var view in views) { agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, null, oldData); view.Update(null, oldData); agentInstanceContext.InstrumentationProvider.AViewIndicate(); } } finally { isDiscardObserverEvents = false; } // remove from union foreach (var oldEvent in oldData) { unionWindow.RemoveAll(oldEvent); } oldDataColl = new OneEventCollection(); oldDataColl.Add(oldData); } // add new event to union if (newData != null) { var removedByView = new bool[newData.Length][] .Fill(() => new bool[views.Length]); foreach (var newEvent in newData) { unionWindow.Add(newEvent, views.Length); } // new events must go to all views // old events, such as when removing from a named window, get removed from all views isHasRemovestreamData = false; // changed by observer logic to indicate new data isRetainObserverEvents = true; // enable retain logic in observer try { for (var viewIndex = 0; viewIndex < views.Length; viewIndex++) { var view = views[viewIndex]; agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, newData, null); view.Update(newData, null); agentInstanceContext.InstrumentationProvider.AViewIndicate(); // first-X asymetric view post no insert stream for events that get dropped, remove these if (newDataChildView != null) { for (var i = 0; i < newData.Length; i++) { var found = false; for (var j = 0; j < newDataChildView.Length; j++) { if (newDataChildView[i] == newData[i]) { found = true; break; } } if (!found) { removedByView[i][viewIndex] = true; } } } else { for (var i = 0; i < newData.Length; i++) { removedByView[i][viewIndex] = true; } } } } finally { isRetainObserverEvents = false; } // determine removed events, those that have a "true" in the remove by view index for all views removalEvents.Clear(); for (var i = 0; i < newData.Length; i++) { var allTrue = true; for (var j = 0; j < views.Length; j++) { if (!removedByView[i][j]) { allTrue = false; break; } } if (allTrue) { removalEvents.Add(newData[i]); unionWindow.RemoveAll(newData[i]); } } // remove if any if (!removalEvents.IsEmpty()) { isDiscardObserverEvents = true; var viewOldData = removalEvents.ToArray(); try { for (var j = 0; j < views.Length; j++) { agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, null, viewOldData); views[j].Update(null, viewOldData); agentInstanceContext.InstrumentationProvider.AViewIndicate(); } } finally { isDiscardObserverEvents = false; } } // see if any child view has removed any events. // if there was an insert stream, handle pushed-out events if (isHasRemovestreamData) { IList<EventBean> removedEvents = null; // process each buffer for (var i = 0; i < oldEventsPerView.Length; i++) { if (oldEventsPerView[i] == null) { continue; } var viewOldData = oldEventsPerView[i]; oldEventsPerView[i] = null; // clear entry // remove events for union, if the last event was removed then add it foreach (var old in viewOldData) { var isNoMoreRef = unionWindow.Remove(old); if (isNoMoreRef) { if (removedEvents == null) { removalEvents.Clear(); removedEvents = removalEvents; } removedEvents.Add(old); } } } if (removedEvents != null) { if (oldDataColl == null) { oldDataColl = new OneEventCollection(); } foreach (var oldItem in removedEvents) { oldDataColl.Add(oldItem); } } } newEvents.Clear(); for (var i = 0; i < newData.Length; i++) { if (!removalEvents.Contains(newData[i])) { newEvents.Add(newData[i]); } } if (!newEvents.IsEmpty()) { newDataPosted = newEvents.ToArray(); } } // indicate new and, possibly, old data if (Child != null && (newDataPosted != null || oldDataColl != null)) { var oldDataToPost = oldDataColl != null ? oldDataColl.ToArray() : null; agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, newDataPosted, oldDataToPost); Child.Update(newDataPosted, oldDataToPost); agentInstanceContext.InstrumentationProvider.AViewIndicate(); } agentInstanceContext.InstrumentationProvider.AViewProcessIRStream(); }
public CompositeTableLookupStrategy(EventType eventType, int lookupStream, IList <QueryGraphValueEntryHashKeyed> hashKeys, IList <QueryGraphValueEntryRange> rangeKeyPairs, PropertyCompositeEventTable index) { _eventType = eventType; _index = index; _rangeKeyPairs = rangeKeyPairs; _chain = CompositeIndexQueryFactory.MakeJoinSingleLookupStream(false, lookupStream, hashKeys, index.OptKeyCoercedTypes, rangeKeyPairs, index.OptRangeCoercedTypes); var expressionTexts = new ArrayDeque <string>(); foreach (QueryGraphValueEntryRange pair in rangeKeyPairs) { ExprNode[] expressions = pair.Expressions; foreach (ExprNode node in expressions) { expressionTexts.Add(ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(node)); } } _lookupStrategyDesc = new LookupStrategyDesc(LookupStrategyType.COMPOSITE, expressionTexts.ToArray()); }