Search in sources :

Example 1 with OutputCallback

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

the class SiddhiAppRuntime 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(queryRuntime.getStreamRuntime());
        streamCallbacks.add(queryRuntime.getOutputCallback());
    }
    for (StreamRuntime streamRuntime1 : streamRuntime) {
        for (SingleStreamRuntime singleStreamRuntime : streamRuntime1.getSingleStreamRuntimes()) {
            singleStreamRuntime.getProcessStreamReceiver().setSiddhiDebugger(siddhiDebugger);
        }
    }
    for (OutputCallback callback : streamCallbacks) {
        callback.setSiddhiDebugger(siddhiDebugger);
    }
    start();
    running = true;
    return siddhiDebugger;
}
Also used : SiddhiDebugger(org.wso2.siddhi.core.debugger.SiddhiDebugger) QueryRuntime(org.wso2.siddhi.core.query.QueryRuntime) StoreQueryRuntime(org.wso2.siddhi.core.query.StoreQueryRuntime) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) ArrayList(java.util.ArrayList) StreamRuntime(org.wso2.siddhi.core.query.input.stream.StreamRuntime) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) OutputCallback(org.wso2.siddhi.core.query.output.callback.OutputCallback)

Example 2 with OutputCallback

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

the class OutputParser method constructOutputCallback.

public static OutputCallback constructOutputCallback(OutputStream outStream, String key, ConcurrentMap<String, StreamJunction> streamJunctionMap, StreamDefinition outputStreamDefinition, SiddhiAppContext siddhiAppContext, String queryName) {
    String id = outStream.getId();
    // Construct CallBack
    if (outStream instanceof InsertIntoStream) {
        StreamJunction outputStreamJunction = streamJunctionMap.get(id + key);
        if (outputStreamJunction == null) {
            outputStreamJunction = new StreamJunction(outputStreamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
            streamJunctionMap.putIfAbsent(id + key, outputStreamJunction);
        }
        InsertIntoStreamCallback insertIntoStreamCallback = new InsertIntoStreamCallback(outputStreamDefinition, queryName);
        insertIntoStreamCallback.init(streamJunctionMap.get(id + key));
        return insertIntoStreamCallback;
    } else {
        throw new SiddhiAppCreationException(outStream.getClass().getName() + " not supported", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
    }
}
Also used : SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) InsertIntoStream(org.wso2.siddhi.query.api.execution.query.output.stream.InsertIntoStream) StreamJunction(org.wso2.siddhi.core.stream.StreamJunction) InsertIntoStreamCallback(org.wso2.siddhi.core.query.output.callback.InsertIntoStreamCallback)

Example 3 with OutputCallback

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

the class OutputParser method constructOutputCallback.

public static OutputCallback constructOutputCallback(final OutputStream outStream, StreamDefinition outputStreamDefinition, Map<String, Table> tableMap, Map<String, Window> eventWindowMap, SiddhiAppContext siddhiAppContext, boolean convertToStreamEvent, String queryName) {
    String id = outStream.getId();
    Table table = null;
    Window window = null;
    if (id != null) {
        table = tableMap.get(id);
        window = eventWindowMap.get(id);
    }
    StreamEventPool streamEventPool = null;
    StreamEventConverter streamEventConverter = null;
    MetaStreamEvent tableMetaStreamEvent = null;
    if (table != null) {
        tableMetaStreamEvent = new MetaStreamEvent();
        tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
        TableDefinition matchingTableDefinition = TableDefinition.id("");
        for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
            tableMetaStreamEvent.addOutputData(attribute);
            matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
        }
        matchingTableDefinition.setQueryContextStartIndex(outStream.getQueryContextStartIndex());
        matchingTableDefinition.setQueryContextEndIndex(outStream.getQueryContextEndIndex());
        tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
        streamEventPool = new StreamEventPool(tableMetaStreamEvent, 10);
        streamEventConverter = new ZeroStreamEventConverter();
    }
    // Construct CallBack
    if (outStream instanceof InsertIntoStream) {
        if (window != null) {
            return new InsertIntoWindowCallback(window, outputStreamDefinition, queryName);
        } else if (table != null) {
            DefinitionParserHelper.validateOutputStream(outputStreamDefinition, table.getTableDefinition());
            return new InsertIntoTableCallback(table, outputStreamDefinition, convertToStreamEvent, streamEventPool, streamEventConverter, queryName);
        } else {
            return new InsertIntoStreamCallback(outputStreamDefinition, queryName);
        }
    } else if (outStream instanceof DeleteStream || outStream instanceof UpdateStream || outStream instanceof UpdateOrInsertStream) {
        if (table != null) {
            if (outStream instanceof UpdateStream) {
                if (((UpdateStream) outStream).getUpdateSet() == null) {
                    TableDefinition tableDefinition = table.getTableDefinition();
                    for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
                        if (!tableDefinition.getAttributeList().contains(attribute)) {
                            throw new SiddhiAppCreationException("Attribute " + attribute + " does not exist on " + "Event Table " + tableDefinition, outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
                        }
                    }
                }
            }
            if (outStream instanceof UpdateOrInsertStream) {
                TableDefinition tableDefinition = table.getTableDefinition();
                for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
                    if (!tableDefinition.getAttributeList().contains(attribute)) {
                        throw new SiddhiAppCreationException("Attribute " + attribute + " does not exist on " + "Event Table " + tableDefinition, outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
                    }
                }
            }
            if (outStream instanceof DeleteStream) {
                try {
                    MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
                    CompiledCondition compiledCondition = table.compileCondition((((DeleteStream) outStream).getOnDeleteExpression()), matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
                    StateEventPool stateEventPool = new StateEventPool(matchingMetaInfoHolder.getMetaStateEvent(), 10);
                    return new DeleteTableCallback(table, compiledCondition, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventPool, streamEventPool, streamEventConverter, queryName);
                } catch (SiddhiAppValidationException e) {
                    throw new SiddhiAppCreationException("Cannot create delete for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
                }
            } else if (outStream instanceof UpdateStream) {
                try {
                    MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
                    CompiledCondition compiledCondition = table.compileCondition((((UpdateStream) outStream).getOnUpdateExpression()), matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
                    UpdateSet updateSet = ((UpdateStream) outStream).getUpdateSet();
                    if (updateSet == null) {
                        updateSet = new UpdateSet();
                        for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
                            updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
                        }
                    }
                    CompiledUpdateSet compiledUpdateSet = table.compileUpdateSet(updateSet, matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
                    StateEventPool stateEventPool = new StateEventPool(matchingMetaInfoHolder.getMetaStateEvent(), 10);
                    return new UpdateTableCallback(table, compiledCondition, compiledUpdateSet, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventPool, streamEventPool, streamEventConverter, queryName);
                } catch (SiddhiAppValidationException e) {
                    throw new SiddhiAppCreationException("Cannot create update for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext);
                }
            } else {
                DefinitionParserHelper.validateOutputStream(outputStreamDefinition, table.getTableDefinition());
                try {
                    MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
                    CompiledCondition compiledCondition = table.compileCondition((((UpdateOrInsertStream) outStream).getOnUpdateExpression()), matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
                    UpdateSet updateSet = ((UpdateOrInsertStream) outStream).getUpdateSet();
                    if (updateSet == null) {
                        updateSet = new UpdateSet();
                        for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
                            updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
                        }
                    }
                    CompiledUpdateSet compiledUpdateSet = table.compileUpdateSet(updateSet, matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
                    StateEventPool stateEventPool = new StateEventPool(matchingMetaInfoHolder.getMetaStateEvent(), 10);
                    return new UpdateOrInsertTableCallback(table, compiledCondition, compiledUpdateSet, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventPool, streamEventPool, streamEventConverter, queryName);
                } catch (SiddhiAppValidationException e) {
                    throw new SiddhiAppCreationException("Cannot create update or insert into for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext);
                }
            }
        } else {
            throw new SiddhiAppCreationException("Event table with id :" + id + " does not exist", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
        }
    } else {
        throw new SiddhiAppCreationException(outStream.getClass().getName() + " not supported", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
    }
}
Also used : Variable(org.wso2.siddhi.query.api.expression.Variable) Attribute(org.wso2.siddhi.query.api.definition.Attribute) InsertIntoWindowCallback(org.wso2.siddhi.core.query.output.callback.InsertIntoWindowCallback) UpdateStream(org.wso2.siddhi.query.api.execution.query.output.stream.UpdateStream) ZeroStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter) UpdateTableCallback(org.wso2.siddhi.core.query.output.callback.UpdateTableCallback) DeleteStream(org.wso2.siddhi.query.api.execution.query.output.stream.DeleteStream) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) UpdateOrInsertTableCallback(org.wso2.siddhi.core.query.output.callback.UpdateOrInsertTableCallback) TableDefinition(org.wso2.siddhi.query.api.definition.TableDefinition) InsertIntoTableCallback(org.wso2.siddhi.core.query.output.callback.InsertIntoTableCallback) Window(org.wso2.siddhi.core.window.Window) Table(org.wso2.siddhi.core.table.Table) StateEventPool(org.wso2.siddhi.core.event.state.StateEventPool) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) StreamEventConverter(org.wso2.siddhi.core.event.stream.converter.StreamEventConverter) ZeroStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter) InsertIntoStream(org.wso2.siddhi.query.api.execution.query.output.stream.InsertIntoStream) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) InsertIntoStreamCallback(org.wso2.siddhi.core.query.output.callback.InsertIntoStreamCallback) CompiledUpdateSet(org.wso2.siddhi.core.table.CompiledUpdateSet) UpdateOrInsertStream(org.wso2.siddhi.query.api.execution.query.output.stream.UpdateOrInsertStream) CompiledCondition(org.wso2.siddhi.core.util.collection.operator.CompiledCondition) MatchingMetaInfoHolder(org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) DeleteTableCallback(org.wso2.siddhi.core.query.output.callback.DeleteTableCallback) UpdateSet(org.wso2.siddhi.query.api.execution.query.output.stream.UpdateSet) CompiledUpdateSet(org.wso2.siddhi.core.table.CompiledUpdateSet) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Example 4 with OutputCallback

use of org.wso2.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
 * @return queryRuntime
 */
public static QueryRuntime 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) {
    List<VariableExpressionExecutor> executors = new ArrayList<VariableExpressionExecutor>();
    QueryRuntime queryRuntime;
    Element nameElement = null;
    LatencyTracker latencyTracker = null;
    LockWrapper lockWrapper = null;
    try {
        nameElement = AnnotationHelper.getAnnotationElement("info", "name", query.getAnnotations());
        String queryName = null;
        if (nameElement != null) {
            queryName = nameElement.getValue();
        } else {
            queryName = "query_" + queryIndex + "_" + UUID.randomUUID().toString();
        }
        latencyTracker = QueryParserHelper.createLatencyTracker(siddhiAppContext, queryName, SiddhiConstants.METRIC_INFIX_QUERIES, null);
        OutputStream.OutputEventType outputEventType = query.getOutputStream().getOutputEventType();
        boolean outputExpectsExpiredEvents = false;
        if (outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS) {
            outputExpectsExpiredEvents = true;
        }
        StreamRuntime streamRuntime = InputStreamParser.parse(query.getInputStream(), siddhiAppContext, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, windowMap, aggregationMap, executors, latencyTracker, outputExpectsExpiredEvents, queryName);
        QuerySelector selector = SelectorParser.parse(query.getSelector(), query.getOutputStream(), siddhiAppContext, streamRuntime.getMetaComplexEvent(), tableMap, executors, queryName, SiddhiConstants.UNKNOWN_STATE);
        boolean isWindow = query.getInputStream() instanceof JoinInputStream;
        if (!isWindow && query.getInputStream() instanceof SingleInputStream) {
            for (StreamHandler streamHandler : ((SingleInputStream) query.getInputStream()).getStreamHandlers()) {
                if (streamHandler instanceof org.wso2.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, siddhiAppContext.getScheduledExecutorService(), siddhiAppContext, queryName);
        if (outputRateLimiter instanceof WrappedSnapshotOutputRateLimiter) {
            selector.setBatchingEnabled(false);
        }
        siddhiAppContext.addEternalReferencedHolder(outputRateLimiter);
        OutputCallback outputCallback = OutputParser.constructOutputCallback(query.getOutputStream(), streamRuntime.getMetaComplexEvent().getOutputStreamDefinition(), tableMap, windowMap, siddhiAppContext, !(streamRuntime instanceof SingleStreamRuntime), queryName);
        QueryParserHelper.reduceMetaComplexEvent(streamRuntime.getMetaComplexEvent());
        QueryParserHelper.updateVariablePosition(streamRuntime.getMetaComplexEvent(), executors);
        QueryParserHelper.initStreamRuntime(streamRuntime, streamRuntime.getMetaComplexEvent(), lockWrapper, queryName);
        selector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(streamRuntime.getMetaComplexEvent()));
        queryRuntime = new QueryRuntime(query, siddhiAppContext, streamRuntime, selector, outputRateLimiter, outputCallback, streamRuntime.getMetaComplexEvent(), lockWrapper != null, queryName);
        if (outputRateLimiter instanceof WrappedSnapshotOutputRateLimiter) {
            selector.setBatchingEnabled(false);
            ((WrappedSnapshotOutputRateLimiter) outputRateLimiter).init(streamRuntime.getMetaComplexEvent().getOutputStreamDefinition().getAttributeList().size(), selector.getAttributeProcessorList(), streamRuntime.getMetaComplexEvent());
        }
        outputRateLimiter.init(siddhiAppContext, lockWrapper, queryName);
    } 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 : Element(org.wso2.siddhi.query.api.annotation.Element) OutputStream(org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream) ArrayList(java.util.ArrayList) OutputCallback(org.wso2.siddhi.core.query.output.callback.OutputCallback) QueryRuntime(org.wso2.siddhi.core.query.QueryRuntime) JoinInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) WrappedSnapshotOutputRateLimiter(org.wso2.siddhi.core.query.output.ratelimit.snapshot.WrappedSnapshotOutputRateLimiter) OutputRateLimiter(org.wso2.siddhi.core.query.output.ratelimit.OutputRateLimiter) StreamHandler(org.wso2.siddhi.query.api.execution.query.input.handler.StreamHandler) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) StreamRuntime(org.wso2.siddhi.core.query.input.stream.StreamRuntime) JoinStreamRuntime(org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime) Window(org.wso2.siddhi.core.window.Window) ReentrantLock(java.util.concurrent.locks.ReentrantLock) DuplicateDefinitionException(org.wso2.siddhi.query.api.exception.DuplicateDefinitionException) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) JoinStreamRuntime(org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) QuerySelector(org.wso2.siddhi.core.query.selector.QuerySelector) LockWrapper(org.wso2.siddhi.core.util.lock.LockWrapper) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) LatencyTracker(org.wso2.siddhi.core.util.statistics.LatencyTracker) WrappedSnapshotOutputRateLimiter(org.wso2.siddhi.core.query.output.ratelimit.snapshot.WrappedSnapshotOutputRateLimiter) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Example 5 with OutputCallback

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

