public void testFlattenList() { // test many arrays EventBean[] testEvents = makeEventArray(new String[] {"a1", "a2", "b1", "b2", "b3", "c1", "c2"}); ArrayDeque<UniformPair<EventBean[]>> eventVector = new ArrayDeque<UniformPair<EventBean[]>>(); eventVector.add( new UniformPair<EventBean[]>(null, new EventBean[] {testEvents[0], testEvents[1]})); eventVector.add(new UniformPair<EventBean[]>(new EventBean[] {testEvents[2]}, null)); eventVector.add( new UniformPair<EventBean[]>( null, new EventBean[] {testEvents[3], testEvents[4], testEvents[5]})); eventVector.add(new UniformPair<EventBean[]>(new EventBean[] {testEvents[6]}, null)); UniformPair<EventBean[]> events = EventBeanUtility.flattenList(eventVector); EPAssertionUtil.assertEqualsExactOrder( new EventBean[] {testEvents[2], testEvents[6]}, events.getFirst()); EPAssertionUtil.assertEqualsExactOrder( new EventBean[] {testEvents[0], testEvents[1], testEvents[3], testEvents[4], testEvents[5]}, events.getSecond()); // test just one array eventVector.clear(); eventVector.add(new UniformPair<EventBean[]>(new EventBean[] {testEvents[2]}, null)); events = EventBeanUtility.flattenList(eventVector); EPAssertionUtil.assertEqualsExactOrder(new EventBean[] {testEvents[2]}, events.getFirst()); EPAssertionUtil.assertEqualsExactOrder((Object[]) null, events.getSecond()); // test empty vector eventVector.clear(); events = EventBeanUtility.flattenList(eventVector); assertNull(events); }
public void handleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents) { EventBean[] newData; // clear state from prior results resultSetProcessor.clear(); // build join result // use linked hash set to retain order of join results for last/first/window to work most // intuitively Set<MultiKey<EventBean>> newEvents = new LinkedHashSet<MultiKey<EventBean>>(); for (int i = 0; i < triggerEvents.length; i++) { EventBean triggerEvent = triggerEvents[0]; if (matchingEvents != null) { for (int j = 0; j < matchingEvents.length; j++) { EventBean[] eventsPerStream = new EventBean[2]; eventsPerStream[0] = matchingEvents[j]; eventsPerStream[1] = triggerEvent; newEvents.add(new MultiKey<EventBean>(eventsPerStream)); } } } // process matches UniformPair<EventBean[]> pair = resultSetProcessor.processJoinResult(newEvents, oldEvents, false); newData = (pair != null ? pair.getFirst() : null); if (isDistinct) { newData = EventBeanUtility.getDistinctByProp(newData, eventBeanReader); } if (internalEventRouter != null) { if (newData != null) { for (int i = 0; i < newData.length; i++) { internalEventRouter.route( newData[i], statementHandle, statementContext.getInternalEventEngineRouteDest(), statementContext, addToFront); } } } // The on-select listeners receive the events selected if ((newData != null) && (newData.length > 0)) { // And post only if we have listeners/subscribers that need the data if (statementResultService.isMakeNatural() || statementResultService.isMakeSynthetic()) { updateChildren(newData, null); } } lastResult = newData; // clear state from prior results resultSetProcessor.clear(); }
public static void output( boolean forceUpdate, UniformPair<EventBean[]> result, UpdateDispatchView finalView) { EventBean[] newEvents = result != null ? result.getFirst() : null; EventBean[] oldEvents = result != null ? result.getSecond() : null; if (newEvents != null || oldEvents != null) { finalView.newResult(result); } else if (forceUpdate) { finalView.newResult(result); } }
/** * Indicate statement result. * * @param newOldEvents result */ public static void indicateEarlyReturn( StatementContext statementContext, UniformPair<EventBean[]> newOldEvents) { if (newOldEvents == null) { return; } if ((statementContext.getMetricReportingService() != null) && (statementContext.getMetricReportingService().getStatementOutputHooks() != null) && (!statementContext.getMetricReportingService().getStatementOutputHooks().isEmpty())) { for (StatementResultListener listener : statementContext.getMetricReportingService().getStatementOutputHooks()) { listener.update( newOldEvents.getFirst(), newOldEvents.getSecond(), statementContext.getStatementName(), null, null); } } }