Search in sources :

Example 1 with InnerStateRuntime

use of org.wso2.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime in project siddhi by wso2.

the class LogicalInnerStateRuntime method clone.

@Override
public InnerStateRuntime clone(String key) {
    InnerStateRuntime clonedInnerStateRuntime1 = innerStateRuntime1.clone(key);
    InnerStateRuntime clonedInnerStateRuntime2 = innerStateRuntime2.clone(key);
    LogicalPreStateProcessor logicalPreStateProcessor1 = (LogicalPreStateProcessor) clonedInnerStateRuntime1.getFirstProcessor();
    LogicalPostStateProcessor logicalPostStateProcessor1 = (LogicalPostStateProcessor) clonedInnerStateRuntime1.getLastProcessor();
    LogicalPreStateProcessor logicalPreStateProcessor2 = (LogicalPreStateProcessor) clonedInnerStateRuntime2.getFirstProcessor();
    LogicalPostStateProcessor logicalPostStateProcessor2 = (LogicalPostStateProcessor) clonedInnerStateRuntime2.getLastProcessor();
    logicalPostStateProcessor1.setPartnerPreStateProcessor(logicalPreStateProcessor2);
    logicalPostStateProcessor2.setPartnerPreStateProcessor(logicalPreStateProcessor1);
    logicalPostStateProcessor1.setPartnerPostStateProcessor(logicalPostStateProcessor2);
    logicalPostStateProcessor2.setPartnerPostStateProcessor(logicalPostStateProcessor1);
    logicalPreStateProcessor1.setPartnerStatePreProcessor(logicalPreStateProcessor2);
    logicalPreStateProcessor2.setPartnerStatePreProcessor(logicalPreStateProcessor1);
    LogicalInnerStateRuntime logicalInnerStateRuntime = new LogicalInnerStateRuntime(clonedInnerStateRuntime1, clonedInnerStateRuntime2, stateType);
    logicalInnerStateRuntime.firstProcessor = clonedInnerStateRuntime1.getFirstProcessor();
    logicalInnerStateRuntime.lastProcessor = clonedInnerStateRuntime2.getLastProcessor();
    logicalInnerStateRuntime.getSingleStreamRuntimeList().addAll(clonedInnerStateRuntime2.getSingleStreamRuntimeList());
    logicalInnerStateRuntime.getSingleStreamRuntimeList().addAll(clonedInnerStateRuntime1.getSingleStreamRuntimeList());
    List<SingleStreamRuntime> runtimeList = logicalInnerStateRuntime.getSingleStreamRuntimeList();
    for (int i = 0; i < runtimeList.size(); i++) {
        String streamId = runtimeList.get(i).getProcessStreamReceiver().getStreamId();
        for (int j = i; j < runtimeList.size(); j++) {
            if (streamId.equals(runtimeList.get(j).getProcessStreamReceiver().getStreamId())) {
                runtimeList.get(j).setProcessStreamReceiver(runtimeList.get(i).getProcessStreamReceiver());
            }
        }
    }
    return logicalInnerStateRuntime;
}
Also used : SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) LogicalPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.LogicalPreStateProcessor) LogicalPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.LogicalPostStateProcessor)

Example 2 with InnerStateRuntime

use of org.wso2.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime in project siddhi by wso2.

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;
}
Also used : StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor) StreamPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPostStateProcessor) PreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.PreStateProcessor) Processor(org.wso2.siddhi.core.query.processor.Processor) PostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.PostStateProcessor) StreamPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPostStateProcessor) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)

Example 3 with InnerStateRuntime

