Package com.espertech.esper.collection

Examples of com.espertech.esper.collection.OneEventCollection


        return parent.getEventType();
    }

    public final void update(EventBean[] newData, EventBean[] oldData)
    {
        OneEventCollection oldDataToPost = null;
        if (oldData != null)
        {
            for (EventBean anOldData : oldData)
            {
                boolean removed = events.remove(anOldData);
                if (removed)
                {
                    if (oldDataToPost == null)
                    {
                        oldDataToPost = new OneEventCollection();
                    }
                    oldDataToPost.add(anOldData);
                }
            }
        }

        // add data points to the timeWindow
        OneEventCollection newDataToPost = null;
        if ((!isClosed) && (newData != null))
        {
            for (EventBean aNewData : newData)
            {
                events.add(aNewData);
                if (newDataToPost == null)
                {
                    newDataToPost = new OneEventCollection();
                }
                newDataToPost.add(aNewData);
            }
        }

        // If there are child views, call update method
        if ((this.hasViews()) && ((newDataToPost != null) || (oldDataToPost != null)))
        {
            updateChildren((newDataToPost != null) ? newDataToPost.toArray() : null,
                           (oldDataToPost != null) ? oldDataToPost.toArray() : null);
        }
    }
View Full Code Here


        return parent.getEventType();
    }

    public final void update(EventBean[] newData, EventBean[] oldData)
    {
        OneEventCollection newDataToPost = null;
        OneEventCollection oldDataToPost = null;

        // add data points to the window as long as its not full, ignoring later events
        if (newData != null)
        {
            for (EventBean aNewData : newData)
            {
                if (indexedEvents.size() < size)
                {
                    if (newDataToPost == null)
                    {
                        newDataToPost = new OneEventCollection();
                    }
                    newDataToPost.add(aNewData);
                    indexedEvents.add(aNewData);
                }
            }
        }

        if (oldData != null)
        {
            for (EventBean anOldData : oldData)
            {
                boolean removed = indexedEvents.remove(anOldData);
                if (removed)
                {
                    if (oldDataToPost == null)
                    {
                        oldDataToPost = new OneEventCollection();
                    }
                    oldDataToPost.add(anOldData);
                }
            }
        }

        // If there are child views, call update method
        if ((this.hasViews()) && ((newDataToPost != null) || (oldDataToPost != null)))
        {
            updateChildren((newDataToPost != null) ? newDataToPost.toArray() : null,
                           (oldDataToPost != null) ? oldDataToPost.toArray() : null);
        }
    }
View Full Code Here

        return parent.getEventType();
    }

    public final void update(EventBean[] newData, EventBean[] oldData)
    {
        OneEventCollection postOldData = null;

        if (this.hasViews())
        {
            postOldData = new OneEventCollection();
        }

        if (newData != null)
        {
            for (int i = 0; i < newData.length; i++)
            {
                // Obtain unique value
                MultiKey<Object> key = getUniqueKey(newData[i]);

                // If there are no child views, just update the own collection
                if (!this.hasViews())
                {
                    mostRecentEvents.put(key, newData[i]);
                    continue;
                }

                // Post the last value as old data
                EventBean lastValue = mostRecentEvents.get(key);
                if (lastValue != null)
                {
                    postOldData.add(lastValue);
                }

                // Override with recent event
                mostRecentEvents.put(key, newData[i]);
            }
        }

        if (oldData != null)
        {
            for (int i = 0; i < oldData.length; i++)
            {
                // Obtain unique value
                MultiKey<Object> key = getUniqueKey(oldData[i]);

                // If the old event is the current unique event, remove and post as old data
                EventBean lastValue = mostRecentEvents.get(key);
                if (lastValue != oldData[i])
                {
                    continue;
                }

                postOldData.add(lastValue);
                mostRecentEvents.remove(key);
            }
        }


        // If there are child views, fireStatementStopped update method
        if (this.hasViews())
        {
            if (postOldData.isEmpty())
            {
                updateChildren(newData, null);
            }
            else
            {
                updateChildren(newData, postOldData.toArray());
            }
        }
    }
