Esempio n. 1
0
        public override void Apply(
            EventBean matchingEvent,
            EventBean[] eventsPerStream,
            OneEventCollection newData,
            OneEventCollection oldData,
            AgentInstanceContext agentInstanceContext)
        {
            var theEvent = insertHelper.Process(eventsPerStream, true, true, agentInstanceContext);

            if (insertIntoTable != null) {
                var tableInstance = insertIntoTable.GetTableInstance(agentInstanceContext.AgentInstanceId);
                tableInstance.AddEventUnadorned(theEvent);
                return;
            }

            if (!route) {
                newData.Add(theEvent);
                return;
            }
            
            if (insertIntoTable != null) {
                var tableInstance = insertIntoTable.GetTableInstance(agentInstanceContext.AgentInstanceId);
                tableInstance.AddEventUnadorned(theEvent);
                return;
            }

            if (audit) {
                agentInstanceContext.AuditProvider.Insert(theEvent, agentInstanceContext);
            }

            agentInstanceContext.InternalEventRouter.Route(theEvent, agentInstanceContext, false);
        }
Esempio n. 2
0
        public override void Apply(EventBean matchingEvent, EventBean[] eventsPerStream, OneEventCollection newData, OneEventCollection oldData, ExprEvaluatorContext exprEvaluatorContext)
        {
            EventBean copy = _updateHelper.UpdateWCopy(matchingEvent, eventsPerStream, exprEvaluatorContext);

            newData.Add(copy);
            oldData.Add(matchingEvent);
        }
Esempio n. 3
0
        private void CompareAndAddOrPassthru(EventBean eventBean, Object uniqueKey, Object newSortKey, OneEventCollection removedEvents)
        {
            // determine full or not
            if (_numberOfEvents >= _sortWindowSize)
            {
                var compared = _comparator.Compare(_sortedEvents.Keys.Last(), newSortKey);

                // this new event will fall outside of the ranks or coincides with the last entry, so its an old event already
                if (compared < 0)
                {
                    removedEvents.Add(eventBean);
                }
                // this new event is higher in sort key then the last entry so we are interested
                else
                {
                    _uniqueKeySortKeys.Put(uniqueKey, newSortKey);
                    _numberOfEvents++;
                    CollectionUtil.AddEventByKeyLazyListMapBack(newSortKey, eventBean, _sortedEvents);
                    InternalHandleAddedKey(newSortKey, eventBean);
                }
            }
            // not yet filled, need to add
            else
            {
                _uniqueKeySortKeys.Put(uniqueKey, newSortKey);
                _numberOfEvents++;
                CollectionUtil.AddEventByKeyLazyListMapBack(newSortKey, eventBean, _sortedEvents);
                InternalHandleAddedKey(newSortKey, eventBean);
            }
        }
        public override void Apply(EventBean matchingEvent, EventBean[] eventsPerStream, OneEventCollection newData, OneEventCollection oldData, ExprEvaluatorContext exprEvaluatorContext)
        {
            EventBean theEvent = _insertHelper.Process(eventsPerStream, true, true, exprEvaluatorContext);

            if (_insertIntoTableName != null)
            {
                TableStateInstance tableStateInstance = _tableService.GetState(_insertIntoTableName, exprEvaluatorContext.AgentInstanceId);
                if (_audit)
                {
                    AuditPath.AuditInsertInto(tableStateInstance.AgentInstanceContext.EngineURI, _statementHandle.StatementName, theEvent);
                }
                tableStateInstance.AddEventUnadorned(theEvent);
                return;
            }

            if (_internalEventRouter == null)
            {
                newData.Add(theEvent);
                return;
            }

            if (_audit)
            {
                AuditPath.AuditInsertInto(_internalEventRouteDest.EngineURI, _statementHandle.StatementName, theEvent);
            }
            _internalEventRouter.Route(theEvent, _statementHandle, _internalEventRouteDest, exprEvaluatorContext, false);
        }
Esempio n. 5
0
 public override void Apply(
     EventBean matchingEvent,
     EventBean[] eventsPerStream,
     OneEventCollection newData,
     OneEventCollection oldData,
     AgentInstanceContext agentInstanceContext)
 {
     oldData.Add(matchingEvent);
 }
