Search in sources :

Example 6 with ProcessStreamReceiver

use of org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver in project ballerina by ballerina-lang.

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

Example 7 with ProcessStreamReceiver

use of org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver) AggregationRuntime(org.ballerinalang.siddhi.core.aggregation.AggregationRuntime)

Example 8 with ProcessStreamReceiver

use of org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) InsertIntoWindowCallback(org.ballerinalang.siddhi.core.query.output.callback.InsertIntoWindowCallback) QueryRuntime(org.ballerinalang.siddhi.core.query.QueryRuntime) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) StreamJunction(org.ballerinalang.siddhi.core.stream.StreamJunction) StreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.StreamRuntime) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) InsertIntoStreamCallback(org.ballerinalang.siddhi.core.query.output.callback.InsertIntoStreamCallback) OutputCallback(org.ballerinalang.siddhi.core.query.output.callback.OutputCallback)

Aggregations

ProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver)8 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)3 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)3 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)2 JoinProcessor (org.ballerinalang.siddhi.core.query.input.stream.join.JoinProcessor)2 StreamPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor)2 SequenceMultiProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver)2 SequenceSingleProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver)2 Processor (org.ballerinalang.siddhi.core.query.processor.Processor)2 SchedulingProcessor (org.ballerinalang.siddhi.core.query.processor.SchedulingProcessor)2 SingleInputStream (org.ballerinalang.siddhi.query.api.execution.query.input.stream.SingleInputStream)2 HashMap (java.util.HashMap)1 AggregationRuntime (org.ballerinalang.siddhi.core.aggregation.AggregationRuntime)1 StateEventCloner (org.ballerinalang.siddhi.core.event.state.StateEventCloner)1 StreamEventCloner (org.ballerinalang.siddhi.core.event.stream.StreamEventCloner)1 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)1 ComplexEventPopulater (org.ballerinalang.siddhi.core.event.stream.populater.ComplexEventPopulater)1 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)1 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)1