the class QueryRuntime method clone.

public QueryRuntime clone(String key, ConcurrentMap<String, StreamJunction> localStreamJunctionMap) {
    LockWrapper lockWrapper = null;
    if (synchronised) {
        lockWrapper = new LockWrapper("");
        lockWrapper.setLock(new ReentrantLock());
    }
    StreamRuntime clonedStreamRuntime = this.streamRuntime.clone(key);
    QuerySelector clonedSelector = this.selector.clone(key);
    OutputRateLimiter clonedOutputRateLimiter = outputRateLimiter.clone(key);
    clonedOutputRateLimiter.init(siddhiAppContext, lockWrapper, queryId);
    QueryRuntime queryRuntime = new QueryRuntime(query, siddhiAppContext, clonedStreamRuntime, clonedSelector, clonedOutputRateLimiter, outputCallback, this.metaComplexEvent, synchronised, this.queryId + key);
    QueryParserHelper.initStreamRuntime(clonedStreamRuntime, metaComplexEvent, lockWrapper, queryId);
    queryRuntime.setToLocalStream(toLocalStream);
    if (!toLocalStream) {
        queryRuntime.outputRateLimiter.setOutputCallback(outputCallback);
        queryRuntime.outputCallback = this.outputCallback;
    } else {
        OutputCallback clonedQueryOutputCallback = OutputParser.constructOutputCallback(query.getOutputStream(), key, localStreamJunctionMap, outputStreamDefinition, siddhiAppContext, queryId);
        queryRuntime.outputRateLimiter.setOutputCallback(clonedQueryOutputCallback);
        queryRuntime.outputCallback = clonedQueryOutputCallback;
    }
    return queryRuntime;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) OutputRateLimiter(org.wso2.siddhi.core.query.output.ratelimit.OutputRateLimiter) QuerySelector(org.wso2.siddhi.core.query.selector.QuerySelector) LockWrapper(org.wso2.siddhi.core.util.lock.LockWrapper) StreamRuntime(org.wso2.siddhi.core.query.input.stream.StreamRuntime) OutputCallback(org.wso2.siddhi.core.query.output.callback.OutputCallback)

