예제 #1
0
        /// <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.IsNotEmpty())
                {
                    newData = _currentBatch.ToArray();
                }
                if ((_lastBatch != null) && (_lastBatch.IsNotEmpty()))
                {
                    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))
                {
                    Instrument.With(
                        i => i.QViewIndicate(this, _timeBatchViewFactory.ViewName, newData, oldData),
                        i => i.AViewIndicate(),
                        () => UpdateChildren(newData, oldData));
                }
            }

            // 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.IsNotEmpty()) || ((_lastBatch != null) && (_lastBatch.IsNotEmpty()))
                ||
                (_isForceOutput))
            {
                ScheduleCallback();
                _isCallbackScheduled = true;
            }

            _lastBatch    = _currentBatch;
            _currentBatch = new ArrayDeque <EventBean>();
        }
예제 #2
0
        /// <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>();
        }
예제 #3
0
        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();
        }
예제 #4
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);
            }
        }