Search in sources :

Example 1 with OutputCallback

use of io.siddhi.core.query.output.callback.OutputCallback in project siddhi by wso2.

the class QueryParser method parse.

/**
 * Parse a query and return corresponding QueryRuntime.
 *
 * @param query                    query to be parsed.
 * @param siddhiAppContext         associated Siddhi app context.
 * @param streamDefinitionMap      keyvalue containing user given stream definitions.
 * @param tableDefinitionMap       keyvalue containing table definitions.
 * @param windowDefinitionMap      keyvalue containing window definition map.
 * @param aggregationDefinitionMap keyvalue containing aggregation definition map.
 * @param tableMap                 keyvalue containing event tables.
 * @param aggregationMap           keyvalue containing aggrigation runtimes.
 * @param windowMap                keyvalue containing event window map.
 * @param lockSynchronizer         Lock synchronizer for sync the lock across queries.
 * @param queryIndex               query index to identify unknown query by number
 * @param partitioned              is the query partitioned
 * @param partitionId              The ID of the partition
 * @return queryRuntime
 */
public static QueryRuntimeImpl parse(Query query, SiddhiAppContext siddhiAppContext, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, Map<String, AggregationRuntime> aggregationMap, Map<String, Window> windowMap, LockSynchronizer lockSynchronizer, String queryIndex, boolean partitioned, String partitionId) {
    List<VariableExpressionExecutor> executors = new ArrayList<>();
    QueryRuntimeImpl queryRuntime;
    Element nameElement = null;
    LatencyTracker latencyTracker = null;
    LockWrapper lockWrapper = null;
    try {
        nameElement = AnnotationHelper.getAnnotationElement("info", "name", query.getAnnotations());
        String queryName;
        if (nameElement != null) {
            queryName = nameElement.getValue();
        } else {
            queryName = "query_" + queryIndex;
        }
        SiddhiQueryContext siddhiQueryContext = new SiddhiQueryContext(siddhiAppContext, queryName, partitionId);
        siddhiQueryContext.setPartitioned(partitioned);
        latencyTracker = QueryParserHelper.createLatencyTracker(siddhiAppContext, siddhiQueryContext.getName(), SiddhiConstants.METRIC_INFIX_QUERIES, null);
        siddhiQueryContext.setLatencyTracker(latencyTracker);
        OutputStream.OutputEventType outputEventType = query.getOutputStream().getOutputEventType();
        if (query.getOutputRate() != null && query.getOutputRate() instanceof SnapshotOutputRate) {
            if (outputEventType != OutputStream.OutputEventType.ALL_EVENTS) {
                throw new SiddhiAppCreationException("As query '" + siddhiQueryContext.getName() + "' is performing snapshot rate limiting, it can only insert '" + OutputStream.OutputEventType.ALL_EVENTS + "' but it is inserting '" + outputEventType + "'!", query.getOutputStream().getQueryContextStartIndex(), query.getOutputStream().getQueryContextEndIndex());
            }
        }
        siddhiQueryContext.setOutputEventType(outputEventType);
        boolean outputExpectsExpiredEvents = false;
        if (outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS) {
            outputExpectsExpiredEvents = true;
        }
        StreamRuntime streamRuntime = InputStreamParser.parse(query.getInputStream(), query, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, windowMap, aggregationMap, executors, outputExpectsExpiredEvents, siddhiQueryContext);
        QuerySelector selector;
        if (streamRuntime.getQuerySelector() != null) {
            selector = streamRuntime.getQuerySelector();
        } else {
            selector = SelectorParser.parse(query.getSelector(), query.getOutputStream(), streamRuntime.getMetaComplexEvent(), tableMap, executors, SiddhiConstants.UNKNOWN_STATE, streamRuntime.getProcessingMode(), outputExpectsExpiredEvents, siddhiQueryContext);
        }
        boolean isWindow = query.getInputStream() instanceof JoinInputStream;
        if (!isWindow && query.getInputStream() instanceof SingleInputStream) {
            for (StreamHandler streamHandler : ((SingleInputStream) query.getInputStream()).getStreamHandlers()) {
                if (streamHandler instanceof io.siddhi.query.api.execution.query.input.handler.Window) {
                    isWindow = true;
                    break;
                }
            }
        }
        Element synchronizedElement = AnnotationHelper.getAnnotationElement("synchronized", null, query.getAnnotations());
        if (synchronizedElement != null) {
            if (!("false".equalsIgnoreCase(synchronizedElement.getValue()))) {
                // Query LockWrapper does not need a unique
                lockWrapper = new LockWrapper("");
                // id since it will
                // not be passed to the LockSynchronizer.
                // LockWrapper does not have a default lock
                lockWrapper.setLock(new ReentrantLock());
            }
        } else {
            if (isWindow || !(streamRuntime instanceof SingleStreamRuntime)) {
                if (streamRuntime instanceof JoinStreamRuntime) {
                    // If at least one Window is involved in the join, use the LockWrapper of that window
                    // for the query as well.
                    // If join is between two EventWindows, sync the locks of the LockWrapper of those windows
                    // and use either of them for query.
                    MetaStateEvent metaStateEvent = (MetaStateEvent) streamRuntime.getMetaComplexEvent();
                    MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
                    if (metaStreamEvents[0].getEventType() == EventType.WINDOW && metaStreamEvents[1].getEventType() == EventType.WINDOW) {
                        LockWrapper leftLockWrapper = windowMap.get(metaStreamEvents[0].getLastInputDefinition().getId()).getLock();
                        LockWrapper rightLockWrapper = windowMap.get(metaStreamEvents[1].getLastInputDefinition().getId()).getLock();
                        if (!leftLockWrapper.equals(rightLockWrapper)) {
                            // Sync the lock across both wrappers
                            lockSynchronizer.sync(leftLockWrapper, rightLockWrapper);
                        }
                        // Can use either leftLockWrapper or rightLockWrapper since both of them will hold the
                        // same lock internally
                        // If either of their lock is updated later, the other lock also will be update by the
                        // LockSynchronizer.
                        lockWrapper = leftLockWrapper;
                    } else if (metaStreamEvents[0].getEventType() == EventType.WINDOW) {
                        // Share the same wrapper as the query lock wrapper
                        lockWrapper = windowMap.get(metaStreamEvents[0].getLastInputDefinition().getId()).getLock();
                    } else if (metaStreamEvents[1].getEventType() == EventType.WINDOW) {
                        // Share the same wrapper as the query lock wrapper
                        lockWrapper = windowMap.get(metaStreamEvents[1].getLastInputDefinition().getId()).getLock();
                    } else {
                        // Join does not contain any Window
                        // Query LockWrapper does not need a unique
                        lockWrapper = new LockWrapper("");
                        // id since
                        // it will not be passed to the LockSynchronizer.
                        // LockWrapper does not have a default lock
                        lockWrapper.setLock(new ReentrantLock());
                    }
                } else {
                    lockWrapper = new LockWrapper("");
                    lockWrapper.setLock(new ReentrantLock());
                }
            }
        }
        OutputRateLimiter outputRateLimiter = OutputParser.constructOutputRateLimiter(query.getOutputStream().getId(), query.getOutputRate(), query.getSelector().getGroupByList().size() != 0, isWindow, siddhiQueryContext);
        if (outputRateLimiter instanceof WrappedSnapshotOutputRateLimiter) {
            selector.setBatchingEnabled(false);
        }
        boolean groupBy = !query.getSelector().getGroupByList().isEmpty();
        OutputCallback outputCallback = OutputParser.constructOutputCallback(query.getOutputStream(), streamRuntime.getMetaComplexEvent().getOutputStreamDefinition(), tableMap, windowMap, !(streamRuntime instanceof SingleStreamRuntime) || groupBy, siddhiQueryContext);
        QueryParserHelper.reduceMetaComplexEvent(streamRuntime.getMetaComplexEvent());
        QueryParserHelper.updateVariablePosition(streamRuntime.getMetaComplexEvent(), executors);
        QueryParserHelper.initStreamRuntime(streamRuntime, streamRuntime.getMetaComplexEvent(), lockWrapper, siddhiQueryContext.getName());
        // Update cache compile selection variable expression executors
        if (streamRuntime instanceof JoinStreamRuntime) {
            streamRuntime.getSingleStreamRuntimes().forEach((singleStreamRuntime -> {
                Processor processorChain = singleStreamRuntime.getProcessorChain();
                if (processorChain instanceof JoinProcessor) {
                    CompiledSelection compiledSelection = ((JoinProcessor) processorChain).getCompiledSelection();
                    if (compiledSelection instanceof AbstractQueryableRecordTable.CompiledSelectionWithCache) {
                        List<VariableExpressionExecutor> variableExpressionExecutors = ((AbstractQueryableRecordTable.CompiledSelectionWithCache) compiledSelection).getVariableExpressionExecutorsForQuerySelector();
                        QueryParserHelper.updateVariablePosition(streamRuntime.getMetaComplexEvent(), variableExpressionExecutors);
                    }
                }
            }));
        }
        selector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(streamRuntime.getMetaComplexEvent()));
        queryRuntime = new QueryRuntimeImpl(query, streamRuntime, selector, outputRateLimiter, outputCallback, streamRuntime.getMetaComplexEvent(), siddhiQueryContext);
        if (outputRateLimiter instanceof WrappedSnapshotOutputRateLimiter) {
            selector.setBatchingEnabled(false);
            ((WrappedSnapshotOutputRateLimiter) outputRateLimiter).init(streamRuntime.getMetaComplexEvent().getOutputStreamDefinition().getAttributeList().size(), selector.getAttributeProcessorList(), streamRuntime.getMetaComplexEvent());
        }
        outputRateLimiter.init(lockWrapper, groupBy, siddhiQueryContext);
    } catch (DuplicateDefinitionException e) {
        if (nameElement != null) {
            throw new DuplicateDefinitionException(e.getMessageWithOutContext() + ", when creating query " + nameElement.getValue(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
        } else {
            throw new DuplicateDefinitionException(e.getMessage(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
        }
    } catch (Throwable t) {
        ExceptionUtil.populateQueryContext(t, query, siddhiAppContext);
        throw t;
    }
    return queryRuntime;
}
Also used : DuplicateDefinitionException(io.siddhi.query.api.exception.DuplicateDefinitionException) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) AnnotationHelper(io.siddhi.query.api.util.AnnotationHelper) QueryRuntimeImpl(io.siddhi.core.query.QueryRuntimeImpl) OutputCallback(io.siddhi.core.query.output.callback.OutputCallback) SiddhiAppContext(io.siddhi.core.config.SiddhiAppContext) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SingleInputStream(io.siddhi.query.api.execution.query.input.stream.SingleInputStream) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) SiddhiConstants(io.siddhi.core.util.SiddhiConstants) CompiledSelection(io.siddhi.core.util.collection.operator.CompiledSelection) QuerySelector(io.siddhi.core.query.selector.QuerySelector) ArrayList(java.util.ArrayList) StreamRuntime(io.siddhi.core.query.input.stream.StreamRuntime) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) Query(io.siddhi.query.api.execution.query.Query) Table(io.siddhi.core.table.Table) LockSynchronizer(io.siddhi.core.util.lock.LockSynchronizer) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) AggregationRuntime(io.siddhi.core.aggregation.AggregationRuntime) Map(java.util.Map) SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) WrappedSnapshotOutputRateLimiter(io.siddhi.core.query.output.ratelimit.snapshot.WrappedSnapshotOutputRateLimiter) LockWrapper(io.siddhi.core.util.lock.LockWrapper) ReentrantLock(java.util.concurrent.locks.ReentrantLock) QueryRuntime(io.siddhi.core.query.QueryRuntime) LatencyTracker(io.siddhi.core.util.statistics.LatencyTracker) EventType(io.siddhi.core.event.stream.MetaStreamEvent.EventType) OutputRateLimiter(io.siddhi.core.query.output.ratelimit.OutputRateLimiter) ExceptionUtil(io.siddhi.core.util.ExceptionUtil) StateEventPopulatorFactory(io.siddhi.core.event.state.populater.StateEventPopulatorFactory) Element(io.siddhi.query.api.annotation.Element) AbstractQueryableRecordTable(io.siddhi.core.table.record.AbstractQueryableRecordTable) List(java.util.List) JoinStreamRuntime(io.siddhi.core.query.input.stream.join.JoinStreamRuntime) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) SnapshotOutputRate(io.siddhi.query.api.execution.query.output.ratelimit.SnapshotOutputRate) Processor(io.siddhi.core.query.processor.Processor) Window(io.siddhi.core.window.Window) QueryParserHelper(io.siddhi.core.util.parser.helper.QueryParserHelper) JoinProcessor(io.siddhi.core.query.input.stream.join.JoinProcessor) JoinInputStream(io.siddhi.query.api.execution.query.input.stream.JoinInputStream) StreamHandler(io.siddhi.query.api.execution.query.input.handler.StreamHandler) Processor(io.siddhi.core.query.processor.Processor) JoinProcessor(io.siddhi.core.query.input.stream.join.JoinProcessor) Element(io.siddhi.query.api.annotation.Element) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) ArrayList(java.util.ArrayList) OutputCallback(io.siddhi.core.query.output.callback.OutputCallback) SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) AbstractQueryableRecordTable(io.siddhi.core.table.record.AbstractQueryableRecordTable) JoinInputStream(io.siddhi.query.api.execution.query.input.stream.JoinInputStream) SingleInputStream(io.siddhi.query.api.execution.query.input.stream.SingleInputStream) WrappedSnapshotOutputRateLimiter(io.siddhi.core.query.output.ratelimit.snapshot.WrappedSnapshotOutputRateLimiter) OutputRateLimiter(io.siddhi.core.query.output.ratelimit.OutputRateLimiter) StreamHandler(io.siddhi.query.api.execution.query.input.handler.StreamHandler) ArrayList(java.util.ArrayList) List(java.util.List) StreamRuntime(io.siddhi.core.query.input.stream.StreamRuntime) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) JoinStreamRuntime(io.siddhi.core.query.input.stream.join.JoinStreamRuntime) JoinProcessor(io.siddhi.core.query.input.stream.join.JoinProcessor) Window(io.siddhi.core.window.Window) ReentrantLock(java.util.concurrent.locks.ReentrantLock) DuplicateDefinitionException(io.siddhi.query.api.exception.DuplicateDefinitionException) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) JoinStreamRuntime(io.siddhi.core.query.input.stream.join.JoinStreamRuntime) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) QuerySelector(io.siddhi.core.query.selector.QuerySelector) LockWrapper(io.siddhi.core.util.lock.LockWrapper) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) SnapshotOutputRate(io.siddhi.query.api.execution.query.output.ratelimit.SnapshotOutputRate) QueryRuntimeImpl(io.siddhi.core.query.QueryRuntimeImpl) CompiledSelection(io.siddhi.core.util.collection.operator.CompiledSelection) LatencyTracker(io.siddhi.core.util.statistics.LatencyTracker) WrappedSnapshotOutputRateLimiter(io.siddhi.core.query.output.ratelimit.snapshot.WrappedSnapshotOutputRateLimiter) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 2 with OutputCallback

