private static void initSingleStreamRuntime(SingleStreamRuntime singleStreamRuntime, int streamEventChainIndex,
                                                MetaComplexEvent metaComplexEvent, StateEventFactory stateEventFactory,
                                                LockWrapper lockWrapper, String queryName) {
        MetaStreamEvent metaStreamEvent;

        if (metaComplexEvent instanceof MetaStateEvent) {
            metaStreamEvent = ((MetaStateEvent) metaComplexEvent).getMetaStreamEvent(streamEventChainIndex);
        } else {
            metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
        }
        StreamEventFactory streamEventFactory = new StreamEventFactory(metaStreamEvent);
        ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
        processStreamReceiver.setMetaStreamEvent(metaStreamEvent);
        processStreamReceiver.setStreamEventFactory(streamEventFactory);
        processStreamReceiver.setLockWrapper(lockWrapper);
        processStreamReceiver.init();
        Processor processor = singleStreamRuntime.getProcessorChain();
        while (processor != null) {
            if (processor instanceof SchedulingProcessor) {
                ((SchedulingProcessor) processor).getScheduler().setStreamEventFactory(streamEventFactory);
                ((SchedulingProcessor) processor).getScheduler().init(lockWrapper, queryName);
            }
            if (processor instanceof AbstractStreamProcessor) {
                ((AbstractStreamProcessor) processor)
                        .setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventFactory));
                ((AbstractStreamProcessor) processor).constructStreamEventPopulater(metaStreamEvent,
                        streamEventChainIndex);
            }
            if (stateEventFactory != null && processor instanceof JoinProcessor) {
                if (((JoinProcessor) processor)
                        .getCompiledCondition() instanceof IncrementalAggregateCompileCondition) {
                    IncrementalAggregateCompileCondition compiledCondition = (IncrementalAggregateCompileCondition) (
                            (JoinProcessor) processor).getCompiledCondition();
                    compiledCondition.init();
                    ComplexEventPopulater complexEventPopulater = StreamEventPopulaterFactory
                            .constructEventPopulator(metaStreamEvent, 0, compiledCondition.getAdditionalAttributes());
                    compiledCondition.setComplexEventPopulater(complexEventPopulater);

                }
                ((JoinProcessor) processor).setStateEventFactory(stateEventFactory);
            }
            if (stateEventFactory != null && processor instanceof StreamPreStateProcessor) {
                ((StreamPreStateProcessor) processor).setStateEventFactory(stateEventFactory);
                ((StreamPreStateProcessor) processor).setStreamEventFactory(streamEventFactory);
                ((StreamPreStateProcessor) processor)
                        .setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventFactory));
                if (metaComplexEvent instanceof MetaStateEvent) {
                    ((StreamPreStateProcessor) processor).setStateEventCloner(
                            new StateEventCloner(((MetaStateEvent) metaComplexEvent), stateEventFactory));
                }
            }

            processor = processor.getNextProcessor();
        }
    }
Helper method to clean/refactor MetaStreamEvent.

@param metaStreamEvent MetaStreamEvent
modules/siddhi-core/src/main/java/io/siddhi/core/util/parser/helper/QueryParserHelper.java