Esempio n. 1
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            IntersectBatchViewLocalState localState = _factory.GetBatchViewLocalStatePerThread();

            // handle remove stream: post oldData to all views
            if (oldData != null && oldData.Length != 0)
            {
                try
                {
                    localState.IsIgnoreViewIRStream = true;
                    for (int i = 0; i < _views.Length; i++)
                    {
                        _views[i].Update(newData, oldData);
                    }
                }
                finally
                {
                    localState.IsIgnoreViewIRStream = false;
                }
            }

            if (newData != null)
            {
                // post to all non-batch views first to let them decide the remove stream, if any
                try
                {
                    localState.IsCaptureIRNonBatch = true;
                    for (int i = 0; i < _views.Length; i++)
                    {
                        if (i != _factory.BatchViewIndex)
                        {
                            _views[i].Update(newData, oldData);
                        }
                    }
                }
                finally
                {
                    localState.IsCaptureIRNonBatch = false;
                }

                // if there is any data removed from non-batch views, remove from all views
                // collect removed events
                localState.RemovedEvents.Clear();
                for (int i = 0; i < _views.Length; i++)
                {
                    if (localState.OldEventsPerView[i] != null)
                    {
                        for (int j = 0; j < _views.Length; j++)
                        {
                            if (i == j)
                            {
                                continue;
                            }
                            _views[j].Update(null, localState.OldEventsPerView[i]);

                            for (int k = 0; k < localState.OldEventsPerView[i].Length; k++)
                            {
                                localState.RemovedEvents.Add(localState.OldEventsPerView[i][k]);
                            }
                        }
                        localState.OldEventsPerView[i] = null;
                    }
                }

                // post only new events to the batch view that have not been removed
                EventBean[] newDataNonRemoved;
                if (_factory.IsAsymmetric())
                {
                    newDataNonRemoved = EventBeanUtility.GetNewDataNonRemoved(
                        newData, localState.RemovedEvents, localState.NewEventsPerView);
                }
                else
                {
                    newDataNonRemoved = EventBeanUtility.GetNewDataNonRemoved(newData, localState.RemovedEvents);
                }
                if (newDataNonRemoved != null)
                {
                    _views[_factory.BatchViewIndex].Update(newDataNonRemoved, null);
                }
            }
        }
Esempio n. 2
0
        public void NewData(int streamId, EventBean[] newEvents, EventBean[] oldEvents)
        {
            IntersectBatchViewLocalState localState = _factory.GetBatchViewLocalStatePerThread();

            if (localState.IsIgnoreViewIRStream)
            {
                return;
            }

            if (localState.IsCaptureIRNonBatch)
            {
                localState.OldEventsPerView[streamId] = oldEvents;
                if (_factory.IsAsymmetric())
                {
                    localState.NewEventsPerView[streamId] = newEvents;
                }
                return;
            }

            // handle case where irstream originates from view, i.e. timer-based
            if (streamId == _factory.BatchViewIndex)
            {
                UpdateChildren(newEvents, oldEvents);
                if (newEvents != null)
                {
                    try
                    {
                        localState.IsIgnoreViewIRStream = true;
                        for (int i = 0; i < _views.Length; i++)
                        {
                            if (i != streamId)
                            {
                                _views[i].Update(null, newEvents);
                            }
                        }
                    }
                    finally
                    {
                        localState.IsIgnoreViewIRStream = false;
                    }
                }
            }
            // post remove stream to all other views
            else
            {
                if (oldEvents != null)
                {
                    try
                    {
                        localState.IsIgnoreViewIRStream = true;
                        for (int i = 0; i < _views.Length; i++)
                        {
                            if (i != streamId)
                            {
                                _views[i].Update(null, oldEvents);
                            }
                        }
                    }
                    finally
                    {
                        localState.IsIgnoreViewIRStream = false;
                    }
                }
            }
        }