Repository: activemq-artemis Updated Branches: refs/heads/master b2c5cb06e -> 78f5ab096
NO-JIRA: Refactoring method on critical analyzer Same semantics, no need for jira here Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/78f5ab09 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/78f5ab09 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/78f5ab09 Branch: refs/heads/master Commit: 78f5ab096f0d3f3f4790fe784d44aedf3121ff7f Parents: b2c5cb0 Author: Clebert Suconic <clebertsuco...@apache.org> Authored: Tue Sep 26 17:21:28 2017 -0400 Committer: Clebert Suconic <clebertsuco...@apache.org> Committed: Tue Sep 26 17:27:04 2017 -0400 ---------------------------------------------------------------------- .../core/server/impl/ActiveMQServerImpl.java | 188 +++++++++---------- 1 file changed, 90 insertions(+), 98 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/78f5ab09/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java ---------------------------------------------------------------------- diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 4cca7ba..969493e 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -176,6 +176,7 @@ import org.apache.activemq.artemis.utils.collections.ConcurrentHashSet; import org.apache.activemq.artemis.utils.critical.CriticalAction; import org.apache.activemq.artemis.utils.critical.CriticalAnalyzer; import org.apache.activemq.artemis.utils.critical.CriticalAnalyzerImpl; +import org.apache.activemq.artemis.utils.critical.CriticalComponent; import org.apache.activemq.artemis.utils.critical.EmptyCriticalAnalyzer; import org.jboss.logging.Logger; @@ -506,104 +507,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { configuration.parseSystemProperties(); - /** Calling this for cases where the server was stopped and now is being restarted... failback, etc...*/ - this.analyzer.clear(); - - this.getCriticalAnalyzer().setCheckTime(configuration.getCriticalAnalyzerCheckPeriod(), TimeUnit.MILLISECONDS).setTimeout(configuration.getCriticalAnalyzerTimeout(), TimeUnit.MILLISECONDS); - - if (configuration.isCriticalAnalyzer()) { - this.getCriticalAnalyzer().start(); - } - - CriticalAction criticalAction = null; - final CriticalAnalyzerPolicy criticalAnalyzerPolicy = configuration.getCriticalAnalyzerPolicy(); - switch (criticalAnalyzerPolicy) { - - case HALT: - criticalAction = criticalComponent -> { - - ActiveMQServerLogger.LOGGER.criticalSystemHalt(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 - long timeout = configuration.getGracefulShutdownTimeout() < 0 ? 30000 : configuration.getGracefulShutdownTimeout(); - - Thread notificationSender = new Thread() { - @Override - public void run() { - try { - callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.criticalFailure(criticalComponent) : null); - } catch (Throwable e) { - logger.warn(e.getMessage(), e); - } - } - }; - - // I'm using a different thread here as we need to manage timeouts - notificationSender.start(); - - try { - notificationSender.join(timeout); - } catch (InterruptedException ignored) { - } - - Runtime.getRuntime().halt(70); // Linux systems will have /usr/include/sysexits.h showing 70 as internal software error - - }; - 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 - long timeout = configuration.getGracefulShutdownTimeout() < 0 ? 30000 : configuration.getGracefulShutdownTimeout(); - - Thread notificationSender = new Thread() { - @Override - public void run() { - try { - callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.criticalFailure(criticalComponent) : null); - } catch (Throwable e) { - logger.warn(e.getMessage(), e); - } - } - }; - - // I'm using a different thread here as we need to manage timeouts - notificationSender.start(); - - try { - notificationSender.join(timeout); - } catch (InterruptedException ignored) { - } - - // 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 = ActiveMQServerLogger.LOGGER::criticalSystemLog; - break; - } - - this.getCriticalAnalyzer().addAction(criticalAction); + initializeCriticalAnalyzer(); startDate = new Date(); @@ -668,6 +572,94 @@ public class ActiveMQServerImpl implements ActiveMQServer { } } + private void initializeCriticalAnalyzer() throws Exception { + /** Calling this for cases where the server was stopped and now is being restarted... failback, etc...*/ + this.analyzer.clear(); + + this.getCriticalAnalyzer().setCheckTime(configuration.getCriticalAnalyzerCheckPeriod(), TimeUnit.MILLISECONDS).setTimeout(configuration.getCriticalAnalyzerTimeout(), TimeUnit.MILLISECONDS); + + if (configuration.isCriticalAnalyzer()) { + this.getCriticalAnalyzer().start(); + } + + CriticalAction criticalAction = null; + final CriticalAnalyzerPolicy criticalAnalyzerPolicy = configuration.getCriticalAnalyzerPolicy(); + switch (criticalAnalyzerPolicy) { + + case HALT: + criticalAction = criticalComponent -> { + + ActiveMQServerLogger.LOGGER.criticalSystemHalt(criticalComponent); + + threadDump(); + sendCriticalNotification(criticalComponent); + + Runtime.getRuntime().halt(70); // Linux systems will have /usr/include/sysexits.h showing 70 as internal software error + + }; + 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 -> { + sendCriticalNotification(criticalComponent); + ActiveMQServerLogger.LOGGER.criticalSystemLog(criticalComponent); + }; + break; + } + + this.getCriticalAnalyzer().addAction(criticalAction); + } + + private void sendCriticalNotification(final CriticalComponent criticalComponent) { + // on the case of a critical failure, -1 cannot simply means forever. + // in case graceful is -1, we will set it to 30 seconds + long timeout = configuration.getGracefulShutdownTimeout() < 0 ? 30000 : configuration.getGracefulShutdownTimeout(); + + Thread notificationSender = new Thread() { + @Override + public void run() { + try { + callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.criticalFailure(criticalComponent) : null); + } catch (Throwable e) { + logger.warn(e.getMessage(), e); + } + } + }; + + // I'm using a different thread here as we need to manage timeouts + notificationSender.start(); + + try { + notificationSender.join(timeout); + } catch (InterruptedException ignored) { + } + } + @Override public ReplicationEndpoint getReplicationEndpoint() { if (activation instanceof SharedNothingBackupActivation) {