Search in sources :

Example 6 with ProcessStreamReceiver

use of org.wso2.siddhi.core.query.input.ProcessStreamReceiver 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 7 with ProcessStreamReceiver

use of org.wso2.siddhi.core.query.input.ProcessStreamReceiver in project siddhi by wso2.

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();
    }
}
Also used : ProcessStreamReceiver(org.wso2.siddhi.core.query.input.ProcessStreamReceiver) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor) Processor(org.wso2.siddhi.core.query.processor.Processor) JoinProcessor(org.wso2.siddhi.core.query.input.stream.join.JoinProcessor) AbstractStreamProcessor(org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor) SchedulingProcessor(org.wso2.siddhi.core.query.processor.SchedulingProcessor) AbstractStreamProcessor(org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor) IncrementalAggregateCompileCondition(org.wso2.siddhi.core.util.collection.operator.IncrementalAggregateCompileCondition) ComplexEventPopulater(org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) SchedulingProcessor(org.wso2.siddhi.core.query.processor.SchedulingProcessor) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.wso2.siddhi.core.event.stream.StreamEventCloner) JoinProcessor(org.wso2.siddhi.core.query.input.stream.join.JoinProcessor) StateEventCloner(org.wso2.siddhi.core.event.state.StateEventCloner) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Example 8 with ProcessStreamReceiver

use of org.wso2.siddhi.core.query.input.ProcessStreamReceiver in project siddhi by wso2.

the class StateStreamRuntime method clone.

@Override
public StreamRuntime clone(String key) {
    StateStreamRuntime stateStreamRuntime = new StateStreamRuntime(siddhiAppContext, metaStateEvent);
    stateStreamRuntime.innerStateRuntime = this.innerStateRuntime.clone(key);
    for (SingleStreamRuntime singleStreamRuntime : stateStreamRuntime.getSingleStreamRuntimes()) {
        ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
        if (processStreamReceiver instanceof SequenceMultiProcessStreamReceiver) {
            ((SequenceMultiProcessStreamReceiver) processStreamReceiver).setStateStreamRuntime(stateStreamRuntime);
        } else if (processStreamReceiver instanceof SequenceSingleProcessStreamReceiver) {
            ((SequenceSingleProcessStreamReceiver) processStreamReceiver).setStateStreamRuntime(stateStreamRuntime);
        }
    }
    ((StreamPreStateProcessor) stateStreamRuntime.innerStateRuntime.getFirstProcessor()).setThisLastProcessor((StreamPostStateProcessor) stateStreamRuntime.innerStateRuntime.getLastProcessor());
    return stateStreamRuntime;
}
Also used : ProcessStreamReceiver(org.wso2.siddhi.core.query.input.ProcessStreamReceiver) SequenceSingleProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver) SequenceMultiProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) SequenceMultiProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) SequenceSingleProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver)

Example 9 with ProcessStreamReceiver

use of org.wso2.siddhi.core.query.input.ProcessStreamReceiver in project siddhi by wso2.

the class SiddhiAppRuntimeBuilder method addQuery.

