use of org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor 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.input.stream.state.StreamPreStateProcessor in project ballerina by ballerina-lang.
the class StateMultiProcessStreamReceiver method processAndClear.
protected void processAndClear(int processIndex, StreamEvent streamEvent) {
ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>(batchProcessingAllowed);
ComplexEventChunk<StreamEvent> currentStreamEventChunk = new ComplexEventChunk<StreamEvent>(streamEvent, streamEvent, batchProcessingAllowed);
ComplexEventChunk<StateEvent> eventChunk = ((StreamPreStateProcessor) nextProcessors[processIndex]).processAndReturn(currentStreamEventChunk);
if (eventChunk.getFirst() != null) {
retEventChunk.add(eventChunk.getFirst());
}
eventChunk.clear();
if (querySelector != null) {
while (retEventChunk.hasNext()) {
StateEvent stateEvent = retEventChunk.next();
retEventChunk.remove();
querySelector.process(new ComplexEventChunk<StateEvent>(stateEvent, stateEvent, batchProcessingAllowed));
}
}
}
use of org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor in project ballerina by ballerina-lang.
the class SingleProcessStreamReceiver method processAndClear.
protected void processAndClear(ComplexEventChunk<StreamEvent> streamEventChunk) {
ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>(false);
synchronized (lockKey) {
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
streamEventChunk.remove();
stabilizeStates();
currentStreamEventChunk.add(streamEvent);
ComplexEventChunk<StateEvent> eventChunk = ((StreamPreStateProcessor) next).processAndReturn(currentStreamEventChunk);
if (eventChunk.getFirst() != null) {
retEventChunk.add(eventChunk.getFirst());
}
eventChunk.clear();
currentStreamEventChunk.clear();
}
}
while (retEventChunk.hasNext()) {
StateEvent stateEvent = retEventChunk.next();
retEventChunk.remove();
querySelector.process(new ComplexEventChunk<StateEvent>(stateEvent, stateEvent, false));
}
}
use of org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor in project ballerina by ballerina-lang.
the class StreamInnerStateRuntime method clone.
@Override
public InnerStateRuntime clone(String key) {
StreamInnerStateRuntime streamInnerStateRuntime = new StreamInnerStateRuntime(stateType);
for (SingleStreamRuntime singleStreamRuntime : singleStreamRuntimeList) {
streamInnerStateRuntime.singleStreamRuntimeList.add((SingleStreamRuntime) singleStreamRuntime.clone(key));
}
Processor processor = streamInnerStateRuntime.singleStreamRuntimeList.get(0).getProcessorChain();
streamInnerStateRuntime.firstProcessor = (StreamPreStateProcessor) processor;
while (processor != null) {
if (processor instanceof StreamPostStateProcessor) {
streamInnerStateRuntime.lastProcessor = (StreamPostStateProcessor) processor;
break;
} else {
processor = processor.getNextProcessor();
}
}
((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor).setThisStatePreProcessor((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor);
((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor).setThisStatePostProcessor((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor);
((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor).setThisLastProcessor((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor);
return streamInnerStateRuntime;
}
use of org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor in project ballerina by ballerina-lang.
the class StateInputStreamParser method parseInputStream.
public static StateStreamRuntime parseInputStream(StateInputStream stateInputStream, SiddhiAppContext siddhiAppContext, MetaStateEvent metaStateEvent, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, List<VariableExpressionExecutor> variableExpressionExecutors, LatencyTracker latencyTracker, String queryName) {
Map<String, ProcessStreamReceiver> processStreamReceiverMap = new HashMap<String, ProcessStreamReceiver>();
StateStreamRuntime stateStreamRuntime = new StateStreamRuntime(siddhiAppContext, metaStateEvent);
String defaultLockKey = "";
for (String streamId : stateInputStream.getAllStreamIds()) {
int streamCount = stateInputStream.getStreamCount(streamId);
if (streamCount == 1) {
if (stateInputStream.getStateType() == StateInputStream.Type.SEQUENCE) {
processStreamReceiverMap.put(streamId, new SequenceSingleProcessStreamReceiver(streamId, stateStreamRuntime, defaultLockKey, latencyTracker, queryName, siddhiAppContext));
} else {
processStreamReceiverMap.put(streamId, new PatternSingleProcessStreamReceiver(streamId, defaultLockKey, latencyTracker, queryName, siddhiAppContext));
}
} else {
if (stateInputStream.getStateType() == StateInputStream.Type.SEQUENCE) {
processStreamReceiverMap.put(streamId, new SequenceMultiProcessStreamReceiver(streamId, streamCount, stateStreamRuntime, latencyTracker, queryName, siddhiAppContext));
} else {
processStreamReceiverMap.put(streamId, new PatternMultiProcessStreamReceiver(streamId, streamCount, latencyTracker, queryName, siddhiAppContext));
}
}
}
StateElement stateElement = stateInputStream.getStateElement();
InnerStateRuntime innerStateRuntime = parse(stateElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, null, null, stateInputStream.getStateType(), new ArrayList<Map.Entry<Long, Set<Integer>>>(), latencyTracker, queryName);
stateStreamRuntime.setInnerStateRuntime(innerStateRuntime);
((StreamPreStateProcessor) innerStateRuntime.getFirstProcessor()).setThisLastProcessor((StreamPostStateProcessor) innerStateRuntime.getLastProcessor());
return stateStreamRuntime;
}
Aggregations