use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.
the class DefinitionParserHelper method constructExtension.
public static Extension constructExtension(StreamDefinition streamDefinition, String typeName, String typeValue, Annotation annotation, String defaultNamespace) {
String[] namespaceAndName = typeValue.split(SiddhiConstants.EXTENSION_SEPARATOR);
String namespace;
String name;
if (namespaceAndName.length == 1) {
namespace = defaultNamespace;
name = namespaceAndName[0];
} else if (namespaceAndName.length == 2) {
namespace = namespaceAndName[0];
name = namespaceAndName[1];
} else {
throw new SiddhiAppCreationException("Malformed '" + typeName + "' annotation type '" + typeValue + "' " + "provided, for annotation '" + annotation + "' on stream '" + streamDefinition.getId() + "', " + "it should be either '<namespace>:<name>' or '<name>'", annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex());
}
return new Extension() {
@Override
public String getNamespace() {
return namespace;
}
@Override
public String getName() {
return name;
}
};
}
use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.
the class QueryParserHelper method createThroughputTracker.
public static ThroughputTracker createThroughputTracker(SiddhiAppContext siddhiAppContext, String name, String type, String function) {
ThroughputTracker throughputTracker = null;
if (siddhiAppContext.getStatisticsManager() != null) {
String metricName = siddhiAppContext.getSiddhiContext().getStatisticsConfiguration().getMetricPrefix() + SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS + SiddhiConstants.METRIC_DELIMITER + siddhiAppContext.getName() + SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_SIDDHI + SiddhiConstants.METRIC_DELIMITER + type + SiddhiConstants.METRIC_DELIMITER + name;
if (function != null) {
metricName += SiddhiConstants.METRIC_DELIMITER + function;
}
metricName += SiddhiConstants.METRIC_DELIMITER + "throughput";
boolean matchExist = false;
for (String regex : siddhiAppContext.getIncludedMetrics()) {
if (metricName.matches(regex)) {
matchExist = true;
break;
}
}
if (matchExist) {
throughputTracker = siddhiAppContext.getSiddhiContext().getStatisticsConfiguration().getFactory().createThroughputTracker(metricName, siddhiAppContext.getStatisticsManager());
}
}
return throughputTracker;
}
use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.
the class SiddhiExtensionLoader method addExtensionToMap.
/**
* Adding extensions to Siddhi siddhiExtensionsMap.
*
* @param extensionClass extension class
* @param siddhiExtensionsMap reference map for the Siddhi extension
*/
private static void addExtensionToMap(Class extensionClass, Map<String, Class> siddhiExtensionsMap) {
Extension siddhiExtensionAnnotation = (Extension) extensionClass.getAnnotation(Extension.class);
if (siddhiExtensionAnnotation != null) {
if (!siddhiExtensionAnnotation.name().isEmpty()) {
Class previousClass = null;
if (!siddhiExtensionAnnotation.namespace().isEmpty()) {
String key = siddhiExtensionAnnotation.namespace() + SiddhiConstants.EXTENSION_SEPARATOR + siddhiExtensionAnnotation.name();
Class existingValue = siddhiExtensionsMap.get(key);
if (existingValue == null) {
previousClass = siddhiExtensionsMap.put(key, extensionClass);
}
if (previousClass != null) {
log.warn("Dropping extension '" + extensionClass + "' as '" + previousClass + "' was already " + "loaded with the same namespace and name '" + siddhiExtensionAnnotation.namespace() + SiddhiConstants.EXTENSION_SEPARATOR + siddhiExtensionAnnotation.name() + "'");
}
} else {
previousClass = siddhiExtensionsMap.put(siddhiExtensionAnnotation.name(), extensionClass);
if (previousClass != null) {
log.warn("Dropping extension '" + extensionClass + "' as '" + previousClass + "' was already " + "loaded with the " + "same name '" + siddhiExtensionAnnotation.name() + "'");
}
}
} else {
log.error("Unable to load extension " + extensionClass.getName() + ", missing Extension annotation.");
}
} else {
log.error("Unable to load extension " + extensionClass.getName() + ", empty name element given in " + "Extension annotation.");
}
}
use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery22.
@Test
public void testPartitionQuery22() throws InterruptedException {
log.info("Partition test22");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest10') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream#window.time(1 sec) " + "select symbol, avg(price) as avgPrice, volume " + "having avgPrice > 10" + "insert expired events into OutStockStream ;" + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
count.incrementAndGet();
if (count.get() == 1) {
AssertJUnit.assertEquals(75.0, event.getData()[1]);
}
eventArrived = true;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75f, 100 });
inputHandler.send(new Object[] { "IBM", 75f, 100 });
SiddhiTestHelper.waitForEvents(200, 1, count, 60000);
AssertJUnit.assertTrue(1 <= count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.ballerinalang.compiler.util.Name in project siddhi by wso2.
the class PartitionTestCase1 method testDivideExpressionExecutorDoubleCase.
@Test
public void testDivideExpressionExecutorDoubleCase() throws InterruptedException {
log.info("Partition testDivideExpressionExecutorDoubleCase");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('testDivideExpressionExecutorDoubleCase') " + "define stream cseEventStream (atr1 string, atr2 string, atr3 int, atr4 double, " + "atr5 long, atr6 long, atr7 double, atr8 float , atr9 bool, atr10 bool, atr11 int);" + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[atr5 < 700 ] select atr4/atr7 as dividedVal, atr5 as threshold, atr1 as" + " symbol, " + "cast(atr2, 'double') as priceInDouble, sum(atr7) as summedValue insert " + "into OutStockStream ; end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
count.incrementAndGet();
if (count.get() == 1) {
AssertJUnit.assertEquals(8.836395450568679, event.getData(0));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(6.640368178829717, event.getData(0));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(2.255140393544108, event.getData(0));
eventArrived = true;
}
if (count.get() == 4) {
AssertJUnit.assertEquals(1.156400274788184, event.getData(0));
eventArrived = true;
}
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", null, 100, 101.0, 500L, 200L, 11.43, 75.7f, false, true, 105 });
inputHandler.send(new Object[] { "WSO2", "aa", 100, 101.0, 501L, 201L, 15.21, 76.7f, false, true, 106 });
inputHandler.send(new Object[] { "IBM", null, 100, 102.0, 502L, 202L, 45.23, 77.7f, false, true, 107 });
inputHandler.send(new Object[] { "ORACLE", null, 100, 101.0, 502L, 202L, 87.34, 77.7f, false, false, 108 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations