From 699a7ca7efd34a8f6995269a3402c98af30b889e Mon Sep 17 00:00:00 2001 From: Ryan Emerson Date: Tue, 4 Aug 2015 16:09:08 +0100 Subject: [PATCH] [ARTEMIS-147] Add WARN log when setting connection-ttl OR connection-ttl-override equal to check-period. Now works when ARTEMIS is deployed in an application server as well as standalone. --- .../core/config/ConfigurationUtils.java | 26 +++++++++++++++++++ .../impl/FileConfigurationParser.java | 14 ---------- .../core/server/ActiveMQServerLogger.java | 10 +++---- .../core/server/impl/ActiveMQServerImpl.java | 5 ++++ 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/ConfigurationUtils.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/ConfigurationUtils.java index eb17193a2d..c83ca9f0d3 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/ConfigurationUtils.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/ConfigurationUtils.java @@ -24,6 +24,7 @@ import org.apache.activemq.artemis.core.config.ha.ReplicatedPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration; import org.apache.activemq.artemis.core.config.ha.SharedStoreSlavePolicyConfiguration; import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle; +import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; import org.apache.activemq.artemis.core.server.cluster.ha.BackupPolicy; import org.apache.activemq.artemis.core.server.cluster.ha.ColocatedPolicy; import org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy; @@ -143,4 +144,29 @@ public final class ConfigurationUtils } return null; } + + // A method to check the passed Configuration object and warn users if semantically unwise parameters are present + public static void validateConfiguration(Configuration configuration) + { + // Warn if connection-ttl-override/connection-ttl == check-period + compareTTLWithCheckPeriod(configuration); + } + + private static void compareTTLWithCheckPeriod(Configuration configuration) + { + for (ClusterConnectionConfiguration c : configuration.getClusterConfigurations()) + compareTTLWithCheckPeriod(c.getName(), c.getConnectionTTL(), configuration.getConnectionTTLOverride(), c.getClientFailureCheckPeriod()); + + for (BridgeConfiguration c : configuration.getBridgeConfigurations()) + compareTTLWithCheckPeriod(c.getName(), c.getConnectionTTL(), configuration.getConnectionTTLOverride(), c.getClientFailureCheckPeriod()); + } + + private static void compareTTLWithCheckPeriod(String name, long connectionTTL, long connectionTTLOverride, long checkPeriod) + { + if (connectionTTLOverride == checkPeriod) + ActiveMQServerLogger.LOGGER.connectionTTLEqualsCheckPeriod(name, "connection-ttl-override", "check-period"); + + if (connectionTTL == checkPeriod) + ActiveMQServerLogger.LOGGER.connectionTTLEqualsCheckPeriod(name, "connection-ttl", "check-period"); + } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java index c1b767a66a..708b710cb8 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java @@ -1525,9 +1525,6 @@ public final class FileConfigurationParser extends XMLConfigurationUtil } } - // Warn if connection-ttl-override/connection-ttl == check-period - compareTTLWithCheckPeriod(mainConfig, connectionTTL, clientFailureCheckPeriod); - ClusterConnectionConfiguration config = new ClusterConnectionConfiguration() .setName(name) .setAddress(address) @@ -1689,8 +1686,6 @@ public final class FileConfigurationParser extends XMLConfigurationUtil } } - // Warn if connection-ttl-override/connection-ttl == check-period - compareTTLWithCheckPeriod(mainConfig, connectionTTL, clientFailureCheckPeriod); BridgeConfiguration config = new BridgeConfiguration() .setName(name) @@ -1811,13 +1806,4 @@ public final class FileConfigurationParser extends XMLConfigurationUtil .setParams(params) .setName(name); } - - private void compareTTLWithCheckPeriod(final Configuration config, final long connectionTTL, final long checkPeriod) - { - if (config.getConnectionTTLOverride() == checkPeriod) - ActiveMQServerLogger.LOGGER.connectionTTLEqualsCheckPeriod("connection-ttl-override", "check-period"); - - if (connectionTTL == checkPeriod) - ActiveMQServerLogger.LOGGER.connectionTTLEqualsCheckPeriod("connection-ttl", "check-period"); - } } \ No newline at end of file diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java index 11e6f6198c..69b34e8b8a 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java @@ -1168,11 +1168,11 @@ public interface ActiveMQServerLogger extends BasicLogger @LogMessage(level = Logger.Level.WARN) @Message(id = 222202, - value = "<{0}> should not be set to the same value as <{1}>. " + - "If a system is under high load, or there is a minor network delay, " + - "there is a high probability of a cluster split/failure due to connection timeout.", - format = Message.Format.MESSAGE_FORMAT) - void connectionTTLEqualsCheckPeriod(String ttl, String checkPeriod); + value = "{0}: <{1}> should not be set to the same value as <{2}>. " + + "If a system is under high load, or there is a minor network delay, " + + "there is a high probability of a cluster split/failure due to connection timeout.", + format = Message.Format.MESSAGE_FORMAT) + void connectionTTLEqualsCheckPeriod(String connectionName, String ttl, String checkPeriod); @LogMessage(level = Logger.Level.ERROR) @Message(id = 224000, value = "Failure in initialisation", format = Message.Format.MESSAGE_FORMAT) 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 9d7e95baed..e33286c9f3 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 @@ -316,6 +316,11 @@ public class ActiveMQServerImpl implements ActiveMQServer { configuration = new ConfigurationImpl(); } + else + { + ConfigurationUtils.validateConfiguration(configuration); + } + if (mbeanServer == null) { // Just use JVM mbean server