Search in sources :

Example 1 with InMemoryTable

use of org.wso2.siddhi.core.table.InMemoryTable in project siddhi by wso2.

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

Aggregations

MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)1 StreamEventCloner (org.wso2.siddhi.core.event.stream.StreamEventCloner)1 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)1 InMemoryTable (org.wso2.siddhi.core.table.InMemoryTable)1 Table (org.wso2.siddhi.core.table.Table)1 RecordTableHandler (org.wso2.siddhi.core.table.record.RecordTableHandler)1 RecordTableHandlerManager (org.wso2.siddhi.core.table.record.RecordTableHandlerManager)1 ConfigReader (org.wso2.siddhi.core.util.config.ConfigReader)1 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)1 Attribute (org.wso2.siddhi.query.api.definition.Attribute)1 Extension (org.wso2.siddhi.query.api.extension.Extension)1