View Full Code Here

        return parent.getEventType();
    }

    public void update(EventBean[] newData, EventBean[] 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 (this.hasViews())
        {
            if ((oldDataToPost != null) && (!oldDataToPost.isEmpty()))
            {
                updateChildren(newData, oldDataToPost.toArray());
            }
            else
            {
                updateChildren(newData, null);
            }
View Full Code Here

        };
    }

    @Override
    public void stop() {
        OneEventCollection oldEvents = new OneEventCollection();
        for (Map.Entry<EventBean, EventBean> oldEvent : newToOldEventMap.entrySet()) {
            oldEvents.add(oldEvent.getValue());
        }
        if (!oldEvents.isEmpty()) {
            updateChildren(null, oldEvents.toArray());
        }
        newToOldEventMap.clear();
    }
View Full Code Here

    // 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()) {
            TimestampEventPair newest = window.getLast();

            while (true) {
                TimestampEventPair first = window.getFirst();

                boolean pass = checkEvent(first, newest, expiredCount);
                if (!pass) {
                    if (expired == null) {
                         expired = new OneEventCollection();
                    }
                    expired.add(window.removeFirst().getEvent());
                    expiredCount++;
                }
                else {
                    break;
                }

                if (window.isEmpty()) {
                    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)
        {
View Full Code Here

        if ((eventData == null) || (eventData.length == 0))
        {
            return null;
        }

        OneEventCollection filtered = null;
        for (EventBean event : eventData)
        {
            eventPerStream[0] = event;
            boolean pass = true;
            for (ExprEvaluator filter : filterList)
            {
                Boolean result = (Boolean) filter.evaluate(eventPerStream, isNewData, exprEvaluatorContext);
                if ((result != null) && (!result))
                {
                    pass = false;
                    break;
                }
            }

            if (pass)
            {
                if (filtered == null)
                {
                    filtered = new OneEventCollection();
                }
                filtered.add(event);
            }
        }

        if (filtered == null)
        {
            return null;
        }
        return filtered.toArray();
    }
View Full Code Here

    public void handleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents)
    {
        if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qNamedWindowOnAction(OnTriggerType.ON_MERGE, triggerEvents, matchingEvents);}

        OneEventCollection newData = new OneEventCollection();
        OneEventCollection oldData = null;
        EventBean[] eventsPerStream = new EventBean[3]; // first:named window, second: trigger, third:before-update (optional)

        if ((matchingEvents == null) || (matchingEvents.length == 0)){

            List<NamedWindowOnMergeMatch> unmatched = parent.getNamedWindowOnMergeHelper().getUnmatched();

            for (EventBean triggerEvent : triggerEvents) {
                eventsPerStream[1] = triggerEvent;

                if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qNamedWindowMergeWhenThens(false, triggerEvent, unmatched);}

                int count = -1;
                for (NamedWindowOnMergeMatch action : unmatched) {
                    count++;

                    if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qNamedWindowMergeWhenThenItem(false, action, count);}
                    if (!action.isApplies(eventsPerStream, super.getExprEvaluatorContext())) {
                        if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aNamedWindowMergeWhenThenItem(false, false);}
                        continue;
                    }
                    action.apply(null, eventsPerStream, newData, oldData, super.getExprEvaluatorContext());
                    if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aNamedWindowMergeWhenThenItem(false, true);}
                    break// apply no other actions
                }

                if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aNamedWindowMergeWhenThens(false);}
            }
        }
        else {

            // handle update/
            oldData = new OneEventCollection();

            List<NamedWindowOnMergeMatch> matched = parent.getNamedWindowOnMergeHelper().getMatched();

            for (EventBean triggerEvent : triggerEvents) {
                eventsPerStream[1] = triggerEvent;
                if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qNamedWindowMergeWhenThens(true, triggerEvent, matched);}

                for (EventBean matchingEvent : matchingEvents) {
                    eventsPerStream[0] = matchingEvent;

                    int count = -1;
                    for (NamedWindowOnMergeMatch action : matched) {
                        count++;

                        if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qNamedWindowMergeWhenThenItem(true, action, count);}
                        if (!action.isApplies(eventsPerStream, super.getExprEvaluatorContext())) {
                            if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aNamedWindowMergeWhenThenItem(true, false);}
                            continue;
                        }
                        action.apply(matchingEvent, eventsPerStream, newData, oldData, super.getExprEvaluatorContext());
                        if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aNamedWindowMergeWhenThenItem(true, true);}
                        break// apply no other actions
                    }
                }

                if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aNamedWindowMergeWhenThens(true);}
            }

        }

        if (!newData.isEmpty() || (oldData != null && !oldData.isEmpty()))
        {
            if ((MetricReportingPath.isMetricsEnabled) && (parent.getCreateNamedWindowMetricHandle().isEnabled()) && !newData.isEmpty())
            {
                parent.getMetricReportingService().accountTime(parent.getCreateNamedWindowMetricHandle(), 0, 0, newData.toArray().length);
            }

            // Events to delete are indicated via old data
            // The on-merge listeners receive the events deleted, but only if there is interest
            if (parent.getStatementResultService().isMakeNatural()) {
                EventBean[] eventsPerStreamNaturalNew = newData.isEmpty() ? null : newData.toArray();
                EventBean[] eventsPerStreamNaturalOld = (oldData == null || oldData.isEmpty()) ? null : oldData.toArray();
                this.rootView.update(EventBeanUtility.denaturalize(eventsPerStreamNaturalNew), EventBeanUtility.denaturalize(eventsPerStreamNaturalOld));
                updateChildren(eventsPerStreamNaturalNew, eventsPerStreamNaturalOld);
            }
            else {
                EventBean[] eventsPerStreamNew = newData.isEmpty() ? null : newData.toArray();
                EventBean[] eventsPerStreamOld = (oldData == null || oldData.isEmpty()) ? null : oldData.toArray();
                this.rootView.update(eventsPerStreamNew, eventsPerStreamOld);
                if (parent.getStatementResultService().isMakeSynthetic()) {
                    updateChildren(eventsPerStreamNew, eventsPerStreamOld);
                }
            }
View Full Code Here

    public final void update(EventBean[] newData, EventBean[] oldData)
    {
        if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qViewProcessIRStream(this, timeFirstViewFactory.getViewName(), newData, oldData);}

        OneEventCollection oldDataToPost = null;
        if (oldData != null)
        {
            for (EventBean anOldData : oldData)
            {
                boolean removed = events.remove(anOldData);
                if (removed)
                {
                    if (oldDataToPost == null)
                    {
                        oldDataToPost = new OneEventCollection();
                    }
                    oldDataToPost.add(anOldData);
                    internalHandleRemoved(anOldData);
                }
            }
        }

        // add data points to the timeWindow
        OneEventCollection newDataToPost = null;
        if ((!isClosed) && (newData != null))
        {
            for (EventBean aNewData : newData)
            {
                events.add(aNewData);
                if (newDataToPost == null)
                {
                    newDataToPost = new OneEventCollection();
                }
                newDataToPost.add(aNewData);
                internalHandleAdded(aNewData);
            }
        }

        // If there are child views, call update method
        if ((this.hasViews()) && ((newDataToPost != null) || (oldDataToPost != null)))
        {
            EventBean[] nd = (newDataToPost != null) ? newDataToPost.toArray() : null;
            EventBean[] od = (oldDataToPost != null) ? oldDataToPost.toArray() : null;
            if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qViewIndicate(this, timeFirstViewFactory.getViewName(), nd, od);}
            updateChildren(nd, od);
            if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aViewIndicate();}
        }
