Search in sources :

Example 1 with CriticalAnalyzerImpl

use of org.apache.activemq.artemis.utils.critical.CriticalAnalyzerImpl in project activemq-artemis by apache.

the class ActiveMQServerImpl method initializeCriticalAnalyzer.

private void initializeCriticalAnalyzer() throws Exception {
    // Some tests will play crazy frequenceistop/start
    CriticalAnalyzer analyzer = this.getCriticalAnalyzer();
    if (analyzer == null) {
        if (configuration.isCriticalAnalyzer()) {
            // this will have its own ScheduledPool
            analyzer = new CriticalAnalyzerImpl();
        } else {
            analyzer = EmptyCriticalAnalyzer.getInstance();
        }
        this.analyzer = analyzer;
    }
    /* Calling this for cases where the server was stopped and now is being restarted... failback, etc...*/
    analyzer.clear();
    analyzer.setCheckTime(configuration.getCriticalAnalyzerCheckPeriod(), TimeUnit.MILLISECONDS).setTimeout(configuration.getCriticalAnalyzerTimeout(), TimeUnit.MILLISECONDS);
    if (configuration.isCriticalAnalyzer()) {
        analyzer.start();
    }
    CriticalAction criticalAction = null;
    final CriticalAnalyzerPolicy criticalAnalyzerPolicy = configuration.getCriticalAnalyzerPolicy();
    switch(criticalAnalyzerPolicy) {
        case HALT:
            criticalAction = criticalComponent -> {
                ActiveMQServerLogger.LOGGER.criticalSystemHalt(criticalComponent);
                threadDump();
                sendCriticalNotification(criticalComponent);
                // Linux systems will have /usr/include/sysexits.h showing 70 as internal software error
                Runtime.getRuntime().halt(70);
            };
            break;
        case SHUTDOWN:
            criticalAction = criticalComponent -> {
                ActiveMQServerLogger.LOGGER.criticalSystemShutdown(criticalComponent);
                threadDump();
                // on the case of a critical failure, -1 cannot simply means forever.
                // in case graceful is -1, we will set it to 30 seconds
                sendCriticalNotification(criticalComponent);
                // you can't stop from the check thread,
                // nor can use an executor
                Thread stopThread = new Thread() {

                    @Override
                    public void run() {
                        try {
                            ActiveMQServerImpl.this.stop();
                        } catch (Throwable e) {
                            logger.warn(e.getMessage(), e);
                        }
                    }
                };
                stopThread.start();
            };
            break;
        case LOG:
            criticalAction = criticalComponent -> {
                ActiveMQServerLogger.LOGGER.criticalSystemLog(criticalComponent);
                threadDump();
                sendCriticalNotification(criticalComponent);
            };
            break;
    }
    analyzer.addAction(criticalAction);
}
Also used : CriticalAnalyzer(org.apache.activemq.artemis.utils.critical.CriticalAnalyzer) EmptyCriticalAnalyzer(org.apache.activemq.artemis.utils.critical.EmptyCriticalAnalyzer) CriticalAction(org.apache.activemq.artemis.utils.critical.CriticalAction) CriticalAnalyzerImpl(org.apache.activemq.artemis.utils.critical.CriticalAnalyzerImpl) CriticalAnalyzerPolicy(org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy)

Aggregations

CriticalAction (org.apache.activemq.artemis.utils.critical.CriticalAction)1 CriticalAnalyzer (org.apache.activemq.artemis.utils.critical.CriticalAnalyzer)1 CriticalAnalyzerImpl (org.apache.activemq.artemis.utils.critical.CriticalAnalyzerImpl)1 CriticalAnalyzerPolicy (org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy)1 EmptyCriticalAnalyzer (org.apache.activemq.artemis.utils.critical.EmptyCriticalAnalyzer)1