use of io.siddhi.core.query.output.callback.OutputCallback in project siddhi by wso2.

the class OnDemandQueryParser method populateFindOnDemandQueryRuntime.

private static void populateFindOnDemandQueryRuntime(FindOnDemandQueryRuntime findOnDemandQueryRuntime, MatchingMetaInfoHolder metaStreamInfoHolder, Selector selector, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, Map<String, Window> windowMap, int metaPosition, boolean groupBy, LockWrapper lockWrapper, SiddhiQueryContext siddhiQueryContext) {
    ReturnStream returnStream = new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS);
    QuerySelector querySelector = SelectorParser.parse(selector, returnStream, metaStreamInfoHolder.getMetaStateEvent(), tableMap, variableExpressionExecutors, metaPosition, ProcessingMode.BATCH, false, siddhiQueryContext);
    PassThroughOutputRateLimiter rateLimiter = new PassThroughOutputRateLimiter(siddhiQueryContext.getName());
    rateLimiter.init(lockWrapper, groupBy, siddhiQueryContext);
    OutputCallback outputCallback = OutputParser.constructOutputCallback(returnStream, metaStreamInfoHolder.getMetaStateEvent().getOutputStreamDefinition(), tableMap, windowMap, true, siddhiQueryContext);
    rateLimiter.setOutputCallback(outputCallback);
    querySelector.setNextProcessor(rateLimiter);
    QueryParserHelper.reduceMetaComplexEvent(metaStreamInfoHolder.getMetaStateEvent());
    QueryParserHelper.updateVariablePosition(metaStreamInfoHolder.getMetaStateEvent(), variableExpressionExecutors);
    querySelector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(metaStreamInfoHolder.getMetaStateEvent()));
    findOnDemandQueryRuntime.setStateEventFactory(new StateEventFactory(metaStreamInfoHolder.getMetaStateEvent()));
    findOnDemandQueryRuntime.setSelector(querySelector);
    findOnDemandQueryRuntime.setOutputAttributes(metaStreamInfoHolder.getMetaStateEvent().getOutputStreamDefinition().getAttributeList());
}
Also used : StateEventFactory(io.siddhi.core.event.state.StateEventFactory) QuerySelector(io.siddhi.core.query.selector.QuerySelector) ReturnStream(io.siddhi.query.api.execution.query.output.stream.ReturnStream) PassThroughOutputRateLimiter(io.siddhi.core.query.output.ratelimit.PassThroughOutputRateLimiter) OutputCallback(io.siddhi.core.query.output.callback.OutputCallback)

