Ejemplo n.º 1
0
        public void NewData(int streamId, EventBean[] newEvents, EventBean[] oldEvents)
        {
            IntersectAsymetricViewLocalState localState = _factory.GetAsymetricViewLocalStatePerThread();

            localState.NewDataChildView = newEvents;

            if ((oldEvents == null) || (localState.IsDiscardObserverEvents))
            {
                return;
            }

            if (localState.IsRetainObserverEvents)
            {
                localState.OldEventsPerView[streamId] = oldEvents;
                localState.HasRemovestreamData        = true;
                return;
            }

            // remove old data from all other views
            localState.IsDiscardObserverEvents = true;
            try
            {
                for (int i = 0; i < _views.Length; i++)
                {
                    if (i != streamId)
                    {
                        _views[i].Update(null, oldEvents);
                    }
                }
            }
            finally
            {
                localState.IsDiscardObserverEvents = false;
            }

            UpdateChildren(null, oldEvents);
        }
Ejemplo n.º 2
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            IntersectAsymetricViewLocalState localState = _factory.GetAsymetricViewLocalStatePerThread();

            localState.OldEvents.Clear();
            EventBean[] newDataPosted = null;

            // handle remove stream
            if (oldData != null)
            {
                localState.IsDiscardObserverEvents = true;     // disable reaction logic in observer
                try
                {
                    foreach (View view in _views)
                    {
                        view.Update(null, oldData);
                    }
                }
                finally
                {
                    localState.IsDiscardObserverEvents = false;
                }

                for (int i = 0; i < oldData.Length; i++)
                {
                    localState.OldEvents.Add(oldData[i]);
                }
            }

            if (newData != null)
            {
                localState.RemovalEvents.Clear();

                // new events must go to all views
                // old events, such as when removing from a named window, get removed from all views
                localState.HasRemovestreamData    = false;  // changed by observer logic to indicate new data
                localState.IsRetainObserverEvents = true;   // enable retain logic in observer
                try
                {
                    foreach (View view in _views)
                    {
                        localState.NewDataChildView = null;
                        view.Update(newData, oldData);

                        // first-X asymetric view post no insert stream for events that get dropped, remove these
                        if (localState.NewDataChildView != null)
                        {
                            for (int i = 0; i < newData.Length; i++)
                            {
                                bool found = false;
                                for (int j = 0; j < localState.NewDataChildView.Length; j++)
                                {
                                    if (localState.NewDataChildView[i] == newData[i])
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                                if (!found)
                                {
                                    localState.RemovalEvents.Add(newData[i]);
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < newData.Length; i++)
                            {
                                localState.RemovalEvents.Add(newData[i]);
                            }
                        }
                    }
                }
                finally
                {
                    localState.IsRetainObserverEvents = false;
                }

                if (!localState.RemovalEvents.IsEmpty())
                {
                    localState.IsDiscardObserverEvents = true;
                    EventBean[] viewOldData = localState.RemovalEvents.ToArray();
                    try
                    {
                        for (int j = 0; j < _views.Length; j++)
                        {
                            _views[j].Update(null, viewOldData);
                        }
                    }
                    finally
                    {
                        localState.IsDiscardObserverEvents = false;
                    }
                }

                // see if any child view has removed any events.
                // if there was an insert stream, handle pushed-out events
                if (localState.HasRemovestreamData)
                {
                    // process each buffer
                    for (int i = 0; i < localState.OldEventsPerView.Length; i++)
                    {
                        if (localState.OldEventsPerView[i] == null)
                        {
                            continue;
                        }

                        EventBean[] viewOldData = localState.OldEventsPerView[i];
                        localState.OldEventsPerView[i] = null;     // clear entry

                        // add each event to the set of events removed
                        foreach (EventBean oldEvent in viewOldData)
                        {
                            localState.RemovalEvents.Add(oldEvent);
                        }

                        localState.IsDiscardObserverEvents = true;
                        try
                        {
                            for (int j = 0; j < _views.Length; j++)
                            {
                                if (i != j)
                                {
                                    _views[j].Update(null, viewOldData);
                                }
                            }
                        }
                        finally
                        {
                            localState.IsDiscardObserverEvents = false;
                        }
                    }

                    localState.OldEvents.AddAll(localState.RemovalEvents);
                }

                localState.NewEvents.Clear();
                for (int i = 0; i < newData.Length; i++)
                {
                    if (!localState.RemovalEvents.Contains(newData[i]))
                    {
                        localState.NewEvents.Add(newData[i]);
                    }
                }

                if (!localState.NewEvents.IsEmpty())
                {
                    newDataPosted = localState.NewEvents.ToArray();
                }
            }

            // indicate new and, possibly, old data
            EventBean[] oldDataPosted = null;
            if (!localState.OldEvents.IsEmpty())
            {
                oldDataPosted = localState.OldEvents.ToArray();
            }
            if ((newDataPosted != null) || (oldDataPosted != null))
            {
                UpdateChildren(newDataPosted, oldDataPosted);
            }
            localState.OldEvents.Clear();
        }