Search in sources :

Example 6 with Scheduler

use of org.ballerinalang.siddhi.core.util.Scheduler in project ballerina by ballerina-lang.

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 queryName      name of the query window belongs to.
 */
public void init(Map<String, Table> tableMap, Map<String, Window> eventWindowMap, String queryName) {
    if (this.windowProcessor != null) {
        return;
    }
    // Create and initialize MetaStreamEvent
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addInputDefinition(windowDefinition);
    metaStreamEvent.setEventType(MetaStreamEvent.EventType.WINDOW);
    metaStreamEvent.initializeAfterWindowData();
    for (Attribute attribute : windowDefinition.getAttributeList()) {
        metaStreamEvent.addOutputData(attribute);
    }
    this.streamEventPool = new StreamEventPool(metaStreamEvent, 5);
    StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, this.streamEventPool);
    OutputStream.OutputEventType outputEventType = windowDefinition.getOutputEventType();
    boolean outputExpectsExpiredEvents = outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS;
    WindowProcessor internalWindowProcessor = (WindowProcessor) SingleInputStreamParser.generateProcessor(windowDefinition.getWindow(), metaStreamEvent, new ArrayList<VariableExpressionExecutor>(), this.siddhiAppContext, tableMap, false, outputExpectsExpiredEvents, queryName);
    internalWindowProcessor.setStreamEventCloner(streamEventCloner);
    internalWindowProcessor.constructStreamEventPopulater(metaStreamEvent, 0);
    EntryValveProcessor entryValveProcessor = null;
    if (internalWindowProcessor instanceof SchedulingProcessor) {
        entryValveProcessor = new EntryValveProcessor(this.siddhiAppContext);
        Scheduler scheduler = SchedulerParser.parse(this.siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, this.siddhiAppContext);
        scheduler.init(this.lockWrapper, queryName);
        scheduler.setStreamEventPool(streamEventPool);
        ((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(org.ballerinalang.siddhi.query.api.definition.Attribute) Scheduler(org.ballerinalang.siddhi.core.util.Scheduler) OutputStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.OutputStream) ArrayList(java.util.ArrayList) SchedulingProcessor(org.ballerinalang.siddhi.core.query.processor.SchedulingProcessor) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.ballerinalang.siddhi.core.event.stream.StreamEventCloner) EntryValveProcessor(org.ballerinalang.siddhi.core.query.input.stream.single.EntryValveProcessor) WindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.WindowProcessor) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)

Aggregations

Scheduler (org.ballerinalang.siddhi.core.util.Scheduler)6 EntryValveProcessor (org.ballerinalang.siddhi.core.query.input.stream.single.EntryValveProcessor)5 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)3 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 ArrayList (java.util.ArrayList)2 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)2 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)2 SchedulingProcessor (org.ballerinalang.siddhi.core.query.processor.SchedulingProcessor)2 WindowProcessor (org.ballerinalang.siddhi.core.query.processor.stream.window.WindowProcessor)2 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)2 AbstractMap (java.util.AbstractMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 AggregationRuntime (org.ballerinalang.siddhi.core.aggregation.AggregationRuntime)1 IncrementalAggregationProcessor (org.ballerinalang.siddhi.core.aggregation.IncrementalAggregationProcessor)1 IncrementalExecutor (org.ballerinalang.siddhi.core.aggregation.IncrementalExecutor)1 RecreateInMemoryData (org.ballerinalang.siddhi.core.aggregation.RecreateInMemoryData)1 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)1 StreamEventCloner (org.ballerinalang.siddhi.core.event.stream.StreamEventCloner)1