View Full Code Here

    public final void update(EventBean[] newData, EventBean[] oldData)
    {
        if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qViewProcessIRStream(this, lengthFirstFactory.getViewName(), newData, oldData);}

        OneEventCollection newDataToPost = null;
        OneEventCollection oldDataToPost = null;

        // add data points to the window as long as its not full, ignoring later events
        if (newData != null)
        {
            for (EventBean aNewData : newData)
            {
                if (indexedEvents.size() < size)
                {
                    if (newDataToPost == null)
                    {
                        newDataToPost = new OneEventCollection();
                    }
                    newDataToPost.add(aNewData);
                    indexedEvents.add(aNewData);
                    internalHandleAdded(aNewData);
                }
            }
        }

        if (oldData != null)
        {
            for (EventBean anOldData : oldData)
            {
                boolean removed = indexedEvents.remove(anOldData);
                if (removed)
                {
                    if (oldDataToPost == null)
                    {
                        oldDataToPost = new OneEventCollection();
                    }
                    oldDataToPost.add(anOldData);
                    internalHandleRemoved(anOldData);
                }
            }
        }

        // If there are child views, call update method
        if ((this.hasViews()) && ((newDataToPost != null) || (oldDataToPost != null)))
        {
            EventBean[] nd = (newDataToPost != null) ? newDataToPost.toArray() : null;
            EventBean[] od = (oldDataToPost != null) ? oldDataToPost.toArray() : null;
            if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qViewIndicate(this, lengthFirstFactory.getViewName(), nd, od);}
            updateChildren(nd, od);
            if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aViewIndicate();}
        }
View Full Code Here

TOP

Related Classes of com.espertech.esper.collection.OneEventCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.