Example 3 with OutputCallback

use of io.siddhi.core.query.output.callback.OutputCallback in project siddhi by wso2.

the class SiddhiAppRuntimeBuilder method addQuery.

public String addQuery(QueryRuntimeImpl 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 streamJunction = streamJunctionMap.get(processStreamReceiver.getStreamId());
            if (streamJunction != null) {
                streamJunction.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(), null, 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(), null, siddhiAppContext);
            streamJunctionMap.putIfAbsent(streamDefinition.getId(), outputStreamJunction);
        }
        insertIntoWindowCallback.getWindow().setPublisher(streamJunctionMap.get(insertIntoWindowCallback.getOutputStreamDefinition().getId()).constructPublisher());
    }
    return queryRuntime.getQueryId();
}
Also used : ProcessStreamReceiver(io.siddhi.core.query.input.ProcessStreamReceiver) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) InsertIntoWindowCallback(io.siddhi.core.query.output.callback.InsertIntoWindowCallback) QueryRuntime(io.siddhi.core.query.QueryRuntime) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) StreamJunction(io.siddhi.core.stream.StreamJunction) StreamRuntime(io.siddhi.core.query.input.stream.StreamRuntime) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) InsertIntoStreamCallback(io.siddhi.core.query.output.callback.InsertIntoStreamCallback) OutputCallback(io.siddhi.core.query.output.callback.OutputCallback)