Aggregations

StreamRuntime (org.wso2.siddhi.core.query.input.stream.StreamRuntime)4 OutputCallback (org.wso2.siddhi.core.query.output.callback.OutputCallback)4 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)3 QueryRuntime (org.wso2.siddhi.core.query.QueryRuntime)3 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 InsertIntoStreamCallback (org.wso2.siddhi.core.query.output.callback.InsertIntoStreamCallback)3 ArrayList (java.util.ArrayList)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)2 InsertIntoWindowCallback (org.wso2.siddhi.core.query.output.callback.InsertIntoWindowCallback)2 OutputRateLimiter (org.wso2.siddhi.core.query.output.ratelimit.OutputRateLimiter)2 QuerySelector (org.wso2.siddhi.core.query.selector.QuerySelector)2 StreamJunction (org.wso2.siddhi.core.stream.StreamJunction)2 LockWrapper (org.wso2.siddhi.core.util.lock.LockWrapper)2 Window (org.wso2.siddhi.core.window.Window)2 InsertIntoStream (org.wso2.siddhi.query.api.execution.query.output.stream.InsertIntoStream)2 SiddhiDebugger (org.wso2.siddhi.core.debugger.SiddhiDebugger)1 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)1 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)1 StateEventPool (org.wso2.siddhi.core.event.state.StateEventPool)1