protected void enableEngineAction( String streamName, EngineActionType engineActionType, Map<String, Object> engineActionParams, StreamOperationServiceWithoutMetrics streamOperationService) { if (!streamStatusDao.isEngineActionEnabled(streamName, engineActionType)) { String engineActionQueryId = siddhiManager.addQuery( QueryFactory.createQuery() .from(QueryFactory.inputStream(streamName)) .insertInto(STREAMING.STATS_NAMES.SINK_STREAM_PREFIX.concat(streamName))); BaseEngineAction engineAction = null; if (engineActionType == EngineActionType.FIRE_RULES) { engineAction = new DroolsEngineAction( droolsConnectionContainer, engineActionParams, siddhiManager, streamOperationService); } siddhiManager.addCallback( engineActionQueryId, callbackService.addEngineCallback(streamName, engineActionType, engineAction)); streamStatusDao.enableEngineAction( streamName, engineActionType, engineActionParams, engineActionQueryId); } }
public void createInternalStream(String streamName, List<ColumnNameTypeValue> columns) { StreamDefinition newStream = QueryFactory.createStreamDefinition().name(streamName); for (ColumnNameTypeValue column : columns) { newStream.attribute(column.getColumn(), getSiddhiType(column.getType())); } siddhiManager.defineStream(newStream); streamStatusDao.createInferredStream(streamName, columns); }
public void enableAction(String streamName, StreamAction action) { if (streamStatusDao.getEnabledActions(streamName).size() == 0) { String actionQueryId = siddhiManager.addQuery( QueryFactory.createQuery() .from(QueryFactory.inputStream(streamName)) .insertInto(STREAMING.STATS_NAMES.SINK_STREAM_PREFIX.concat(streamName))); streamStatusDao.setActionQuery(streamName, actionQueryId); String groupId = null; if (configurationContext != null && configurationContext.isClusteringEnabled()) { groupId = configurationContext.getGroupId(); } siddhiManager.addCallback( actionQueryId, callbackService.add(streamName, streamStatusDao.getEnabledActions(streamName), groupId)); } streamStatusDao.enableAction(streamName, action); }
@Test public void testPatternWithinQuery1() throws InterruptedException { log.info("testPatternWithin1 - OUT 1"); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.defineStream( QueryFactory.createStreamDefinition() .name("Stream1") .attribute("symbol", Attribute.Type.STRING) .attribute("price", Attribute.Type.FLOAT) .attribute("volume", Attribute.Type.INT)); siddhiManager.defineStream( QueryFactory.createStreamDefinition() .name("Stream2") .attribute("symbol", Attribute.Type.STRING) .attribute("price", Attribute.Type.FLOAT) .attribute("volume", Attribute.Type.INT)); Query query = QueryFactory.createQuery(); query.from( QueryFactory.patternStream( Pattern.followedBy( Pattern.every( QueryFactory.inputStream("e1", "Stream1") .filter( Condition.compare( Expression.variable("price"), Condition.Operator.GREATER_THAN, Expression.value(20)))), QueryFactory.inputStream("e2", "Stream2") .filter( Condition.compare( Expression.variable("price"), Condition.Operator.GREATER_THAN, Expression.variable("e1", "price")))), Expression.value(1000))); query.insertInto("OutStream"); query.project( QueryFactory.outputProjector() .project("symbol1", Expression.variable("e1", "symbol")) .project("symbol2", Expression.variable("e2", "symbol"))); String queryReference = siddhiManager.addQuery(query); siddhiManager.addCallback( queryReference, new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); if (eventCount == 0) { Assert.assertArrayEquals(new Object[] {"GOOG", "IBM"}, inEvents[0].getData()); } else { Assert.fail(); } eventCount++; eventArrived = true; } }); InputHandler stream1 = siddhiManager.getInputHandler("Stream1"); InputHandler stream2 = siddhiManager.getInputHandler("Stream2"); stream1.send(new Object[] {"WSO2", 55.6f, 100}); Thread.sleep(1500); stream1.send(new Object[] {"GOOG", 54f, 100}); Thread.sleep(500); stream2.send(new Object[] {"IBM", 55.7f, 100}); Thread.sleep(500); siddhiManager.shutdown(); Assert.assertEquals("Number of success events", 1, eventCount); Assert.assertEquals("Event arrived", true, eventArrived); }