Search in sources :

Example 6 with ConfigReader

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;
    }
}
Also used : Extension(org.ballerinalang.siddhi.query.api.extension.Extension) Script(org.ballerinalang.siddhi.core.function.Script) ConfigReader(org.ballerinalang.siddhi.core.util.config.ConfigReader)

Example 7 with ConfigReader

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);
    }
}
Also used : Extension(org.ballerinalang.siddhi.query.api.extension.Extension) InMemoryTable(org.ballerinalang.siddhi.core.table.InMemoryTable) InMemoryTable(org.ballerinalang.siddhi.core.table.InMemoryTable) Table(org.ballerinalang.siddhi.core.table.Table) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) ConfigReader(org.ballerinalang.siddhi.core.util.config.ConfigReader) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.ballerinalang.siddhi.core.event.stream.StreamEventCloner) RecordTableHandler(org.ballerinalang.siddhi.core.table.record.RecordTableHandler) RecordTableHandlerManager(org.ballerinalang.siddhi.core.table.record.RecordTableHandlerManager) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) Annotation(org.ballerinalang.siddhi.query.api.annotation.Annotation)

Aggregations

ConfigReader (org.ballerinalang.siddhi.core.util.config.ConfigReader)7 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)5 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)4 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)3 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)3 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)3 Extension (org.ballerinalang.siddhi.query.api.extension.Extension)3 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)2 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)2 WindowProcessor (org.ballerinalang.siddhi.core.query.processor.stream.window.WindowProcessor)2 Annotation (org.ballerinalang.siddhi.query.api.annotation.Annotation)2 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)2 ArrayList (java.util.ArrayList)1 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)1 StreamEventCloner (org.ballerinalang.siddhi.core.event.stream.StreamEventCloner)1 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)1 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)1 AndConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.AndConditionExpressionExecutor)1 BoolConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.BoolConditionExpressionExecutor)1 ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)1