Search in sources :

Example 6 with Extension

use of org.ballerinalang.siddhi.query.api.extension.Extension 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)

Example 7 with Extension

use of org.ballerinalang.siddhi.query.api.extension.Extension in project ballerina by ballerina-lang.

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;
        }
    };
}
Also used : Extension(org.ballerinalang.siddhi.query.api.extension.Extension) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)

Aggregations

Extension (org.ballerinalang.siddhi.query.api.extension.Extension)7 ConfigReader (org.ballerinalang.siddhi.core.util.config.ConfigReader)4 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)3 Annotation (org.ballerinalang.siddhi.query.api.annotation.Annotation)3 Sink (org.ballerinalang.siddhi.core.stream.output.sink.Sink)2 OptionHolder (org.ballerinalang.siddhi.core.util.transport.OptionHolder)2 ArrayList (java.util.ArrayList)1 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)1 StreamEventCloner (org.ballerinalang.siddhi.core.event.stream.StreamEventCloner)1 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)1 Script (org.ballerinalang.siddhi.core.function.Script)1 Source (org.ballerinalang.siddhi.core.stream.input.source.Source)1 SourceHandler (org.ballerinalang.siddhi.core.stream.input.source.SourceHandler)1 SourceHandlerManager (org.ballerinalang.siddhi.core.stream.input.source.SourceHandlerManager)1 SourceMapper (org.ballerinalang.siddhi.core.stream.input.source.SourceMapper)1 OutputGroupDeterminer (org.ballerinalang.siddhi.core.stream.output.sink.OutputGroupDeterminer)1 SinkHandler (org.ballerinalang.siddhi.core.stream.output.sink.SinkHandler)1 SinkHandlerManager (org.ballerinalang.siddhi.core.stream.output.sink.SinkHandlerManager)1 SinkMapper (org.ballerinalang.siddhi.core.stream.output.sink.SinkMapper)1 DistributedTransport (org.ballerinalang.siddhi.core.stream.output.sink.distributed.DistributedTransport)1