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());
}
}
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);
}
}
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;
}
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);
}
}
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());
}
}
}
}
Aggregations