Search in sources :

Example 1 with StreamJunction

use of org.ballerinalang.siddhi.core.stream.StreamJunction in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) InsertIntoStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.InsertIntoStream) StreamJunction(org.ballerinalang.siddhi.core.stream.StreamJunction) InsertIntoStreamCallback(org.ballerinalang.siddhi.core.query.output.callback.InsertIntoStreamCallback)

Example 2 with StreamJunction

use of org.ballerinalang.siddhi.core.stream.StreamJunction in project ballerina by ballerina-lang.

the class DefinitionParserHelper method addStreamJunction.

public static void addStreamJunction(StreamDefinition streamDefinition, ConcurrentMap<String, StreamJunction> streamJunctionMap, SiddhiAppContext siddhiAppContext) {
    if (!streamJunctionMap.containsKey(streamDefinition.getId())) {
        StreamJunction streamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
        streamJunctionMap.putIfAbsent(streamDefinition.getId(), streamJunction);
    }
}
Also used : StreamJunction(org.ballerinalang.siddhi.core.stream.StreamJunction)

Example 3 with StreamJunction

use of org.ballerinalang.siddhi.core.stream.StreamJunction in project ballerina by ballerina-lang.

the class PartitionRuntime method addQuery.

public QueryRuntime addQuery(QueryRuntime metaQueryRuntime) {
    Query query = metaQueryRuntime.getQuery();
    if (query.getOutputStream() instanceof InsertIntoStream && metaQueryRuntime.getOutputCallback() instanceof InsertIntoStreamCallback) {
        InsertIntoStreamCallback insertIntoStreamCallback = (InsertIntoStreamCallback) metaQueryRuntime.getOutputCallback();
        StreamDefinition streamDefinition = insertIntoStreamCallback.getOutputStreamDefinition();
        String id = streamDefinition.getId();
        if (((InsertIntoStream) query.getOutputStream()).isInnerStream()) {
            metaQueryRuntime.setToLocalStream(true);
            localStreamDefinitionMap.putIfAbsent(id, streamDefinition);
            DefinitionParserHelper.validateOutputStream(streamDefinition, localStreamDefinitionMap.get(id));
            StreamJunction outputStreamJunction = localStreamJunctionMap.get(id);
            if (outputStreamJunction == null) {
                outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
                localStreamJunctionMap.putIfAbsent(id, outputStreamJunction);
            }
            insertIntoStreamCallback.init(localStreamJunctionMap.get(id));
        } else {
            streamDefinitionMap.putIfAbsent(id, streamDefinition);
            DefinitionParserHelper.validateOutputStream(streamDefinition, streamDefinitionMap.get(id));
            StreamJunction outputStreamJunction = streamJunctionMap.get(id);
            if (outputStreamJunction == null) {
                outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
                streamJunctionMap.putIfAbsent(id, outputStreamJunction);
            }
            insertIntoStreamCallback.init(streamJunctionMap.get(id));
        }
    }
    metaQueryRuntimeMap.put(metaQueryRuntime.getQueryId(), metaQueryRuntime);
    return metaQueryRuntime;
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) InsertIntoStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.InsertIntoStream) StreamJunction(org.ballerinalang.siddhi.core.stream.StreamJunction) InsertIntoStreamCallback(org.ballerinalang.siddhi.core.query.output.callback.InsertIntoStreamCallback)

Example 4 with StreamJunction

use of org.ballerinalang.siddhi.core.stream.StreamJunction in project ballerina by ballerina-lang.

the class PartitionRuntime method clonePartition.

private synchronized void clonePartition(String key) {
    PartitionInstanceRuntime partitionInstance = this.partitionInstanceRuntimeMap.get(key);
    if (partitionInstance == null) {
        List<QueryRuntime> queryRuntimeList = new ArrayList<QueryRuntime>();
        List<QueryRuntime> partitionedQueryRuntimeList = new ArrayList<QueryRuntime>();
        for (QueryRuntime queryRuntime : metaQueryRuntimeMap.values()) {
            QueryRuntime clonedQueryRuntime = queryRuntime.clone(key, localStreamJunctionMap);
            queryRuntimeList.add(clonedQueryRuntime);
            QueryParserHelper.registerMemoryUsageTracking(clonedQueryRuntime.getQueryId(), queryRuntime, SiddhiConstants.METRIC_INFIX_QUERIES, siddhiAppContext, memoryUsageTracker);
            if (queryRuntime.isFromLocalStream()) {
                for (int i = 0; i < clonedQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().size(); i++) {
                    String streamId = queryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver().getStreamId();
                    StreamDefinition streamDefinition;
                    if (streamId.startsWith("#")) {
                        streamDefinition = (StreamDefinition) localStreamDefinitionMap.get(streamId);
                    } else {
                        streamDefinition = (StreamDefinition) streamDefinitionMap.get(streamId);
                    }
                    StreamJunction streamJunction = localStreamJunctionMap.get(streamId + key);
                    if (streamJunction == null) {
                        streamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
                        localStreamJunctionMap.put(streamId + key, streamJunction);
                    }
                    streamJunction.subscribe(clonedQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver());
                }
            } else {
                partitionedQueryRuntimeList.add(clonedQueryRuntime);
            }
        }
        partitionInstanceRuntimeMap.putIfAbsent(key, new PartitionInstanceRuntime(key, queryRuntimeList));
        updatePartitionStreamReceivers(key, partitionedQueryRuntimeList);
    }
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) QueryRuntime(org.ballerinalang.siddhi.core.query.QueryRuntime) StreamJunction(org.ballerinalang.siddhi.core.stream.StreamJunction) ArrayList(java.util.ArrayList)

Example 5 with StreamJunction

use of org.ballerinalang.siddhi.core.stream.StreamJunction in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.core.query.QueryRuntime) StreamJunction(org.ballerinalang.siddhi.core.stream.StreamJunction) StreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.StreamRuntime)

Aggregations

StreamJunction (org.ballerinalang.siddhi.core.stream.StreamJunction)10 QueryRuntime (org.ballerinalang.siddhi.core.query.QueryRuntime)3 InsertIntoStreamCallback (org.ballerinalang.siddhi.core.query.output.callback.InsertIntoStreamCallback)3 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)3 DefinitionNotExistException (org.ballerinalang.siddhi.core.exception.DefinitionNotExistException)2 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)2 StreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.StreamRuntime)2 InsertIntoStream (org.ballerinalang.siddhi.query.api.execution.query.output.stream.InsertIntoStream)2 ArrayList (java.util.ArrayList)1 ProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver)1 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)1 InsertIntoWindowCallback (org.ballerinalang.siddhi.core.query.output.callback.InsertIntoWindowCallback)1 OutputCallback (org.ballerinalang.siddhi.core.query.output.callback.OutputCallback)1 Source (org.ballerinalang.siddhi.core.stream.input.source.Source)1 SourceHandlerManager (org.ballerinalang.siddhi.core.stream.input.source.SourceHandlerManager)1 Sink (org.ballerinalang.siddhi.core.stream.output.sink.Sink)1 SinkHandlerManager (org.ballerinalang.siddhi.core.stream.output.sink.SinkHandlerManager)1 Table (org.ballerinalang.siddhi.core.table.Table)1 RecordTableHandler (org.ballerinalang.siddhi.core.table.record.RecordTableHandler)1 RecordTableHandlerManager (org.ballerinalang.siddhi.core.table.record.RecordTableHandlerManager)1