Search in sources :

Example 1 with EternalReferencedHolder

use of org.wso2.siddhi.core.util.extension.holder.EternalReferencedHolder in project siddhi by wso2.

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.wso2.siddhi.core.table.Table) SourceHandlerManager(org.wso2.siddhi.core.stream.input.source.SourceHandlerManager) RecordTableHandler(org.wso2.siddhi.core.table.record.RecordTableHandler) EternalReferencedHolder(org.wso2.siddhi.core.util.extension.holder.EternalReferencedHolder) Source(org.wso2.siddhi.core.stream.input.source.Source) Sink(org.wso2.siddhi.core.stream.output.sink.Sink) StreamJunction(org.wso2.siddhi.core.stream.StreamJunction) SinkHandlerManager(org.wso2.siddhi.core.stream.output.sink.SinkHandlerManager) RecordTableHandlerManager(org.wso2.siddhi.core.table.record.RecordTableHandlerManager)

Aggregations

StreamJunction (org.wso2.siddhi.core.stream.StreamJunction)1 Source (org.wso2.siddhi.core.stream.input.source.Source)1 SourceHandlerManager (org.wso2.siddhi.core.stream.input.source.SourceHandlerManager)1 Sink (org.wso2.siddhi.core.stream.output.sink.Sink)1 SinkHandlerManager (org.wso2.siddhi.core.stream.output.sink.SinkHandlerManager)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 EternalReferencedHolder (org.wso2.siddhi.core.util.extension.holder.EternalReferencedHolder)1