use of org.wso2.siddhi.core.query.QueryRuntime in project siddhi by wso2.
the class PartitionRuntime method addPartitionReceiver.
public void addPartitionReceiver(QueryRuntime queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) {
Query query = queryRuntime.getQuery();
List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, siddhiAppContext, null).getPartitionExecutorLists();
if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) {
SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream();
addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
} else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) {
SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream();
addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getRightInputStream();
addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1));
} else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) {
StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement();
addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0);
}
}
use of org.wso2.siddhi.core.query.QueryRuntime 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());
}
}
}
}
use of org.wso2.siddhi.core.query.QueryRuntime 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();
}
Aggregations