use of io.siddhi.core.query.input.stream.state.receiver.PatternMultiProcessStreamReceiver in project siddhi by wso2.
the class StateInputStreamParser method parseInputStream.
public static StateStreamRuntime parseInputStream(StateInputStream stateInputStream, 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, SiddhiQueryContext siddhiQueryContext) {
Map<String, ProcessStreamReceiver> processStreamReceiverMap = new HashMap<String, ProcessStreamReceiver>();
StateStreamRuntime stateStreamRuntime = new StateStreamRuntime(siddhiQueryContext, metaStateEvent);
Object patternSyncObject = new Object();
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, patternSyncObject, siddhiQueryContext));
} else {
processStreamReceiverMap.put(streamId, new PatternSingleProcessStreamReceiver(streamId, patternSyncObject, siddhiQueryContext));
}
} else {
if (stateInputStream.getStateType() == StateInputStream.Type.SEQUENCE) {
processStreamReceiverMap.put(streamId, new SequenceMultiProcessStreamReceiver(streamId, streamCount, stateStreamRuntime, patternSyncObject, siddhiQueryContext));
} else {
processStreamReceiverMap.put(streamId, new PatternMultiProcessStreamReceiver(streamId, streamCount, patternSyncObject, siddhiQueryContext));
}
}
}
StateElement stateElement = stateInputStream.getStateElement();
List<PreStateProcessor> preStateProcessors = new ArrayList<>();
List<PreStateProcessor> startupPreStateProcessors = new ArrayList<>();
InnerStateRuntime innerStateRuntime = parse(stateElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, variableExpressionExecutors, processStreamReceiverMap, null, null, stateInputStream.getStateType(), false, preStateProcessors, true, startupPreStateProcessors, siddhiQueryContext);
stateStreamRuntime.setInnerStateRuntime(innerStateRuntime);
stateStreamRuntime.setStartupPreStateProcessors(startupPreStateProcessors);
for (ProcessStreamReceiver processStreamReceiver : processStreamReceiverMap.values()) {
processStreamReceiver.setAllStatefulProcessors(preStateProcessors);
}
if (stateInputStream.getWithinTime() != null) {
List<Integer> startStateIdList = new ArrayList<>();
for (PreStateProcessor preStateProcessor : preStateProcessors) {
if (preStateProcessor.isStartState()) {
startStateIdList.add(preStateProcessor.getStateId());
}
}
int[] startStateIds = Ints.toArray(startStateIdList);
for (PreStateProcessor preStateProcessor : preStateProcessors) {
preStateProcessor.setStartStateIds(startStateIds);
preStateProcessor.setWithinTime(stateInputStream.getWithinTime().value());
}
}
((StreamPreStateProcessor) innerStateRuntime.getFirstProcessor()).setThisLastProcessor((StreamPostStateProcessor) innerStateRuntime.getLastProcessor());
return stateStreamRuntime;
}
Aggregations