use of io.siddhi.core.query.processor.stream.window.WindowProcessor in project siddhi by siddhi-io.
the class Window method init.
/**
* Initialize the WindowEvent table by creating {@link WindowProcessor} to handle the events.
*
* @param tableMap map of {@link Table}s
* @param eventWindowMap map of EventWindows
* @param windowName name of the query window belongs to.
* @param findToBeExecuted will find will be executed on the window.
*/
public void init(Map<String, Table> tableMap, Map<String, Window> eventWindowMap, String windowName, boolean findToBeExecuted) {
if (this.windowProcessor != null) {
return;
}
// Create and initialize MetaStreamEvent
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addInputDefinition(windowDefinition);
metaStreamEvent.setEventType(MetaStreamEvent.EventType.WINDOW);
for (Attribute attribute : windowDefinition.getAttributeList()) {
metaStreamEvent.addOutputData(attribute);
}
this.streamEventFactory = new StreamEventFactory(metaStreamEvent);
StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, this.streamEventFactory);
OutputStream.OutputEventType outputEventType = windowDefinition.getOutputEventType();
boolean outputExpectsExpiredEvents = outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS;
SiddhiQueryContext siddhiQueryContext = new SiddhiQueryContext(siddhiAppContext, windowName);
WindowProcessor internalWindowProcessor = (WindowProcessor) SingleInputStreamParser.generateProcessor(windowDefinition.getWindow(), metaStreamEvent, new ArrayList<VariableExpressionExecutor>(), tableMap, false, outputExpectsExpiredEvents, findToBeExecuted, siddhiQueryContext);
internalWindowProcessor.setStreamEventCloner(streamEventCloner);
internalWindowProcessor.constructStreamEventPopulater(metaStreamEvent, 0);
EntryValveProcessor entryValveProcessor = null;
if (internalWindowProcessor instanceof SchedulingProcessor) {
entryValveProcessor = new EntryValveProcessor(this.siddhiAppContext);
Scheduler scheduler = SchedulerParser.parse(entryValveProcessor, siddhiQueryContext);
scheduler.init(this.lockWrapper, windowName);
scheduler.setStreamEventFactory(streamEventFactory);
((SchedulingProcessor) internalWindowProcessor).setScheduler(scheduler);
}
if (entryValveProcessor != null) {
entryValveProcessor.setToLast(internalWindowProcessor);
this.windowProcessor = entryValveProcessor;
} else {
this.windowProcessor = internalWindowProcessor;
}
// StreamPublishProcessor must be the last in chain so that it can publish the events to StreamJunction
this.windowProcessor.setToLast(new StreamPublishProcessor(outputEventType));
this.internalWindowProcessor = internalWindowProcessor;
}
Aggregations