Search in sources :

Example 1 with QueryRuntime

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;
}
Also used : SiddhiDebugger(org.ballerinalang.siddhi.core.debugger.SiddhiDebugger) StoreQueryRuntime(org.ballerinalang.siddhi.core.query.StoreQueryRuntime) QueryRuntime(org.ballerinalang.siddhi.core.query.QueryRuntime) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) ArrayList(java.util.ArrayList) StreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.StreamRuntime) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) OutputCallback(org.ballerinalang.siddhi.core.query.output.callback.OutputCallback)

Example 2 with QueryRuntime

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);
}
Also used : QueryNotExistException(org.ballerinalang.siddhi.core.exception.QueryNotExistException) StoreQueryRuntime(org.ballerinalang.siddhi.core.query.StoreQueryRuntime) QueryRuntime(org.ballerinalang.siddhi.core.query.QueryRuntime)

Example 3 with QueryRuntime

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);
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) HashMap(java.util.HashMap) ElementIdGenerator(org.ballerinalang.siddhi.core.util.ElementIdGenerator) Source(org.ballerinalang.siddhi.core.stream.input.source.Source) SiddhiContext(org.ballerinalang.siddhi.core.config.SiddhiContext) Sink(org.ballerinalang.siddhi.core.stream.output.sink.Sink) QueryRuntime(org.ballerinalang.siddhi.core.query.QueryRuntime) LockSynchronizer(org.ballerinalang.siddhi.core.util.lock.LockSynchronizer) List(java.util.List) AggregationRuntime(org.ballerinalang.siddhi.core.aggregation.AggregationRuntime) Window(org.ballerinalang.siddhi.core.window.Window) SnapshotService(org.ballerinalang.siddhi.core.util.snapshot.SnapshotService) Table(org.ballerinalang.siddhi.core.table.Table) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) AbstractDefinition(org.ballerinalang.siddhi.query.api.definition.AbstractDefinition) SiddhiAppContext(org.ballerinalang.siddhi.core.config.SiddhiAppContext) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) Test(org.testng.annotations.Test)

Example 4 with QueryRuntime

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);
    }
}
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 QueryRuntime

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

QueryRuntime (org.ballerinalang.siddhi.core.query.QueryRuntime)9 ArrayList (java.util.ArrayList)5 StreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.StreamRuntime)4 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)4 OutputCallback (org.ballerinalang.siddhi.core.query.output.callback.OutputCallback)3 StreamJunction (org.ballerinalang.siddhi.core.stream.StreamJunction)3 Window (org.ballerinalang.siddhi.core.window.Window)3 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)3 Query (org.ballerinalang.siddhi.query.api.execution.query.Query)3 SiddhiAppContext (org.ballerinalang.siddhi.core.config.SiddhiAppContext)2 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)2 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)2 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)2 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)2 PartitionRuntime (org.ballerinalang.siddhi.core.partition.PartitionRuntime)2 StoreQueryRuntime (org.ballerinalang.siddhi.core.query.StoreQueryRuntime)2 ElementIdGenerator (org.ballerinalang.siddhi.core.util.ElementIdGenerator)2 SnapshotService (org.ballerinalang.siddhi.core.util.snapshot.SnapshotService)2 Element (org.ballerinalang.siddhi.query.api.annotation.Element)2 AbstractDefinition (org.ballerinalang.siddhi.query.api.definition.AbstractDefinition)2