public String addQuery(QueryRuntime queryRuntime) {
    QueryRuntime oldQueryRuntime = queryProcessorMap.put(queryRuntime.getQueryId(), queryRuntime);
    if (oldQueryRuntime != null) {
        throw new SiddhiAppCreationException("Multiple queries with name '" + queryRuntime.getQueryId() + "' defined in Siddhi App '" + siddhiAppContext.getName() + "'", queryRuntime.getQuery().getQueryContextStartIndex(), queryRuntime.getQuery().getQueryContextEndIndex());
    }
    StreamRuntime streamRuntime = queryRuntime.getStreamRuntime();
    for (SingleStreamRuntime singleStreamRuntime : streamRuntime.getSingleStreamRuntimes()) {
        ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
        if (processStreamReceiver.toStream()) {
            StreamJunction streamJuction = streamJunctionMap.get(processStreamReceiver.getStreamId());
            if (streamJuction != null) {
                streamJuction.subscribe(processStreamReceiver);
            } else {
                throw new SiddhiAppCreationException("Expecting a stream, but provided '" + processStreamReceiver.getStreamId() + "' is not a stream");
            }
        }
    }
    OutputCallback outputCallback = queryRuntime.getOutputCallback();
    if (outputCallback != null && outputCallback instanceof InsertIntoStreamCallback) {
        InsertIntoStreamCallback insertIntoStreamCallback = (InsertIntoStreamCallback) outputCallback;
        StreamDefinition streamDefinition = insertIntoStreamCallback.getOutputStreamDefinition();
        streamDefinitionMap.putIfAbsent(streamDefinition.getId(), streamDefinition);
        DefinitionParserHelper.validateOutputStream(streamDefinition, streamDefinitionMap.get(streamDefinition.getId()));
        StreamJunction outputStreamJunction = streamJunctionMap.get(streamDefinition.getId());
        if (outputStreamJunction == null) {
            outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
            streamJunctionMap.putIfAbsent(streamDefinition.getId(), outputStreamJunction);
        }
        insertIntoStreamCallback.init(streamJunctionMap.get(insertIntoStreamCallback.getOutputStreamDefinition().getId()));
    } else if (outputCallback != null && outputCallback instanceof InsertIntoWindowCallback) {
        InsertIntoWindowCallback insertIntoWindowCallback = (InsertIntoWindowCallback) outputCallback;
        StreamDefinition streamDefinition = insertIntoWindowCallback.getOutputStreamDefinition();
        windowDefinitionMap.putIfAbsent(streamDefinition.getId(), streamDefinition);
        DefinitionParserHelper.validateOutputStream(streamDefinition, windowDefinitionMap.get(streamDefinition.getId()));
        StreamJunction outputStreamJunction = streamJunctionMap.get(streamDefinition.getId());
        if (outputStreamJunction == null) {
            outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
            streamJunctionMap.putIfAbsent(streamDefinition.getId(), outputStreamJunction);
        }
        insertIntoWindowCallback.getWindow().setPublisher(streamJunctionMap.get(insertIntoWindowCallback.getOutputStreamDefinition().getId()).constructPublisher());
    }
    return queryRuntime.getQueryId();
}
Also used : ProcessStreamReceiver(org.wso2.siddhi.core.query.input.ProcessStreamReceiver) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) InsertIntoWindowCallback(org.wso2.siddhi.core.query.output.callback.InsertIntoWindowCallback) QueryRuntime(org.wso2.siddhi.core.query.QueryRuntime) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) StreamJunction(org.wso2.siddhi.core.stream.StreamJunction) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) StreamRuntime(org.wso2.siddhi.core.query.input.stream.StreamRuntime) InsertIntoStreamCallback(org.wso2.siddhi.core.query.output.callback.InsertIntoStreamCallback) OutputCallback(org.wso2.siddhi.core.query.output.callback.OutputCallback)

Example 10 with ProcessStreamReceiver

use of org.wso2.siddhi.core.query.input.ProcessStreamReceiver in project siddhi by wso2.

the class SiddhiAppRuntimeBuilder method defineAggregation.

public void defineAggregation(AggregationDefinition aggregationDefinition) {
    AggregationRuntime aggregationRuntime = AggregationParser.parse(aggregationDefinition, siddhiAppContext, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, windowMap, aggregationMap, this);
    DefinitionParserHelper.validateDefinition(aggregationDefinition, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap);
    aggregationDefinitionMap.putIfAbsent(aggregationDefinition.getId(), aggregationDefinition);
    ProcessStreamReceiver processStreamReceiver = aggregationRuntime.getSingleStreamRuntime().getProcessStreamReceiver();
    streamJunctionMap.get(processStreamReceiver.getStreamId()).subscribe(processStreamReceiver);
    aggregationMap.putIfAbsent(aggregationDefinition.getId(), aggregationRuntime);
}
Also used : ProcessStreamReceiver(org.wso2.siddhi.core.query.input.ProcessStreamReceiver) AggregationRuntime(org.wso2.siddhi.core.aggregation.AggregationRuntime)

Aggregations

ProcessStreamReceiver (org.wso2.siddhi.core.query.input.ProcessStreamReceiver)8 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)5 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)4 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4 OperationNotSupportedException (org.wso2.siddhi.core.exception.OperationNotSupportedException)3 StreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor)3 Processor (org.wso2.siddhi.core.query.processor.Processor)3 SchedulingProcessor (org.wso2.siddhi.core.query.processor.SchedulingProcessor)3 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)2 JoinProcessor (org.wso2.siddhi.core.query.input.stream.join.JoinProcessor)2 EntryValveProcessor (org.wso2.siddhi.core.query.input.stream.single.EntryValveProcessor)2 AbsentStreamPreStateProcessor (org.wso2.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor)2 SequenceMultiProcessStreamReceiver (org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver)2 SequenceSingleProcessStreamReceiver (org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver)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