use of org.ballerinalang.siddhi.core.util.config.ConfigReader in project ballerina by ballerina-lang.
the class DefinitionParserHelper method addFunction.
public static void addFunction(SiddhiAppContext siddhiAppContext, final FunctionDefinition functionDefinition) {
Extension extension = new Extension() {
@Override
public String getNamespace() {
return "script";
}
@Override
public String getName() {
return functionDefinition.getLanguage().toLowerCase();
}
};
try {
Script script = (Script) SiddhiClassLoader.loadExtensionImplementation(extension, ScriptExtensionHolder.getInstance(siddhiAppContext));
ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(extension.getNamespace(), extension.getName());
script.setReturnType(functionDefinition.getReturnType());
script.init(functionDefinition.getId(), functionDefinition.getBody(), configReader);
siddhiAppContext.getScriptFunctionMap().put(functionDefinition.getId(), script);
} catch (Throwable t) {
ExceptionUtil.populateQueryContext(t, functionDefinition, siddhiAppContext);
throw t;
}
}
use of org.ballerinalang.siddhi.core.util.config.ConfigReader in project ballerina by ballerina-lang.
the class DefinitionParserHelper method addTable.
public static void addTable(TableDefinition tableDefinition, ConcurrentMap<String, Table> tableMap, SiddhiAppContext siddhiAppContext) {
if (!tableMap.containsKey(tableDefinition.getId())) {
MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
tableMetaStreamEvent.addInputDefinition(tableDefinition);
for (Attribute attribute : tableDefinition.getAttributeList()) {
tableMetaStreamEvent.addOutputData(attribute);
}
StreamEventPool tableStreamEventPool = new StreamEventPool(tableMetaStreamEvent, 10);
StreamEventCloner tableStreamEventCloner = new StreamEventCloner(tableMetaStreamEvent, tableStreamEventPool);
Annotation annotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_STORE, tableDefinition.getAnnotations());
Table table;
ConfigReader configReader = null;
RecordTableHandlerManager recordTableHandlerManager = null;
RecordTableHandler recordTableHandler = null;
if (annotation != null) {
annotation = updateAnnotationRef(annotation, SiddhiConstants.NAMESPACE_STORE, siddhiAppContext);
String tableType = annotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
Extension extension = new Extension() {
@Override
public String getNamespace() {
return SiddhiConstants.NAMESPACE_STORE;
}
@Override
public String getName() {
return tableType;
}
};
recordTableHandlerManager = siddhiAppContext.getSiddhiContext().getRecordTableHandlerManager();
if (recordTableHandlerManager != null) {
recordTableHandler = recordTableHandlerManager.generateRecordTableHandler();
}
table = (Table) SiddhiClassLoader.loadExtensionImplementation(extension, TableExtensionHolder.getInstance(siddhiAppContext));
configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(extension.getNamespace(), extension.getName());
} else {
table = new InMemoryTable();
}
table.initTable(tableDefinition, tableStreamEventPool, tableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
if (recordTableHandler != null) {
recordTableHandlerManager.registerRecordTableHandler(recordTableHandler.getElementId(), recordTableHandler);
}
tableMap.putIfAbsent(tableDefinition.getId(), table);
}
}
Aggregations