Esempio n. 6
0
 public override void Apply(
     EventBean matchingEvent,
     EventBean[] eventsPerStream,
     OneEventCollection newData,
     OneEventCollection oldData,
     AgentInstanceContext agentInstanceContext)
 {
     var copy = namedWindowUpdate.Invoke(matchingEvent, eventsPerStream, agentInstanceContext);
     newData.Add(copy);
     oldData.Add(matchingEvent);
 }
 public void Add(EventBean theEvent, EventBean[] eventsPerStream, bool isNewData, ExprEvaluatorContext context)
 {
     if (_coll == null)
     {
         _coll = new OneEventCollection();
     }
     if (theEvent is NaturalEventBean)
     {
         theEvent = ((NaturalEventBean)theEvent).OptionalSynthetic;
     }
     _coll.Add(_tableMetadata.EventToPublic.Convert(theEvent, eventsPerStream, isNewData, context));
 }
Esempio n. 8
0
        public override void HandleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraOnAction(OnTriggerType.ON_UPDATE, triggerEvents, matchingEvents);
            }

            if ((matchingEvents == null) || (matchingEvents.Length == 0))
            {
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AInfraOnAction();
                }
                return;
            }

            var eventsPerStream = new EventBean[3];

            var newData = new OneEventCollection();
            var oldData = new OneEventCollection();

            foreach (var triggerEvent in triggerEvents)
            {
                eventsPerStream[1] = triggerEvent;
                foreach (var matchingEvent in matchingEvents)
                {
                    var copy = _parent.UpdateHelper.UpdateWCopy(matchingEvent, eventsPerStream, base.ExprEvaluatorContext);
                    newData.Add(copy);
                    oldData.Add(matchingEvent);
                }
            }

            if (!newData.IsEmpty())
            {
                // Events to delete are indicated via old data
                RootView.Update(newData.ToArray(), oldData.ToArray());

                // The on-delete listeners receive the events deleted, but only if there is interest
                if (_parent.StatementResultService.IsMakeNatural || _parent.StatementResultService.IsMakeSynthetic)
                {
                    UpdateChildren(newData.ToArray(), oldData.ToArray());
                }
            }

            // Keep the last delete records
            _lastResult = matchingEvents;
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraOnAction();
            }
        }
        public void Stop(AgentInstanceStopServices services)
        {
            if (!newToOldEventMap.IsEmpty()) {
                var oldEvents = new OneEventCollection();
                foreach (var oldEvent in newToOldEventMap) {
                    oldEvents.Add(oldEvent.Value);
                }

                if (!oldEvents.IsEmpty()) {
                    Child.Update(null, oldEvents.ToArray());
                }

                newToOldEventMap.Clear();
            }
        }
Esempio n. 10
0
 public void Stop()
 {
     if (!_newToOldEventMap.IsEmpty())
     {
         var oldEvents = new OneEventCollection();
         foreach (var oldEvent in _newToOldEventMap)
         {
             oldEvents.Add(oldEvent.Value);
         }
         if (!oldEvents.IsEmpty())
         {
             UpdateChildren(null, oldEvents.ToArray());
         }
         _newToOldEventMap.Clear();
     }
 }
Esempio n. 11
0
        public override void HandleMatching(
            EventBean[] triggerEvents,
            EventBean[] matchingEvents)
        {
            agentInstanceContext.InstrumentationProvider.QInfraOnAction(
                OnTriggerType.ON_UPDATE,
                triggerEvents,
                matchingEvents);

            if (matchingEvents == null || matchingEvents.Length == 0) {
                agentInstanceContext.InstrumentationProvider.AInfraOnAction();
                return;
            }

            var eventsPerStream = new EventBean[3];

            var newData = new OneEventCollection();
            var oldData = new OneEventCollection();

            foreach (var triggerEvent in triggerEvents) {
                eventsPerStream[1] = triggerEvent;
                foreach (var matchingEvent in matchingEvents) {
                    var copy = parent.UpdateHelperNamedWindow.Invoke(
                        matchingEvent,
                        eventsPerStream,
                        ExprEvaluatorContext);
                    newData.Add(copy);
                    oldData.Add(matchingEvent);
                }
            }

            if (!newData.IsEmpty()) {
                // Events to delete are indicated via old data
                rootView.Update(newData.ToArray(), oldData.ToArray());

                // The on-delete listeners receive the events deleted, but only if there is interest
                var statementResultService = agentInstanceContext.StatementResultService;
                if (statementResultService.IsMakeNatural || statementResultService.IsMakeSynthetic) {
                    Child?.Update(newData.ToArray(), oldData.ToArray());
                }
            }

            // Keep the last delete records
            agentInstanceContext.InstrumentationProvider.AInfraOnAction();
        }
Esempio n. 12
0
        // Called based on schedule evaluation registered when a variable changes (new data is null).
        // Called when new data arrives.
        private void Expire(EventBean[] newData, EventBean[] oldData)
        {
            OneEventCollection expired = null;

            if (oldData != null)
            {
                expired = new OneEventCollection();
                expired.Add(oldData);
            }
            int expiredCount = 0;

            if (!_window.IsEmpty())
            {
                ExpressionWindowTimestampEventPair newest = _window.Last;

                while (true)
                {
                    ExpressionWindowTimestampEventPair first = _window.First;

                    bool pass = CheckEvent(first, newest, expiredCount);
                    if (!pass)
                    {
                        if (expired == null)
                        {
                            expired = new OneEventCollection();
                        }
                        EventBean removed = _window.RemoveFirst().TheEvent;
                        expired.Add(removed);
                        if (AggregationService != null)
                        {
                            _removedEvents[0] = removed;
                            AggregationService.ApplyLeave(_removedEvents, null, AgentInstanceContext);
                        }
                        expiredCount++;
                        InternalHandleExpired(first);
                    }
                    else
                    {
                        break;
                    }

                    if (_window.IsEmpty())
                    {
                        if (AggregationService != null)
                        {
                            AggregationService.ClearResults(AgentInstanceContext);
                        }
                        break;
                    }
                }
            }

            // Check for any events that get pushed out of the window
            EventBean[] expiredArr = null;
            if (expired != null)
            {
                expiredArr = expired.ToArray();
            }

            // update event buffer for access by expressions, if any
            if (ViewUpdatedCollection != null)
            {
                ViewUpdatedCollection.Update(newData, expiredArr);
            }

            // If there are child views, call update method
            if (HasViews)
            {
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QViewIndicate(this, _dataWindowViewFactory.ViewName, newData, expiredArr);
                }
                UpdateChildren(newData, expiredArr);
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AViewIndicate();
                }
            }
        }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            using (Instrument.With(
                       i => i.QViewProcessIRStream(this, _unionViewFactory.ViewName, newData, oldData),
                       i => i.AViewProcessIRStream()))
            {
                OneEventCollection oldDataColl = null;
                if (oldData != null)
                {
                    _isDiscardObserverEvents = true; // disable reaction logic in observer

                    try
                    {
                        foreach (View view in _views)
                        {
                            view.Update(null, oldData);
                        }
                    }
                    finally
                    {
                        _isDiscardObserverEvents = false;
                    }

                    // remove from union
                    foreach (EventBean oldEvent in oldData)
                    {
                        _unionWindow.RemoveAll(oldEvent);
                    }

                    oldDataColl = new OneEventCollection();
                    oldDataColl.Add(oldData);
                }

                // add new event to union
                if (newData != null)
                {
                    foreach (EventBean 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
                    {
                        foreach (View view in _views)
                        {
                            view.Update(newData, null);
                        }
                    }
                    finally
                    {
                        _isRetainObserverEvents = 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 (int i = 0; i < _oldEventsPerView.Length; i++)
                        {
                            if (_oldEventsPerView[i] == null)
                            {
                                continue;
                            }

                            EventBean[] viewOldData = _oldEventsPerView[i];
                            _oldEventsPerView[i] = null; // clear entry

                            // remove events for union, if the last event was removed then add it
                            foreach (EventBean old in viewOldData)
                            {
                                bool 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 (EventBean oldItem in removedEvents)
                            {
                                oldDataColl.Add(oldItem);
                            }
                        }
                    }
                }

                if (HasViews)
                {
                    // indicate new and, possibly, old data
                    EventBean[] oldEvents = oldDataColl != null?oldDataColl.ToArray() : null;

                    Instrument.With(
                        i => i.QViewIndicate(this, _unionViewFactory.ViewName, newData, oldEvents),
                        i => i.AViewIndicate(),
                        () => UpdateChildren(newData, oldEvents));
                }
            }
        }
Esempio n. 15
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, ViewFactory);
            agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(ViewFactory, newData, oldData);

            OneEventCollection oldDataColl = 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) {
                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 {
                    foreach (var view in views) {
                        agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, newData, null);
                        view.Update(newData, null);
                        agentInstanceContext.InstrumentationProvider.AViewIndicate();
                    }
                }
                finally {
                    isRetainObserverEvents = 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);
                        }
                    }
                }
            }

            if (child != null) {
                // indicate new and, possibly, old data
                var oldEvents = oldDataColl != null ? oldDataColl.ToArray() : null;
                agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, newData, oldEvents);
                child.Update(newData, oldEvents);
                agentInstanceContext.InstrumentationProvider.AViewIndicate();
            }

            agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }
Esempio n. 16
0
 public override void Apply(EventBean matchingEvent, EventBean[] eventsPerStream, OneEventCollection newData, OneEventCollection oldData, ExprEvaluatorContext exprEvaluatorContext)
 {
     oldData.Add(matchingEvent);
 }
Esempio n. 17
0
        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();
        }
Esempio n. 18
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QViewProcessIRStream(this, _rankWindowViewFactory.ViewName, newData, oldData);
            }

            var removedEvents = new OneEventCollection();

            // Remove old data
            if (oldData != null)
            {
                for (var i = 0; i < oldData.Length; i++)
                {
                    var uniqueKey       = GetUniqueValues(oldData[i]);
                    var existingSortKey = _uniqueKeySortKeys.Get(uniqueKey);

                    if (existingSortKey == null)
                    {
                        continue;
                    }

                    var theEvent = RemoveFromSortedEvents(existingSortKey, uniqueKey);
                    if (theEvent != null)
                    {
                        _numberOfEvents--;
                        _uniqueKeySortKeys.Remove(uniqueKey);
                        removedEvents.Add(theEvent);
                        InternalHandleRemovedKey(existingSortKey, oldData[i]);
                    }
                }
            }

            // Add new data
            if (newData != null)
            {
                for (var i = 0; i < newData.Length; i++)
                {
                    var uniqueKey       = GetUniqueValues(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);
                    }
                    // same unique-key event found already, remove and add again
                    else
                    {
                        // 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
            if (_numberOfEvents > _sortWindowSize)
            {
                while (_numberOfEvents > _sortWindowSize)
                {
                    var lastKey  = _sortedEvents.Keys.Last();
                    var existing = _sortedEvents.Get(lastKey);
                    if (existing is IList <EventBean> )
                    {
                        var existingList = (IList <EventBean>)existing;
                        while (_numberOfEvents > _sortWindowSize && !existingList.IsEmpty())
                        {
                            var newestEvent = existingList.DeleteAt(0);
                            var uniqueKey   = GetUniqueValues(newestEvent);
                            _uniqueKeySortKeys.Remove(uniqueKey);
                            _numberOfEvents--;
                            removedEvents.Add(newestEvent);
                            InternalHandleRemovedKey(existing, newestEvent);
                        }
                        if (existingList.IsEmpty())
                        {
                            _sortedEvents.Remove(lastKey);
                        }
                    }
                    else
                    {
                        var lastSortedEvent = (EventBean)existing;
                        var uniqueKey       = GetUniqueValues(lastSortedEvent);
                        _uniqueKeySortKeys.Remove(uniqueKey);
                        _numberOfEvents--;
                        removedEvents.Add(lastSortedEvent);
                        _sortedEvents.Remove(lastKey);
                        InternalHandleRemovedKey(lastKey, lastSortedEvent);
                    }
                }
            }

            // If there are child views, fireStatementStopped Update method
            if (_optionalRankedRandomAccess != null)
            {
                _optionalRankedRandomAccess.Refresh(_sortedEvents, _numberOfEvents, _sortWindowSize);
            }
            if (HasViews)
            {
                EventBean[] expiredArr = null;
                if (!removedEvents.IsEmpty())
                {
                    expiredArr = removedEvents.ToArray();
                }

                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QViewIndicate(this, _rankWindowViewFactory.ViewName, newData, expiredArr);
                }
                UpdateChildren(newData, expiredArr);
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AViewIndicate();
                }
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AViewProcessIRStream();
            }
        }
Esempio n. 19
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            _agentInstanceContext.AuditProvider.View(newData, oldData, _agentInstanceContext, _viewFactory);
            _agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(_viewFactory, newData, oldData);

            OneEventCollection oldDataToPost = null;

            if (newData != null && newData.Length == 1 && (oldData == null || oldData.Length == 0)) {
                var currentLast = _lastEvent;
                _lastEvent = newData[0];
                if (child != null) {
                    var oldDataToPostHere = currentLast == null ? null : new[] {currentLast};
                    _agentInstanceContext.InstrumentationProvider.QViewIndicate(_viewFactory, newData, oldDataToPostHere);
                    child.Update(newData, oldDataToPostHere);
                    _agentInstanceContext.InstrumentationProvider.AViewIndicate();
                }
            }
            else {
                if (newData != null && newData.Length != 0) {
                    if (_lastEvent != null) {
                        oldDataToPost = new OneEventCollection();
                        oldDataToPost.Add(_lastEvent);
                    }

                    if (newData.Length > 1) {
                        for (var i = 0; i < newData.Length - 1; i++) {
                            if (oldDataToPost == null) {
                                oldDataToPost = new OneEventCollection();
                            }

                            oldDataToPost.Add(newData[i]);
                        }
                    }

                    _lastEvent = newData[newData.Length - 1];
                }

                if (oldData != null) {
                    for (var i = 0; i < oldData.Length; i++) {
                        if (oldData[i] == _lastEvent) {
                            if (oldDataToPost == null) {
                                oldDataToPost = new OneEventCollection();
                            }

                            oldDataToPost.Add(oldData[i]);
                            _lastEvent = null;
                        }
                    }
                }

                // If there are child views, fireStatementStopped update method
                if (child != null) {
                    if (oldDataToPost != null && !oldDataToPost.IsEmpty()) {
                        var oldDataArray = oldDataToPost.ToArray();
                        _agentInstanceContext.InstrumentationProvider.QViewIndicate(_viewFactory, newData, oldDataArray);
                        child.Update(newData, oldDataArray);
                        _agentInstanceContext.InstrumentationProvider.AViewIndicate();
                    }
                    else {
                        _agentInstanceContext.InstrumentationProvider.QViewIndicate(_viewFactory, newData, null);
                        child.Update(newData, null);
                        _agentInstanceContext.InstrumentationProvider.AViewIndicate();
                    }
                }
            }

            _agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }
Esempio n. 20
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QViewProcessIRStream(this, LastElementViewFactory.NAME, newData, oldData);
            }
            OneEventCollection oldDataToPost = null;

            if ((newData != null) && (newData.Length != 0))
            {
                if (_lastEvent != null)
                {
                    oldDataToPost = new OneEventCollection();
                    oldDataToPost.Add(_lastEvent);
                }
                if (newData.Length > 1)
                {
                    for (int i = 0; i < newData.Length - 1; i++)
                    {
                        if (oldDataToPost == null)
                        {
                            oldDataToPost = new OneEventCollection();
                        }
                        oldDataToPost.Add(newData[i]);
                    }
                }
                _lastEvent = newData[newData.Length - 1];
            }

            if (oldData != null)
            {
                for (int i = 0; i < oldData.Length; i++)
                {
                    if (oldData[i] == _lastEvent)
                    {
                        if (oldDataToPost == null)
                        {
                            oldDataToPost = new OneEventCollection();
                        }
                        oldDataToPost.Add(oldData[i]);
                        _lastEvent = null;
                    }
                }
            }

            // If there are child views, fireStatementStopped Update method
            if (HasViews)
            {
                if ((oldDataToPost != null) && (!oldDataToPost.IsEmpty()))
                {
                    EventBean[] oldDataArray = oldDataToPost.ToArray();
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().QViewIndicate(this, LastElementViewFactory.NAME, newData, oldDataArray);
                    }
                    UpdateChildren(newData, oldDataArray);
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().AViewIndicate();
                    }
                }
                else
                {
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().QViewIndicate(this, LastElementViewFactory.NAME, newData, null);
                    }
                    UpdateChildren(newData, null);
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().AViewIndicate();
                    }
                }
            }
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AViewProcessIRStream();
            }
        }
Esempio n. 21
0
        // Called based on schedule evaluation registered when a variable changes (new data is null).
        // Called when new data arrives.
        private void Expire(
            EventBean[] newData,
            EventBean[] oldData)
        {
            OneEventCollection expired = null;
            if (oldData != null) {
                expired = new OneEventCollection();
                expired.Add(oldData);
            }

            var expiredCount = 0;
            if (!window.IsEmpty()) {
                var newest = window.Last;

                while (true) {
                    var first = window.First;

                    var pass = CheckEvent(first, newest, expiredCount);
                    if (!pass) {
                        if (expired == null) {
                            expired = new OneEventCollection();
                        }

                        var removed = window.RemoveFirst().TheEvent;
                        expired.Add(removed);
                        if (aggregationService != null) {
                            removedEvents[0] = removed;
                            aggregationService.ApplyLeave(removedEvents, null, agentInstanceContext);
                        }

                        expiredCount++;
                        InternalHandleExpired(first);
                    }
                    else {
                        break;
                    }

                    if (window.IsEmpty()) {
                        aggregationService?.ClearResults(agentInstanceContext);

                        break;
                    }
                }
            }

            // Check for any events that get pushed out of the window
            EventBean[] expiredArr = null;
            if (expired != null) {
                expiredArr = expired.ToArray();
            }

            // update event buffer for access by expressions, if any
            viewUpdatedCollection?.Update(newData, expiredArr);

            // If there are child views, call update method
            if (child != null) {
                agentInstanceContext.InstrumentationProvider.QViewIndicate(factory, newData, expiredArr);
                child.Update(newData, expiredArr);
                agentInstanceContext.InstrumentationProvider.AViewIndicate();
            }
        }