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);
}
}