Search in sources :

Example 1 with PatternSingleProcessStreamReceiver

use of io.siddhi.core.query.input.stream.state.receiver.PatternSingleProcessStreamReceiver 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;
}
Also used : SequenceSingleProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver) ProcessStreamReceiver(io.siddhi.core.query.input.ProcessStreamReceiver) PatternSingleProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.PatternSingleProcessStreamReceiver) PatternMultiProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.PatternMultiProcessStreamReceiver) SequenceMultiProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) PatternSingleProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.PatternSingleProcessStreamReceiver) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LogicalStateElement(io.siddhi.query.api.execution.query.input.state.LogicalStateElement) NextStateElement(io.siddhi.query.api.execution.query.input.state.NextStateElement) AbsentStreamStateElement(io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) EveryStateElement(io.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(io.siddhi.query.api.execution.query.input.state.StreamStateElement) StateElement(io.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(io.siddhi.query.api.execution.query.input.state.CountStateElement) AbsentStreamPreStateProcessor(io.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor) SequenceSingleProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver) SequenceMultiProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) PatternMultiProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.PatternMultiProcessStreamReceiver) InnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime) StreamInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime) EveryInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime) LogicalInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime) NextInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime) CountInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime) LogicalPreStateProcessor(io.siddhi.core.query.input.stream.state.LogicalPreStateProcessor) CountPreStateProcessor(io.siddhi.core.query.input.stream.state.CountPreStateProcessor) AbsentStreamPreStateProcessor(io.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor) AbsentLogicalPreStateProcessor(io.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor) PreStateProcessor(io.siddhi.core.query.input.stream.state.PreStateProcessor) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor) StateStreamRuntime(io.siddhi.core.query.input.stream.state.StateStreamRuntime)

Aggregations

ProcessStreamReceiver (io.siddhi.core.query.input.ProcessStreamReceiver)1 AbsentLogicalPreStateProcessor (io.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor)1 AbsentStreamPreStateProcessor (io.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor)1 CountPreStateProcessor (io.siddhi.core.query.input.stream.state.CountPreStateProcessor)1 LogicalPreStateProcessor (io.siddhi.core.query.input.stream.state.LogicalPreStateProcessor)1 PreStateProcessor (io.siddhi.core.query.input.stream.state.PreStateProcessor)1 StateStreamRuntime (io.siddhi.core.query.input.stream.state.StateStreamRuntime)1 StreamPreStateProcessor (io.siddhi.core.query.input.stream.state.StreamPreStateProcessor)1 PatternMultiProcessStreamReceiver (io.siddhi.core.query.input.stream.state.receiver.PatternMultiProcessStreamReceiver)1 PatternSingleProcessStreamReceiver (io.siddhi.core.query.input.stream.state.receiver.PatternSingleProcessStreamReceiver)1 SequenceMultiProcessStreamReceiver (io.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver)1 SequenceSingleProcessStreamReceiver (io.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver)1 CountInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime)1 EveryInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime)1 InnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime)1 LogicalInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime)1 NextInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime)1 StreamInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime)1 AbsentStreamStateElement (io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)1 CountStateElement (io.siddhi.query.api.execution.query.input.state.CountStateElement)1