Example 4 with OutputCallback

use of io.siddhi.core.query.output.callback.OutputCallback in project siddhi by wso2.

the class SiddhiAppRuntimeImpl method debug.

public synchronized SiddhiDebugger debug() {
    siddhiDebugger = new SiddhiDebugger(siddhiAppContext);
    List<StreamRuntime> streamRuntime = new ArrayList<>();
    List<OutputCallback> streamCallbacks = new ArrayList<>();
    for (QueryRuntime queryRuntime : queryProcessorMap.values()) {
        streamRuntime.add(((QueryRuntimeImpl) queryRuntime).getStreamRuntime());
        streamCallbacks.add(((QueryRuntimeImpl) queryRuntime).getOutputCallback());
    }
    for (StreamRuntime streamRuntime1 : streamRuntime) {
        for (SingleStreamRuntime singleStreamRuntime : streamRuntime1.getSingleStreamRuntimes()) {
            singleStreamRuntime.getProcessStreamReceiver().setSiddhiDebugger(siddhiDebugger);
        }
    }
    for (OutputCallback callback : streamCallbacks) {
        callback.setSiddhiDebugger(siddhiDebugger);
    }
    start();
    return siddhiDebugger;
}
Also used : SiddhiDebugger(io.siddhi.core.debugger.SiddhiDebugger) OnDemandQueryRuntime(io.siddhi.core.query.OnDemandQueryRuntime) QueryRuntime(io.siddhi.core.query.QueryRuntime) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) ArrayList(java.util.ArrayList) StreamRuntime(io.siddhi.core.query.input.stream.StreamRuntime) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) OutputCallback(io.siddhi.core.query.output.callback.OutputCallback)