use of org.wso2.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime 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, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, ProcessStreamReceiver> processStreamReceiverMap, StreamPreStateProcessor streamPreStateProcessor, StreamPostStateProcessor streamPostStateProcessor, StateInputStream.Type stateType, ArrayList<Map.Entry<Long, Set<Integer>>> withinStates, LatencyTracker latencyTracker, String queryName) {
    if (stateElement instanceof StreamStateElement) {
        BasicSingleInputStream basicSingleInputStream = ((StreamStateElement) stateElement).getBasicSingleInputStream();
        SingleStreamRuntime singleStreamRuntime = SingleInputStreamParser.parseInputStream(basicSingleInputStream, siddhiAppContext, variableExpressionExecutors, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, processStreamReceiverMap.get(basicSingleInputStream.getUniqueStreamIds().get(0)), false, false, queryName);
        int stateIndex = metaStateEvent.getStreamEventCount() - 1;
        if (streamPreStateProcessor == null) {
            if (stateElement.getWithin() != null) {
                Set<Integer> withinStateset = new HashSet<Integer>();
                withinStateset.add(SiddhiConstants.ANY);
                withinStates.add(0, new AbstractMap.SimpleEntry<Long, Set<Integer>>(stateElement.getWithin().getValue(), withinStateset));
            }
            if (stateElement instanceof AbsentStreamStateElement) {
                AbsentStreamPreStateProcessor absentProcessor = new AbsentStreamPreStateProcessor(stateType, clonewithinStates(withinStates), ((AbsentStreamStateElement) stateElement).getWaitingTime());
                // Set the scheduler
                siddhiAppContext.addEternalReferencedHolder(absentProcessor);
                EntryValveProcessor entryValveProcessor = new EntryValveProcessor(siddhiAppContext);
                entryValveProcessor.setToLast(absentProcessor);
                Scheduler scheduler = SchedulerParser.parse(siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, siddhiAppContext);
                absentProcessor.setScheduler(scheduler);
                // Assign the AbsentStreamPreStateProcessor to streamPreStateProcessor
                streamPreStateProcessor = absentProcessor;
            } else {
                streamPreStateProcessor = new StreamPreStateProcessor(stateType, clonewithinStates(withinStates));
            }
            streamPreStateProcessor.init(siddhiAppContext, queryName);
            if (stateElement.getWithin() != null) {
                withinStates.remove(0);
            }
        }
        streamPreStateProcessor.setStateId(stateIndex);
        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);
        return innerStateRuntime;
    } else if (stateElement instanceof NextStateElement) {
        StateElement currentElement = ((NextStateElement) stateElement).getStateElement();
        InnerStateRuntime currentInnerStateRuntime = parse(currentElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, streamPreStateProcessor, streamPostStateProcessor, stateType, withinStates, latencyTracker, queryName);
        if (stateElement.getWithin() != null) {
            Set<Integer> withinStateSet = new HashSet<Integer>();
            withinStateSet.add(currentInnerStateRuntime.getFirstProcessor().getStateId());
            withinStateSet.add(currentInnerStateRuntime.getLastProcessor().getStateId());
            withinStates.add(0, new AbstractMap.SimpleEntry<Long, Set<Integer>>(stateElement.getWithin().getValue(), withinStateSet));
        }
        StateElement nextElement = ((NextStateElement) stateElement).getNextStateElement();
        InnerStateRuntime nextInnerStateRuntime = parse(nextElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, streamPreStateProcessor, streamPostStateProcessor, stateType, withinStates, latencyTracker, queryName);
        if (stateElement.getWithin() != null) {
            withinStates.remove(0);
        }
        // currentInnerStateRuntime.getFirstProcessor().getStateId()
        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();
        InnerStateRuntime innerStateRuntime = parse(currentElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, streamPreStateProcessor, streamPostStateProcessor, stateType, withinStates, latencyTracker, queryName);
        EveryInnerStateRuntime everyInnerStateRuntime = new EveryInnerStateRuntime(innerStateRuntime, stateType);
        everyInnerStateRuntime.setFirstProcessor(innerStateRuntime.getFirstProcessor());
        everyInnerStateRuntime.setLastProcessor(innerStateRuntime.getLastProcessor());
        for (SingleStreamRuntime singleStreamRuntime : innerStateRuntime.getSingleStreamRuntimeList()) {
            everyInnerStateRuntime.addStreamRuntime(singleStreamRuntime);
        }
        everyInnerStateRuntime.getLastProcessor().setNextEveryStatePerProcessor(everyInnerStateRuntime.getFirstProcessor());
        return everyInnerStateRuntime;
    } else if (stateElement instanceof LogicalStateElement) {
        LogicalStateElement.Type type = ((LogicalStateElement) stateElement).getType();
        if (stateElement.getWithin() != null) {
            Set<Integer> withinStateset = new HashSet<Integer>();
            withinStateset.add(SiddhiConstants.ANY);
            withinStates.add(0, new AbstractMap.SimpleEntry<Long, Set<Integer>>(stateElement.getWithin().getValue(), withinStateset));
        }
        LogicalPreStateProcessor logicalPreStateProcessor1;
        if (((LogicalStateElement) stateElement).getStreamStateElement1() instanceof AbsentStreamStateElement) {
            logicalPreStateProcessor1 = new AbsentLogicalPreStateProcessor(type, stateType, clonewithinStates(withinStates), ((AbsentStreamStateElement) ((LogicalStateElement) stateElement).getStreamStateElement1()).getWaitingTime());
            // Set the scheduler
            siddhiAppContext.addEternalReferencedHolder((AbsentLogicalPreStateProcessor) logicalPreStateProcessor1);
            EntryValveProcessor entryValveProcessor = new EntryValveProcessor(siddhiAppContext);
            entryValveProcessor.setToLast(logicalPreStateProcessor1);
            Scheduler scheduler = SchedulerParser.parse(siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, siddhiAppContext);
            ((SchedulingProcessor) logicalPreStateProcessor1).setScheduler(scheduler);
        } else {
            logicalPreStateProcessor1 = new LogicalPreStateProcessor(type, stateType, clonewithinStates(withinStates));
        }
        logicalPreStateProcessor1.init(siddhiAppContext, queryName);
        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, clonewithinStates(withinStates), ((AbsentStreamStateElement) ((LogicalStateElement) stateElement).getStreamStateElement2()).getWaitingTime());
            siddhiAppContext.addEternalReferencedHolder((AbsentLogicalPreStateProcessor) logicalPreStateProcessor2);
            EntryValveProcessor entryValveProcessor = new EntryValveProcessor(siddhiAppContext);
            entryValveProcessor.setToLast(logicalPreStateProcessor2);
            Scheduler scheduler = SchedulerParser.parse(siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, siddhiAppContext);
            ((SchedulingProcessor) logicalPreStateProcessor2).setScheduler(scheduler);
        } else {
            logicalPreStateProcessor2 = new LogicalPreStateProcessor(type, stateType, clonewithinStates(withinStates));
        }
        logicalPreStateProcessor2.init(siddhiAppContext, queryName);
        LogicalPostStateProcessor logicalPostStateProcessor2;
        if (((LogicalStateElement) stateElement).getStreamStateElement2() instanceof AbsentStreamStateElement) {
            logicalPostStateProcessor2 = new AbsentLogicalPostStateProcessor(type);
        } else {
            logicalPostStateProcessor2 = new LogicalPostStateProcessor(type);
        }
        if (stateElement.getWithin() != null) {
            withinStates.remove(0);
        }
        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, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, logicalPreStateProcessor2, logicalPostStateProcessor2, stateType, withinStates, latencyTracker, queryName);
        StateElement stateElement1 = ((LogicalStateElement) stateElement).getStreamStateElement1();
        InnerStateRuntime innerStateRuntime1 = parse(stateElement1, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, logicalPreStateProcessor1, logicalPostStateProcessor1, stateType, withinStates, latencyTracker, queryName);
        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;
        }
        if (stateElement.getWithin() != null) {
            Set<Integer> withinStateset = new HashSet<Integer>();
            withinStateset.add(SiddhiConstants.ANY);
            withinStates.add(0, new AbstractMap.SimpleEntry<Long, Set<Integer>>(stateElement.getWithin().getValue(), withinStateset));
        }
        CountPreStateProcessor countPreStateProcessor = new CountPreStateProcessor(minCount, maxCount, stateType, withinStates);
        countPreStateProcessor.init(siddhiAppContext, queryName);
        CountPostStateProcessor countPostStateProcessor = new CountPostStateProcessor(minCount, maxCount);
        if (stateElement.getWithin() != null) {
            withinStates.remove(0);
        }
        countPreStateProcessor.setCountPostStateProcessor(countPostStateProcessor);
        StateElement currentElement = ((CountStateElement) stateElement).getStreamStateElement();
        InnerStateRuntime innerStateRuntime = parse(currentElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, countPreStateProcessor, countPostStateProcessor, stateType, withinStates, latencyTracker, queryName);
        return new CountInnerStateRuntime((StreamInnerStateRuntime) innerStateRuntime);
    } else {
        throw new OperationNotSupportedException();
    }
}
Also used : CountPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.CountPreStateProcessor) Set(java.util.Set) HashSet(java.util.HashSet) NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) Scheduler(org.wso2.siddhi.core.util.Scheduler) LogicalStateElement(org.wso2.siddhi.query.api.execution.query.input.state.LogicalStateElement) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) StateElement(org.wso2.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement) AbsentStreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor) AbsentStreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor) LogicalPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.LogicalPostStateProcessor) AbsentLogicalPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.AbsentLogicalPostStateProcessor) EveryInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement) AbsentLogicalPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.AbsentLogicalPostStateProcessor) AbstractMap(java.util.AbstractMap) StreamInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime) NextInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime) LogicalInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime) InnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime) EveryInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime) CountInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime) StreamPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPostStateProcessor) AbsentStreamPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.AbsentStreamPostStateProcessor) CountStateElement(org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement) NextInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime) LogicalInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime) LogicalStateElement(org.wso2.siddhi.query.api.execution.query.input.state.LogicalStateElement) StreamInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime) HashSet(java.util.HashSet) OperationNotSupportedException(org.wso2.siddhi.core.exception.OperationNotSupportedException) CountPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.CountPostStateProcessor) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) CountInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime) AbsentStreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) LogicalPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.LogicalPreStateProcessor) AbsentLogicalPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor) AbsentLogicalPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor) AbsentStreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor) StreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement) AbsentStreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) EntryValveProcessor(org.wso2.siddhi.core.query.input.stream.single.EntryValveProcessor) AbsentStreamPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.AbsentStreamPostStateProcessor)

