use of org.ballerinalang.siddhi.core.query.processor.SchedulingProcessor in project ballerina by ballerina-lang.
the class QueryParserHelper method initSingleStreamRuntime.
private static void initSingleStreamRuntime(SingleStreamRuntime singleStreamRuntime, int streamEventChainIndex, MetaComplexEvent metaComplexEvent, StateEventPool stateEventPool, LockWrapper lockWrapper, String queryName) {
MetaStreamEvent metaStreamEvent;
if (metaComplexEvent instanceof MetaStateEvent) {
metaStreamEvent = ((MetaStateEvent) metaComplexEvent).getMetaStreamEvent(streamEventChainIndex);
} else {
metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
}
StreamEventPool streamEventPool = new StreamEventPool(metaStreamEvent, 5);
ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
processStreamReceiver.setMetaStreamEvent(metaStreamEvent);
processStreamReceiver.setStreamEventPool(streamEventPool);
processStreamReceiver.setLockWrapper(lockWrapper);
processStreamReceiver.init();
Processor processor = singleStreamRuntime.getProcessorChain();
while (processor != null) {
if (processor instanceof SchedulingProcessor) {
((SchedulingProcessor) processor).getScheduler().setStreamEventPool(streamEventPool);
((SchedulingProcessor) processor).getScheduler().init(lockWrapper, queryName);
}
if (processor instanceof AbstractStreamProcessor) {
((AbstractStreamProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventPool));
((AbstractStreamProcessor) processor).constructStreamEventPopulater(metaStreamEvent, streamEventChainIndex);
}
if (stateEventPool != null && processor instanceof JoinProcessor) {
if (((JoinProcessor) processor).getCompiledCondition() instanceof IncrementalAggregateCompileCondition) {
IncrementalAggregateCompileCondition compiledCondition = (IncrementalAggregateCompileCondition) ((JoinProcessor) processor).getCompiledCondition();
ComplexEventPopulater complexEventPopulater = StreamEventPopulaterFactory.constructEventPopulator(metaStreamEvent, 0, compiledCondition.getAdditionalAttributes());
compiledCondition.setComplexEventPopulater(complexEventPopulater);
}
((JoinProcessor) processor).setStateEventPool(stateEventPool);
((JoinProcessor) processor).setJoinLock(lockWrapper);
}
if (stateEventPool != null && processor instanceof StreamPreStateProcessor) {
((StreamPreStateProcessor) processor).setStateEventPool(stateEventPool);
((StreamPreStateProcessor) processor).setStreamEventPool(streamEventPool);
((StreamPreStateProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventPool));
if (metaComplexEvent instanceof MetaStateEvent) {
((StreamPreStateProcessor) processor).setStateEventCloner(new StateEventCloner(((MetaStateEvent) metaComplexEvent), stateEventPool));
}
}
processor = processor.getNextProcessor();
}
}
use of org.ballerinalang.siddhi.core.query.processor.SchedulingProcessor in project ballerina by ballerina-lang.
the class SingleStreamRuntime method clone.
@Override
public StreamRuntime clone(String key) {
ProcessStreamReceiver clonedProcessStreamReceiver = this.processStreamReceiver.clone(key);
EntryValveProcessor entryValveProcessor = null;
SchedulingProcessor schedulingProcessor;
Processor clonedProcessorChain = null;
if (processorChain != null) {
if (!(processorChain instanceof QuerySelector || processorChain instanceof OutputRateLimiter)) {
clonedProcessorChain = processorChain.cloneProcessor(key);
if (clonedProcessorChain instanceof EntryValveProcessor) {
entryValveProcessor = (EntryValveProcessor) clonedProcessorChain;
}
}
Processor processor = processorChain.getNextProcessor();
while (processor != null) {
if (!(processor instanceof QuerySelector || processor instanceof OutputRateLimiter)) {
Processor clonedProcessor = processor.cloneProcessor(key);
clonedProcessorChain.setToLast(clonedProcessor);
if (clonedProcessor instanceof EntryValveProcessor) {
entryValveProcessor = (EntryValveProcessor) clonedProcessor;
} else if (clonedProcessor instanceof SchedulingProcessor) {
schedulingProcessor = (SchedulingProcessor) clonedProcessor;
schedulingProcessor.setScheduler(((SchedulingProcessor) processor).getScheduler().clone(key, entryValveProcessor));
}
}
processor = processor.getNextProcessor();
}
}
return new SingleStreamRuntime(clonedProcessStreamReceiver, clonedProcessorChain, metaComplexEvent);
}
use of org.ballerinalang.siddhi.core.query.processor.SchedulingProcessor in project ballerina by ballerina-lang.
the class SingleInputStreamParser method parseInputStream.
/**
* Parse single InputStream and return SingleStreamRuntime.
*
* @param inputStream single input stream to be parsed
* @param siddhiAppContext query to be parsed
* @param variableExpressionExecutors List to hold VariableExpressionExecutors to update after query parsing
* @param streamDefinitionMap Stream Definition Map
* @param tableDefinitionMap Table Definition Map
* @param windowDefinitionMap window definition map
* @param aggregationDefinitionMap aggregation definition map
* @param tableMap Table Map
* @param metaComplexEvent MetaComplexEvent
* @param processStreamReceiver ProcessStreamReceiver
* @param supportsBatchProcessing supports batch processing
* @param outputExpectsExpiredEvents is output expects ExpiredEvents
* @param queryName query name of single input stream belongs to.
* @return SingleStreamRuntime
*/
public static SingleStreamRuntime parseInputStream(SingleInputStream inputStream, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, MetaComplexEvent metaComplexEvent, ProcessStreamReceiver processStreamReceiver, boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents, String queryName) {
Processor processor = null;
EntryValveProcessor entryValveProcessor = null;
boolean first = true;
MetaStreamEvent metaStreamEvent;
if (metaComplexEvent instanceof MetaStateEvent) {
metaStreamEvent = new MetaStreamEvent();
((MetaStateEvent) metaComplexEvent).addEvent(metaStreamEvent);
initMetaStreamEvent(inputStream, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, metaStreamEvent);
} else {
metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
initMetaStreamEvent(inputStream, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, metaStreamEvent);
}
// A window cannot be defined for a window stream
if (!inputStream.getStreamHandlers().isEmpty() && windowDefinitionMap != null && windowDefinitionMap.containsKey(inputStream.getStreamId())) {
for (StreamHandler handler : inputStream.getStreamHandlers()) {
if (handler instanceof Window) {
throw new OperationNotSupportedException("Cannot create " + ((Window) handler).getName() + " " + "window for the window stream " + inputStream.getStreamId());
}
}
}
if (!inputStream.getStreamHandlers().isEmpty()) {
for (StreamHandler handler : inputStream.getStreamHandlers()) {
Processor currentProcessor = generateProcessor(handler, metaComplexEvent, variableExpressionExecutors, siddhiAppContext, tableMap, supportsBatchProcessing, outputExpectsExpiredEvents, queryName);
if (currentProcessor instanceof SchedulingProcessor) {
if (entryValveProcessor == null) {
entryValveProcessor = new EntryValveProcessor(siddhiAppContext);
if (first) {
processor = entryValveProcessor;
first = false;
} else {
processor.setToLast(entryValveProcessor);
}
}
Scheduler scheduler = SchedulerParser.parse(siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, siddhiAppContext);
((SchedulingProcessor) currentProcessor).setScheduler(scheduler);
}
if (first) {
processor = currentProcessor;
first = false;
} else {
processor.setToLast(currentProcessor);
}
}
}
metaStreamEvent.initializeAfterWindowData();
return new SingleStreamRuntime(processStreamReceiver, processor, metaComplexEvent);
}
use of org.ballerinalang.siddhi.core.query.processor.SchedulingProcessor 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;
}
Aggregations