Search in sources :

Example 1 with StateStreamRuntime

use of org.ballerinalang.siddhi.core.query.input.stream.state.StateStreamRuntime in project ballerina by ballerina-lang.

the class PartitionRuntime method addPartitionReceiver.

public void addPartitionReceiver(QueryRuntime queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) {
    Query query = queryRuntime.getQuery();
    List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, siddhiAppContext, null).getPartitionExecutorLists();
    if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) {
        SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream();
        addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
    } else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) {
        SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream();
        addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
        SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getRightInputStream();
        addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1));
    } else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) {
        StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement();
        addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0);
    }
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) SingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.join.JoinStreamRuntime) JoinInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.JoinInputStream) 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) 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) ArrayList(java.util.ArrayList) List(java.util.List) StateInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.StateInputStream) StateStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.state.StateStreamRuntime)

Example 2 with StateStreamRuntime

use of org.ballerinalang.siddhi.core.query.input.stream.state.StateStreamRuntime 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)

Aggregations

StateStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.state.StateStreamRuntime)2 CountStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.CountStateElement)2 EveryStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.EveryStateElement)2 LogicalStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.LogicalStateElement)2 NextStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.NextStateElement)2 StateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.StateElement)2 StreamStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver)1 JoinStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.join.JoinStreamRuntime)1 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)1 AbsentStreamPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor)1 StreamPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor)1 PatternMultiProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.stream.state.receiver.PatternMultiProcessStreamReceiver)1 PatternSingleProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.stream.state.receiver.PatternSingleProcessStreamReceiver)1 SequenceMultiProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver)1 SequenceSingleProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver)1 CountInnerStateRuntime (org.ballerinalang.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime)1