Example 4 with InnerStateRuntime

use of org.wso2.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime in project siddhi by wso2.

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

Example 5 with InnerStateRuntime

use of org.wso2.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime in project siddhi by wso2.

the class CountInnerStateRuntime method clone.

@Override
public InnerStateRuntime clone(String key) {
    StreamInnerStateRuntime clonedStreamInnerStateRuntime = (StreamInnerStateRuntime) streamInnerStateRuntime.clone(key);
    CountPreStateProcessor countPreStateProcessor = (CountPreStateProcessor) clonedStreamInnerStateRuntime.getFirstProcessor();
    CountPostStateProcessor countPostStateProcessor = (CountPostStateProcessor) clonedStreamInnerStateRuntime.getLastProcessor();
    countPreStateProcessor.setCountPostStateProcessor(countPostStateProcessor);
    return new CountInnerStateRuntime(clonedStreamInnerStateRuntime);
}
Also used : CountPostStateProcessor(org.wso2.siddhi.core.query.input.stream.state.CountPostStateProcessor) CountPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.CountPreStateProcessor)

Aggregations

SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 StreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)3 AbsentStreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor)2 CountPostStateProcessor (org.wso2.siddhi.core.query.input.stream.state.CountPostStateProcessor)2 CountPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.CountPreStateProcessor)2 LogicalPostStateProcessor (org.wso2.siddhi.core.query.input.stream.state.LogicalPostStateProcessor)2 LogicalPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.LogicalPreStateProcessor)2 StreamPostStateProcessor (org.wso2.siddhi.core.query.input.stream.state.StreamPostStateProcessor)2 CountInnerStateRuntime (org.wso2.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime)2 EveryInnerStateRuntime (org.wso2.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime)2 InnerStateRuntime (org.wso2.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime)2 LogicalInnerStateRuntime (org.wso2.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime)2 NextInnerStateRuntime (org.wso2.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime)2 StreamInnerStateRuntime (org.wso2.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime)2 AbsentStreamStateElement (org.wso2.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)2 CountStateElement (org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement)2 EveryStateElement (org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement)2 LogicalStateElement (org.wso2.siddhi.query.api.execution.query.input.state.LogicalStateElement)2 NextStateElement (org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement)2 StateElement (org.wso2.siddhi.query.api.execution.query.input.state.StateElement)2