Example 5 with OutputCallback

use of io.siddhi.core.query.output.callback.OutputCallback in project siddhi by wso2.

the class OnDemandQueryParser method getQuerySelector.

private static QuerySelector getQuerySelector(MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, Map<String, Window> windowMap, int metaPosition, OnDemandQuery onDemandQuery, LockWrapper lockWrapper, SiddhiQueryContext siddhiQueryContext) {
    QuerySelector querySelector = SelectorParser.parse(onDemandQuery.getSelector(), onDemandQuery.getOutputStream(), matchingMetaInfoHolder.getMetaStateEvent(), tableMap, variableExpressionExecutors, metaPosition, ProcessingMode.BATCH, false, siddhiQueryContext);
    PassThroughOutputRateLimiter rateLimiter = new PassThroughOutputRateLimiter(siddhiQueryContext.getName());
    rateLimiter.init(lockWrapper, !onDemandQuery.getSelector().getGroupByList().isEmpty(), siddhiQueryContext);
    OutputCallback outputCallback = OutputParser.constructOutputCallback(onDemandQuery.getOutputStream(), matchingMetaInfoHolder.getMetaStateEvent().getOutputStreamDefinition(), tableMap, windowMap, true, siddhiQueryContext);
    rateLimiter.setOutputCallback(outputCallback);
    querySelector.setNextProcessor(rateLimiter);
    QueryParserHelper.reduceMetaComplexEvent(matchingMetaInfoHolder.getMetaStateEvent());
    QueryParserHelper.updateVariablePosition(matchingMetaInfoHolder.getMetaStateEvent(), variableExpressionExecutors);
    querySelector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(matchingMetaInfoHolder.getMetaStateEvent()));
    return querySelector;
}
Also used : QuerySelector(io.siddhi.core.query.selector.QuerySelector) PassThroughOutputRateLimiter(io.siddhi.core.query.output.ratelimit.PassThroughOutputRateLimiter) OutputCallback(io.siddhi.core.query.output.callback.OutputCallback)

