Search in sources :

Example 1 with StreamPreStateProcessor

use of io.siddhi.core.query.input.stream.state.StreamPreStateProcessor in project siddhi by wso2.

the class StateInputStreamParser method parse.

private static InnerStateRuntime parse(StateElement stateElement, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, MetaStateEvent metaStateEvent, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, ProcessStreamReceiver> processStreamReceiverMap, StreamPreStateProcessor streamPreStateProcessor, StreamPostStateProcessor streamPostStateProcessor, StateInputStream.Type stateType, boolean multiValue, List<PreStateProcessor> preStateProcessors, boolean isStartState, List<PreStateProcessor> startupPreStateProcessors, SiddhiQueryContext siddhiQueryContext) {
    if (stateElement instanceof StreamStateElement) {
        BasicSingleInputStream basicSingleInputStream = ((StreamStateElement) stateElement).getBasicSingleInputStream();
        SingleStreamRuntime singleStreamRuntime = SingleInputStreamParser.parseInputStream(basicSingleInputStream, variableExpressionExecutors, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, processStreamReceiverMap.get(basicSingleInputStream.getUniqueStreamIds().get(0)), false, false, false, multiValue, siddhiQueryContext);
        int stateIndex = metaStateEvent.getStreamEventCount() - 1;
        if (streamPreStateProcessor == null) {
            if (stateElement instanceof AbsentStreamStateElement) {
                AbsentStreamPreStateProcessor absentProcessor = new AbsentStreamPreStateProcessor(stateType, ((AbsentStreamStateElement) stateElement).getWaitingTime().value());
                // Set the scheduler
                startupPreStateProcessors.add(absentProcessor);
                EntryValveProcessor entryValveProcessor = new EntryValveProcessor(siddhiQueryContext.getSiddhiAppContext());
                entryValveProcessor.setToLast(absentProcessor);
                Scheduler scheduler = SchedulerParser.parse(entryValveProcessor, siddhiQueryContext);
                absentProcessor.setScheduler(scheduler);
                // Assign the AbsentStreamPreStateProcessor to streamPreStateProcessor
                streamPreStateProcessor = absentProcessor;
            } else {
                streamPreStateProcessor = new StreamPreStateProcessor(stateType);
            }
            streamPreStateProcessor.init(siddhiQueryContext);
        }
        streamPreStateProcessor.setStateId(stateIndex);
        streamPreStateProcessor.setStartState(isStartState);
        streamPreStateProcessor.setNextProcessor(singleStreamRuntime.getProcessorChain());
        singleStreamRuntime.setProcessorChain(streamPreStateProcessor);
        if (streamPostStateProcessor == null) {
            if (stateElement instanceof AbsentStreamStateElement) {
                streamPostStateProcessor = new AbsentStreamPostStateProcessor();
            } else {
                streamPostStateProcessor = new StreamPostStateProcessor();
            }
        }
        streamPostStateProcessor.setStateId(stateIndex);
        singleStreamRuntime.getProcessorChain().setToLast(streamPostStateProcessor);
        streamPostStateProcessor.setThisStatePreProcessor(streamPreStateProcessor);
        streamPreStateProcessor.setThisStatePostProcessor(streamPostStateProcessor);
        streamPreStateProcessor.setThisLastProcessor(streamPostStateProcessor);
        StreamInnerStateRuntime innerStateRuntime = new StreamInnerStateRuntime(stateType);
        innerStateRuntime.setFirstProcessor(streamPreStateProcessor);
        innerStateRuntime.setLastProcessor(streamPostStateProcessor);
        innerStateRuntime.addStreamRuntime(singleStreamRuntime);
        preStateProcessors.add(streamPreStateProcessor);
        return innerStateRuntime;
    } else if (stateElement instanceof NextStateElement) {
        StateElement currentElement = ((NextStateElement) stateElement).getStateElement();
        InnerStateRuntime currentInnerStateRuntime = parse(currentElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, variableExpressionExecutors, processStreamReceiverMap, streamPreStateProcessor, streamPostStateProcessor, stateType, multiValue, preStateProcessors, isStartState, startupPreStateProcessors, siddhiQueryContext);
        StateElement nextElement = ((NextStateElement) stateElement).getNextStateElement();
        InnerStateRuntime nextInnerStateRuntime = parse(nextElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, variableExpressionExecutors, processStreamReceiverMap, streamPreStateProcessor, streamPostStateProcessor, stateType, multiValue, preStateProcessors, false, startupPreStateProcessors, siddhiQueryContext);
        currentInnerStateRuntime.getLastProcessor().setNextStatePreProcessor(nextInnerStateRuntime.getFirstProcessor());
        NextInnerStateRuntime nextStateRuntime = new NextInnerStateRuntime(currentInnerStateRuntime, nextInnerStateRuntime, stateType);
        nextStateRuntime.setFirstProcessor(currentInnerStateRuntime.getFirstProcessor());
        nextStateRuntime.setLastProcessor(nextInnerStateRuntime.getLastProcessor());
        for (SingleStreamRuntime singleStreamRuntime : currentInnerStateRuntime.getSingleStreamRuntimeList()) {
            nextStateRuntime.addStreamRuntime(singleStreamRuntime);
        }
        for (SingleStreamRuntime singleStreamRuntime : nextInnerStateRuntime.getSingleStreamRuntimeList()) {
            nextStateRuntime.addStreamRuntime(singleStreamRuntime);
        }
        return nextStateRuntime;
    } else if (stateElement instanceof EveryStateElement) {
        StateElement currentElement = ((EveryStateElement) stateElement).getStateElement();
        List<PreStateProcessor> withinEveryPreStateProcessors = new ArrayList<>();
        InnerStateRuntime innerStateRuntime = parse(currentElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, variableExpressionExecutors, processStreamReceiverMap, streamPreStateProcessor, streamPostStateProcessor, stateType, multiValue, withinEveryPreStateProcessors, isStartState, startupPreStateProcessors, siddhiQueryContext);
        EveryInnerStateRuntime everyInnerStateRuntime = new EveryInnerStateRuntime(innerStateRuntime, stateType);
        everyInnerStateRuntime.setFirstProcessor(innerStateRuntime.getFirstProcessor());
        everyInnerStateRuntime.setLastProcessor(innerStateRuntime.getLastProcessor());
        for (SingleStreamRuntime singleStreamRuntime : innerStateRuntime.getSingleStreamRuntimeList()) {
            everyInnerStateRuntime.addStreamRuntime(singleStreamRuntime);
        }
        everyInnerStateRuntime.getLastProcessor().setNextEveryStatePreProcessor(everyInnerStateRuntime.getFirstProcessor());
        for (PreStateProcessor preStateProcessor : withinEveryPreStateProcessors) {
            preStateProcessor.setWithinEveryPreStateProcessor(everyInnerStateRuntime.getFirstProcessor());
        }
        preStateProcessors.addAll(withinEveryPreStateProcessors);
        return everyInnerStateRuntime;
    } else if (stateElement instanceof LogicalStateElement) {
        LogicalStateElement.Type type = ((LogicalStateElement) stateElement).getType();
        LogicalPreStateProcessor logicalPreStateProcessor1;
        if (((LogicalStateElement) stateElement).getStreamStateElement1() instanceof AbsentStreamStateElement) {
            logicalPreStateProcessor1 = new AbsentLogicalPreStateProcessor(type, stateType, ((AbsentStreamStateElement) ((LogicalStateElement) stateElement).getStreamStateElement1()).getWaitingTime());
            // Set the scheduler
            startupPreStateProcessors.add(logicalPreStateProcessor1);
            EntryValveProcessor entryValveProcessor = new EntryValveProcessor(siddhiQueryContext.getSiddhiAppContext());
            entryValveProcessor.setToLast(logicalPreStateProcessor1);
            Scheduler scheduler = SchedulerParser.parse(entryValveProcessor, siddhiQueryContext);
            ((SchedulingProcessor) logicalPreStateProcessor1).setScheduler(scheduler);
        } else {
            logicalPreStateProcessor1 = new LogicalPreStateProcessor(type, stateType);
        }
        logicalPreStateProcessor1.init(siddhiQueryContext);
        LogicalPostStateProcessor logicalPostStateProcessor1;
        if (((LogicalStateElement) stateElement).getStreamStateElement1() instanceof AbsentStreamStateElement) {
            logicalPostStateProcessor1 = new AbsentLogicalPostStateProcessor(type);
        } else {
            logicalPostStateProcessor1 = new LogicalPostStateProcessor(type);
        }
        LogicalPreStateProcessor logicalPreStateProcessor2;
        if (((LogicalStateElement) stateElement).getStreamStateElement2() instanceof AbsentStreamStateElement) {
            logicalPreStateProcessor2 = new AbsentLogicalPreStateProcessor(type, stateType, ((AbsentStreamStateElement) ((LogicalStateElement) stateElement).getStreamStateElement2()).getWaitingTime());
            startupPreStateProcessors.add(logicalPreStateProcessor2);
            EntryValveProcessor entryValveProcessor = new EntryValveProcessor(siddhiQueryContext.getSiddhiAppContext());
            entryValveProcessor.setToLast(logicalPreStateProcessor2);
            Scheduler scheduler = SchedulerParser.parse(entryValveProcessor, siddhiQueryContext);
            ((SchedulingProcessor) logicalPreStateProcessor2).setScheduler(scheduler);
        } else {
            logicalPreStateProcessor2 = new LogicalPreStateProcessor(type, stateType);
        }
        logicalPreStateProcessor2.init(siddhiQueryContext);
        LogicalPostStateProcessor logicalPostStateProcessor2;
        if (((LogicalStateElement) stateElement).getStreamStateElement2() instanceof AbsentStreamStateElement) {
            logicalPostStateProcessor2 = new AbsentLogicalPostStateProcessor(type);
        } else {
            logicalPostStateProcessor2 = new LogicalPostStateProcessor(type);
        }
        logicalPostStateProcessor1.setPartnerPreStateProcessor(logicalPreStateProcessor2);
        logicalPostStateProcessor2.setPartnerPreStateProcessor(logicalPreStateProcessor1);
        logicalPostStateProcessor1.setPartnerPostStateProcessor(logicalPostStateProcessor2);
        logicalPostStateProcessor2.setPartnerPostStateProcessor(logicalPostStateProcessor1);
        logicalPreStateProcessor1.setPartnerStatePreProcessor(logicalPreStateProcessor2);
        logicalPreStateProcessor2.setPartnerStatePreProcessor(logicalPreStateProcessor1);
        StateElement stateElement2 = ((LogicalStateElement) stateElement).getStreamStateElement2();
        InnerStateRuntime innerStateRuntime2 = parse(stateElement2, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, variableExpressionExecutors, processStreamReceiverMap, logicalPreStateProcessor2, logicalPostStateProcessor2, stateType, multiValue, preStateProcessors, isStartState, startupPreStateProcessors, siddhiQueryContext);
        StateElement stateElement1 = ((LogicalStateElement) stateElement).getStreamStateElement1();
        InnerStateRuntime innerStateRuntime1 = parse(stateElement1, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, variableExpressionExecutors, processStreamReceiverMap, logicalPreStateProcessor1, logicalPostStateProcessor1, stateType, multiValue, preStateProcessors, isStartState, startupPreStateProcessors, siddhiQueryContext);
        LogicalInnerStateRuntime logicalInnerStateRuntime = new LogicalInnerStateRuntime(innerStateRuntime1, innerStateRuntime2, stateType);
        logicalInnerStateRuntime.setFirstProcessor(innerStateRuntime1.getFirstProcessor());
        logicalInnerStateRuntime.setLastProcessor(innerStateRuntime2.getLastProcessor());
        for (SingleStreamRuntime singleStreamRuntime : innerStateRuntime2.getSingleStreamRuntimeList()) {
            logicalInnerStateRuntime.addStreamRuntime(singleStreamRuntime);
        }
        for (SingleStreamRuntime singleStreamRuntime : innerStateRuntime1.getSingleStreamRuntimeList()) {
            logicalInnerStateRuntime.addStreamRuntime(singleStreamRuntime);
        }
        return logicalInnerStateRuntime;
    } else if (stateElement instanceof CountStateElement) {
        int minCount = ((CountStateElement) stateElement).getMinCount();
        int maxCount = ((CountStateElement) stateElement).getMaxCount();
        if (minCount == SiddhiConstants.ANY) {
            minCount = 0;
        }
        if (maxCount == SiddhiConstants.ANY) {
            maxCount = Integer.MAX_VALUE;
        }
        CountPreStateProcessor countPreStateProcessor = new CountPreStateProcessor(minCount, maxCount, stateType);
        countPreStateProcessor.init(siddhiQueryContext);
        CountPostStateProcessor countPostStateProcessor = new CountPostStateProcessor(minCount, maxCount);
        countPreStateProcessor.setCountPostStateProcessor(countPostStateProcessor);
        StateElement currentElement = ((CountStateElement) stateElement).getStreamStateElement();
        InnerStateRuntime innerStateRuntime = parse(currentElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, variableExpressionExecutors, processStreamReceiverMap, countPreStateProcessor, countPostStateProcessor, stateType, true, preStateProcessors, isStartState, startupPreStateProcessors, siddhiQueryContext);
        return new CountInnerStateRuntime((StreamInnerStateRuntime) innerStateRuntime);
    } else {
        throw new OperationNotSupportedException();
    }
}
Also used : CountPreStateProcessor(io.siddhi.core.query.input.stream.state.CountPreStateProcessor) NextStateElement(io.siddhi.query.api.execution.query.input.state.NextStateElement) Scheduler(io.siddhi.core.util.Scheduler) 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) LogicalPostStateProcessor(io.siddhi.core.query.input.stream.state.LogicalPostStateProcessor) AbsentLogicalPostStateProcessor(io.siddhi.core.query.input.stream.state.AbsentLogicalPostStateProcessor) EveryInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime) EveryStateElement(io.siddhi.query.api.execution.query.input.state.EveryStateElement) AbsentLogicalPostStateProcessor(io.siddhi.core.query.input.stream.state.AbsentLogicalPostStateProcessor) 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) StreamPostStateProcessor(io.siddhi.core.query.input.stream.state.StreamPostStateProcessor) AbsentStreamPostStateProcessor(io.siddhi.core.query.input.stream.state.AbsentStreamPostStateProcessor) CountStateElement(io.siddhi.query.api.execution.query.input.state.CountStateElement) NextInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime) LogicalInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime) 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) LogicalStateElement(io.siddhi.query.api.execution.query.input.state.LogicalStateElement) StreamInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime) OperationNotSupportedException(io.siddhi.core.exception.OperationNotSupportedException) CountPostStateProcessor(io.siddhi.core.query.input.stream.state.CountPostStateProcessor) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) CountInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime) AbsentStreamStateElement(io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) LogicalPreStateProcessor(io.siddhi.core.query.input.stream.state.LogicalPreStateProcessor) AbsentLogicalPreStateProcessor(io.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor) AbsentLogicalPreStateProcessor(io.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor) AbsentStreamPreStateProcessor(io.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor) AbsentStreamStateElement(io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StreamStateElement(io.siddhi.query.api.execution.query.input.state.StreamStateElement) BasicSingleInputStream(io.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) EntryValveProcessor(io.siddhi.core.query.input.stream.single.EntryValveProcessor) AbsentStreamPostStateProcessor(io.siddhi.core.query.input.stream.state.AbsentStreamPostStateProcessor)

Example 2 with StreamPreStateProcessor

use of io.siddhi.core.query.input.stream.state.StreamPreStateProcessor 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)

