use of org.ballerinalang.siddhi.core.query.QueryRuntime in project ballerina by ballerina-lang.
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;
}
use of org.ballerinalang.siddhi.core.query.QueryRuntime in project ballerina by ballerina-lang.
the class SiddhiAppRuntime method addCallback.
public void addCallback(String queryName, QueryCallback callback) {
callback.setContext(siddhiAppContext);
QueryRuntime queryRuntime = queryProcessorMap.get(queryName);
if (queryRuntime == null) {
throw new QueryNotExistException("No query found with name: " + queryName);
}
callback.setQuery(queryRuntime.getQuery());
queryRuntime.addCallback(callback);
}
use of org.ballerinalang.siddhi.core.query.QueryRuntime in project ballerina by ballerina-lang.
the class EventTestCase method testQueryParser.
@Test
public void testQueryParser() {
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
StreamDefinition outStreamDefinition = StreamDefinition.id("outputStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT);
Query query = new Query();
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.NOT_EQUAL, Expression.value(50))));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("outputStream");
Map<String, AbstractDefinition> tableDefinitionMap = new HashMap<>();
Map<String, AbstractDefinition> windowDefinitionMap = new HashMap<>();
Map<String, AbstractDefinition> aggregationDefinitionMap = new HashMap<>();
Map<String, Table> tableMap = new HashMap<String, Table>();
Map<String, Window> eventWindowMap = new HashMap<String, Window>();
Map<String, AggregationRuntime> aggregationMap = new HashMap<String, AggregationRuntime>();
Map<String, List<Source>> eventSourceMap = new HashMap<String, List<Source>>();
Map<String, List<Sink>> eventSinkMap = new HashMap<String, List<Sink>>();
Map<String, AbstractDefinition> streamDefinitionMap = new HashMap<String, AbstractDefinition>();
LockSynchronizer lockSynchronizer = new LockSynchronizer();
streamDefinitionMap.put("cseEventStream", streamDefinition);
streamDefinitionMap.put("outputStream", outStreamDefinition);
SiddhiContext siddhicontext = new SiddhiContext();
SiddhiAppContext context = new SiddhiAppContext();
context.setSiddhiContext(siddhicontext);
context.setElementIdGenerator(new ElementIdGenerator(context.getName()));
context.setSnapshotService(new SnapshotService(context));
QueryRuntime runtime = QueryParser.parse(query, context, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, aggregationMap, eventWindowMap, lockSynchronizer, "1");
AssertJUnit.assertNotNull(runtime);
AssertJUnit.assertTrue(runtime.getStreamRuntime() instanceof SingleStreamRuntime);
AssertJUnit.assertNotNull(runtime.getSelector());
AssertJUnit.assertTrue(runtime.getMetaComplexEvent() instanceof MetaStreamEvent);
}
use of org.ballerinalang.siddhi.core.query.QueryRuntime 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.query.QueryRuntime 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