Search in sources :

Example 6 with WindowProcessor

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;
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) Scheduler(io.siddhi.core.util.Scheduler) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) ArrayList(java.util.ArrayList) SchedulingProcessor(io.siddhi.core.query.processor.SchedulingProcessor) SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) EntryValveProcessor(io.siddhi.core.query.input.stream.single.EntryValveProcessor) WindowProcessor(io.siddhi.core.query.processor.stream.window.WindowProcessor) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Aggregations

MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)6 WindowProcessor (io.siddhi.core.query.processor.stream.window.WindowProcessor)6 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)4 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)4 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)4 ConfigReader (io.siddhi.core.util.config.ConfigReader)4 Attribute (io.siddhi.query.api.definition.Attribute)4 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)2 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)2 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)2 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)2 OperationNotSupportedException (io.siddhi.core.exception.OperationNotSupportedException)2 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)2 JoinProcessor (io.siddhi.core.query.input.stream.join.JoinProcessor)2 EntryValveProcessor (io.siddhi.core.query.input.stream.single.EntryValveProcessor)2 Processor (io.siddhi.core.query.processor.Processor)2 SchedulingProcessor (io.siddhi.core.query.processor.SchedulingProcessor)2 FilterProcessor (io.siddhi.core.query.processor.filter.FilterProcessor)2 AbstractStreamProcessor (io.siddhi.core.query.processor.stream.AbstractStreamProcessor)2 AggregateWindowProcessor (io.siddhi.core.query.processor.stream.window.AggregateWindowProcessor)2