Search in sources :

Example 1 with StreamPreStateProcessor

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

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

Example 2 with StreamPreStateProcessor

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

the class StateMultiProcessStreamReceiver method processAndClear.

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

Example 3 with StreamPreStateProcessor

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

the class SingleProcessStreamReceiver method processAndClear.

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

Example 4 with StreamPreStateProcessor

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

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

Example 5 with StreamPreStateProcessor

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

StreamPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor)6 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)2 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)2 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)2 ProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver)2 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)2 AbsentStreamPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor)2 StreamPostStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.StreamPostStateProcessor)2 CountInnerStateRuntime (org.ballerinalang.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime)2 EveryInnerStateRuntime (org.ballerinalang.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime)2 InnerStateRuntime (org.ballerinalang.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime)2 LogicalInnerStateRuntime (org.ballerinalang.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime)2 NextInnerStateRuntime (org.ballerinalang.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime)2 StreamInnerStateRuntime (org.ballerinalang.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime)2 AbsentStreamStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)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