Search in sources :

Example 1 with RecordTableHandler

use of org.ballerinalang.siddhi.core.table.record.RecordTableHandler in project ballerina by ballerina-lang.

the class SiddhiAppRuntime method shutdown.

public synchronized void shutdown() {
    SourceHandlerManager sourceHandlerManager = siddhiAppContext.getSiddhiContext().getSourceHandlerManager();
    for (List<Source> sources : sourceMap.values()) {
        for (Source source : sources) {
            try {
                if (sourceHandlerManager != null) {
                    sourceHandlerManager.unregisterSourceHandler(source.getMapper().getHandler().getElementId());
                }
                source.shutdown();
            } catch (Throwable t) {
                log.error(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(t, siddhiAppContext)) + " Error in shutting down source '" + StringUtil.removeCRLFCharacters(source.getType()) + "' at '" + StringUtil.removeCRLFCharacters(source.getStreamDefinition().getId()) + "' on Siddhi App '" + siddhiAppContext.getName() + "'.", t);
            }
        }
    }
    for (Table table : tableMap.values()) {
        try {
            table.shutdown();
        } catch (Throwable t) {
            log.error(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(t, siddhiAppContext)) + " Error in shutting down table '" + StringUtil.removeCRLFCharacters(table.getTableDefinition().getId()) + "' on Siddhi App '" + StringUtil.removeCRLFCharacters(siddhiAppContext.getName()) + "'.", t);
        }
    }
    SinkHandlerManager sinkHandlerManager = siddhiAppContext.getSiddhiContext().getSinkHandlerManager();
    for (List<Sink> sinks : sinkMap.values()) {
        for (Sink sink : sinks) {
            try {
                if (sinkHandlerManager != null) {
                    sinkHandlerManager.unregisterSinkHandler(sink.getHandler().getElementId());
                }
                sink.shutdown();
            } catch (Throwable t) {
                log.error(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(t, siddhiAppContext)) + " Error in shutting down sink '" + StringUtil.removeCRLFCharacters(sink.getType()) + "' at '" + StringUtil.removeCRLFCharacters(sink.getStreamDefinition().getId()) + "' on Siddhi App '" + StringUtil.removeCRLFCharacters(siddhiAppContext.getName()) + "'.", t);
            }
        }
    }
    for (Table table : tableMap.values()) {
        RecordTableHandlerManager recordTableHandlerManager = siddhiAppContext.getSiddhiContext().getRecordTableHandlerManager();
        if (recordTableHandlerManager != null) {
            String elementId = null;
            RecordTableHandler recordTableHandler = table.getHandler();
            if (recordTableHandler != null) {
                elementId = recordTableHandler.getElementId();
            }
            if (elementId != null) {
                recordTableHandlerManager.unregisterRecordTableHandler(elementId);
            }
        }
        table.shutdown();
    }
    for (EternalReferencedHolder eternalReferencedHolder : siddhiAppContext.getEternalReferencedHolders()) {
        try {
            eternalReferencedHolder.stop();
        } catch (Throwable t) {
            log.error(StringUtil.removeCRLFCharacters(ExceptionUtil.getMessageWithContext(t, siddhiAppContext)) + " Error while stopping EternalReferencedHolder '" + StringUtil.removeCRLFCharacters(eternalReferencedHolder.toString()) + "' down Siddhi app '" + StringUtil.removeCRLFCharacters(siddhiAppContext.getName()) + "'.", t);
        }
    }
    inputManager.disconnect();
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            for (StreamJunction streamJunction : streamJunctionMap.values()) {
                streamJunction.stopProcessing();
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            siddhiAppContext.getScheduledExecutorService().shutdownNow();
            siddhiAppContext.getExecutorService().shutdownNow();
        }
    }, "Siddhi-SiddhiApp-" + siddhiAppContext.getName() + "-Shutdown-Cleaner");
    thread.start();
    if (siddhiAppRuntimeMap != null) {
        siddhiAppRuntimeMap.remove(siddhiAppContext.getName());
    }
    if (siddhiAppContext.getStatisticsManager() != null) {
        if (siddhiAppContext.isStatsEnabled()) {
            siddhiAppContext.getStatisticsManager().stopReporting();
        }
        siddhiAppContext.getStatisticsManager().cleanup();
    }
    running = false;
}
Also used : Table(org.ballerinalang.siddhi.core.table.Table) SourceHandlerManager(org.ballerinalang.siddhi.core.stream.input.source.SourceHandlerManager) RecordTableHandler(org.ballerinalang.siddhi.core.table.record.RecordTableHandler) EternalReferencedHolder(org.ballerinalang.siddhi.core.util.extension.holder.EternalReferencedHolder) Source(org.ballerinalang.siddhi.core.stream.input.source.Source) Sink(org.ballerinalang.siddhi.core.stream.output.sink.Sink) StreamJunction(org.ballerinalang.siddhi.core.stream.StreamJunction) SinkHandlerManager(org.ballerinalang.siddhi.core.stream.output.sink.SinkHandlerManager) RecordTableHandlerManager(org.ballerinalang.siddhi.core.table.record.RecordTableHandlerManager)

Example 2 with RecordTableHandler

use of org.ballerinalang.siddhi.core.table.record.RecordTableHandler 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

Table (org.ballerinalang.siddhi.core.table.Table)2 RecordTableHandler (org.ballerinalang.siddhi.core.table.record.RecordTableHandler)2 RecordTableHandlerManager (org.ballerinalang.siddhi.core.table.record.RecordTableHandlerManager)2 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 StreamJunction (org.ballerinalang.siddhi.core.stream.StreamJunction)1 Source (org.ballerinalang.siddhi.core.stream.input.source.Source)1 SourceHandlerManager (org.ballerinalang.siddhi.core.stream.input.source.SourceHandlerManager)1 Sink (org.ballerinalang.siddhi.core.stream.output.sink.Sink)1 SinkHandlerManager (org.ballerinalang.siddhi.core.stream.output.sink.SinkHandlerManager)1 InMemoryTable (org.ballerinalang.siddhi.core.table.InMemoryTable)1 ConfigReader (org.ballerinalang.siddhi.core.util.config.ConfigReader)1 EternalReferencedHolder (org.ballerinalang.siddhi.core.util.extension.holder.EternalReferencedHolder)1 Annotation (org.ballerinalang.siddhi.query.api.annotation.Annotation)1 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)1 Extension (org.ballerinalang.siddhi.query.api.extension.Extension)1