Example 3 with StreamPreStateProcessor

use of io.siddhi.core.query.input.stream.state.StreamPreStateProcessor in project siddhi by wso2.

the class SingleProcessStreamReceiver method processAndClear.

protected void processAndClear(ComplexEventChunk<StreamEvent> streamEventChunk) {
    ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<>();
    ComplexEventChunk<StreamEvent> currentStreamEventChunk = new ComplexEventChunk<>();
    synchronized (patternSyncObject) {
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            streamEventChunk.remove();
            stabilizeStates(streamEvent.getTimestamp());
            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));
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor)

Example 4 with StreamPreStateProcessor

use of io.siddhi.core.query.input.stream.state.StreamPreStateProcessor in project siddhi by wso2.

the class QueryParserHelper method initSingleStreamRuntime.

private static void initSingleStreamRuntime(SingleStreamRuntime singleStreamRuntime, int streamEventChainIndex, MetaComplexEvent metaComplexEvent, StateEventFactory stateEventFactory, LockWrapper lockWrapper, String queryName) {
    MetaStreamEvent metaStreamEvent;
    if (metaComplexEvent instanceof MetaStateEvent) {
        metaStreamEvent = ((MetaStateEvent) metaComplexEvent).getMetaStreamEvent(streamEventChainIndex);
    } else {
        metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
    }
    StreamEventFactory streamEventFactory = new StreamEventFactory(metaStreamEvent);
    ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
    processStreamReceiver.setMetaStreamEvent(metaStreamEvent);
    processStreamReceiver.setStreamEventFactory(streamEventFactory);
    processStreamReceiver.setLockWrapper(lockWrapper);
    processStreamReceiver.init();
    Processor processor = singleStreamRuntime.getProcessorChain();
    while (processor != null) {
        if (processor instanceof SchedulingProcessor) {
            ((SchedulingProcessor) processor).getScheduler().setStreamEventFactory(streamEventFactory);
            ((SchedulingProcessor) processor).getScheduler().init(lockWrapper, queryName);
        }
        if (processor instanceof AbstractStreamProcessor) {
            ((AbstractStreamProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventFactory));
            ((AbstractStreamProcessor) processor).constructStreamEventPopulater(metaStreamEvent, streamEventChainIndex);
        }
        if (stateEventFactory != null && processor instanceof JoinProcessor) {
            if (((JoinProcessor) processor).getCompiledCondition() instanceof IncrementalAggregateCompileCondition) {
                IncrementalAggregateCompileCondition compiledCondition = (IncrementalAggregateCompileCondition) ((JoinProcessor) processor).getCompiledCondition();
                compiledCondition.init();
                ComplexEventPopulater complexEventPopulater = StreamEventPopulaterFactory.constructEventPopulator(metaStreamEvent, 0, compiledCondition.getAdditionalAttributes());
                compiledCondition.setComplexEventPopulater(complexEventPopulater);
            }
            ((JoinProcessor) processor).setStateEventFactory(stateEventFactory);
        }
        if (stateEventFactory != null && processor instanceof StreamPreStateProcessor) {
            ((StreamPreStateProcessor) processor).setStateEventFactory(stateEventFactory);
            ((StreamPreStateProcessor) processor).setStreamEventFactory(streamEventFactory);
            ((StreamPreStateProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventFactory));
            if (metaComplexEvent instanceof MetaStateEvent) {
                ((StreamPreStateProcessor) processor).setStateEventCloner(new StateEventCloner(((MetaStateEvent) metaComplexEvent), stateEventFactory));
            }
        }
        processor = processor.getNextProcessor();
    }
}
Also used : ProcessStreamReceiver(io.siddhi.core.query.input.ProcessStreamReceiver) AbstractStreamProcessor(io.siddhi.core.query.processor.stream.AbstractStreamProcessor) Processor(io.siddhi.core.query.processor.Processor) SchedulingProcessor(io.siddhi.core.query.processor.SchedulingProcessor) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor) JoinProcessor(io.siddhi.core.query.input.stream.join.JoinProcessor) AbstractStreamProcessor(io.siddhi.core.query.processor.stream.AbstractStreamProcessor) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) IncrementalAggregateCompileCondition(io.siddhi.core.util.collection.operator.IncrementalAggregateCompileCondition) ComplexEventPopulater(io.siddhi.core.event.stream.populater.ComplexEventPopulater) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) SchedulingProcessor(io.siddhi.core.query.processor.SchedulingProcessor) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) JoinProcessor(io.siddhi.core.query.input.stream.join.JoinProcessor) StateEventCloner(io.siddhi.core.event.state.StateEventCloner) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 5 with StreamPreStateProcessor

