Search in sources :

Example 11 with StreamRuntime

use of org.wso2.siddhi.core.query.input.stream.StreamRuntime 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)

Example 12 with StreamRuntime

use of org.wso2.siddhi.core.query.input.stream.StreamRuntime in project siddhi by wso2.

the class PartitionStreamReceiver method addStreamJunction.

/**
 * create local streamJunctions through which events received by partitionStreamReceiver, are sent to
 * queryStreamReceivers
 *
 * @param key              partitioning key
 * @param queryRuntimeList queryRuntime list of the partition
 */
public void addStreamJunction(String key, List<QueryRuntime> queryRuntimeList) {
    StreamJunction streamJunction = cachedStreamJunctionMap.get(streamId + key);
    if (streamJunction == null) {
        streamJunction = partitionRuntime.getLocalStreamJunctionMap().get(streamId + key);
        if (streamJunction == null) {
            streamJunction = createStreamJunction();
            partitionRuntime.addStreamJunction(streamId + key, streamJunction);
        }
        cachedStreamJunctionMap.put(streamId + key, streamJunction);
    }
    for (QueryRuntime queryRuntime : queryRuntimeList) {
        StreamRuntime streamRuntime = queryRuntime.getStreamRuntime();
        for (int i = 0; i < queryRuntime.getInputStreamId().size(); i++) {
            if ((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver().getStreamId().equals(streamId + key)) {
                streamJunction.subscribe((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver());
            }
        }
    }
}
Also used : QueryRuntime(org.wso2.siddhi.core.query.QueryRuntime) StreamJunction(org.wso2.siddhi.core.stream.StreamJunction) StreamRuntime(org.wso2.siddhi.core.query.input.stream.StreamRuntime)

Example 13 with StreamRuntime

use of org.wso2.siddhi.core.query.input.stream.StreamRuntime in project siddhi by wso2.

the class StateStreamRuntime method clone.

@Override
public StreamRuntime clone(String key) {
    StateStreamRuntime stateStreamRuntime = new StateStreamRuntime(siddhiAppContext, metaStateEvent);
    stateStreamRuntime.innerStateRuntime = this.innerStateRuntime.clone(key);
    for (SingleStreamRuntime singleStreamRuntime : stateStreamRuntime.getSingleStreamRuntimes()) {
        ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
        if (processStreamReceiver instanceof SequenceMultiProcessStreamReceiver) {
            ((SequenceMultiProcessStreamReceiver) processStreamReceiver).setStateStreamRuntime(stateStreamRuntime);
        } else if (processStreamReceiver instanceof SequenceSingleProcessStreamReceiver) {
            ((SequenceSingleProcessStreamReceiver) processStreamReceiver).setStateStreamRuntime(stateStreamRuntime);
        }
    }
    ((StreamPreStateProcessor) stateStreamRuntime.innerStateRuntime.getFirstProcessor()).setThisLastProcessor((StreamPostStateProcessor) stateStreamRuntime.innerStateRuntime.getLastProcessor());
    return stateStreamRuntime;
}
Also used : ProcessStreamReceiver(org.wso2.siddhi.core.query.input.ProcessStreamReceiver) SequenceSingleProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver) SequenceMultiProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) SequenceMultiProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) SequenceSingleProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver)

Example 14 with StreamRuntime

use of org.wso2.siddhi.core.query.input.stream.StreamRuntime in project siddhi by wso2.

the class SiddhiAppRuntimeBuilder method addQuery.

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

Aggregations

SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)8 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)6 StreamRuntime (org.wso2.siddhi.core.query.input.stream.StreamRuntime)6 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)5 ProcessStreamReceiver (org.wso2.siddhi.core.query.input.ProcessStreamReceiver)5 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)4 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)4 QueryRuntime (org.wso2.siddhi.core.query.QueryRuntime)4 OutputCallback (org.wso2.siddhi.core.query.output.callback.OutputCallback)4 ArrayList (java.util.ArrayList)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)3 OutputRateLimiter (org.wso2.siddhi.core.query.output.ratelimit.OutputRateLimiter)3 Processor (org.wso2.siddhi.core.query.processor.Processor)3 FindableProcessor (org.wso2.siddhi.core.query.processor.stream.window.FindableProcessor)3 QuerySelector (org.wso2.siddhi.core.query.selector.QuerySelector)3 AggregationRuntime (org.wso2.siddhi.core.aggregation.AggregationRuntime)2 OperationNotSupportedException (org.wso2.siddhi.core.exception.OperationNotSupportedException)2 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)2 JoinProcessor (org.wso2.siddhi.core.query.input.stream.join.JoinProcessor)2