Aggregations

OutputCallback (io.siddhi.core.query.output.callback.OutputCallback)5 QueryRuntime (io.siddhi.core.query.QueryRuntime)3 StreamRuntime (io.siddhi.core.query.input.stream.StreamRuntime)3 SingleStreamRuntime (io.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 QuerySelector (io.siddhi.core.query.selector.QuerySelector)3 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)2 PassThroughOutputRateLimiter (io.siddhi.core.query.output.ratelimit.PassThroughOutputRateLimiter)2 AggregationRuntime (io.siddhi.core.aggregation.AggregationRuntime)1 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)1 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)1 SiddhiDebugger (io.siddhi.core.debugger.SiddhiDebugger)1 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)1 StateEventFactory (io.siddhi.core.event.state.StateEventFactory)1 StateEventPopulatorFactory (io.siddhi.core.event.state.populater.StateEventPopulatorFactory)1 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)1 EventType (io.siddhi.core.event.stream.MetaStreamEvent.EventType)1 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)1 OnDemandQueryRuntime (io.siddhi.core.query.OnDemandQueryRuntime)1 QueryRuntimeImpl (io.siddhi.core.query.QueryRuntimeImpl)1 ProcessStreamReceiver (io.siddhi.core.query.input.ProcessStreamReceiver)1