use of io.siddhi.core.query.input.stream.state.StreamPreStateProcessor in project siddhi by wso2.

the class StateMultiProcessStreamReceiver method processAndClear.

protected void processAndClear(int processIndex, StreamEvent streamEvent) {
    ComplexEventChunk<StateEvent> retEventChunk = new ComplexEventChunk<StateEvent>();
    ComplexEventChunk<StreamEvent> currentStreamEventChunk = new ComplexEventChunk<StreamEvent>(streamEvent, streamEvent);
    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));
        }
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor)

Aggregations

StreamPreStateProcessor (io.siddhi.core.query.input.stream.state.StreamPreStateProcessor)5 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)2 StateEvent (io.siddhi.core.event.state.StateEvent)2 StreamEvent (io.siddhi.core.event.stream.StreamEvent)2 ProcessStreamReceiver (io.siddhi.core.query.input.ProcessStreamReceiver)2 AbsentLogicalPreStateProcessor (io.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor)2 AbsentStreamPreStateProcessor (io.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor)2 CountPreStateProcessor (io.siddhi.core.query.input.stream.state.CountPreStateProcessor)2 LogicalPreStateProcessor (io.siddhi.core.query.input.stream.state.LogicalPreStateProcessor)2 PreStateProcessor (io.siddhi.core.query.input.stream.state.PreStateProcessor)2 CountInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime)2 EveryInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime)2 InnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime)2 LogicalInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime)2 NextInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime)2 StreamInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime)2 AbsentStreamStateElement (io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)2 CountStateElement (io.siddhi.query.api.execution.query.input.state.CountStateElement)2 EveryStateElement (io.siddhi.query.api.execution.query.input.state.EveryStateElement)2 LogicalStateElement (io.siddhi.query.api.execution.query.input.state.LogicalStateElement)2