diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java index 59d1e89b00..bb2c6c27cf 100644 --- a/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java +++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/FileBrokerTest.java @@ -153,6 +153,55 @@ public class FileBrokerTest { } } + @Test + public void testConfigFileReloadNegative() throws Exception { + ServerDTO serverDTO = new ServerDTO(); + serverDTO.configuration = "broker-reload-disabled.xml"; + FileBroker broker = null; + String path = null; + try { + SecurityConfiguration securityConfiguration = new SecurityConfiguration(); + securityConfiguration.addUser("myUser", "myPass"); + securityConfiguration.addRole("myUser", "guest"); + ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration); + broker = new FileBroker(serverDTO, securityManager, null); + broker.start(); + ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core"); + Assert.assertNotNull(activeMQServer); + Assert.assertTrue(activeMQServer.isStarted()); + Assert.assertTrue(broker.isStarted()); + File file = new File(activeMQServer.getConfiguration().getConfigurationUrl().toURI()); + path = file.getPath(); + Assert.assertNotNull(activeMQServer.getConfiguration().getConfigurationUrl()); + + Thread.sleep(1000); + + ServerLocator locator = ActiveMQClient.createServerLocator("tcp://localhost:61616"); + ClientSessionFactory sf = locator.createSessionFactory(); + ClientSession session = sf.createSession("myUser", "myPass", false, true, false, false, 0); + ClientProducer producer = session.createProducer("DLQ"); + producer.send(session.createMessage(true)); + + replacePatternInFile(path, "guest", "X"); + + Thread.sleep(1000); + + try { + producer.send(session.createMessage(true)); + } catch (Exception e) { + fail("Should not throw an exception: " + e.getMessage()); + } + + locator.close(); + } finally { + assert broker != null; + broker.stop(); + if (path != null) { + replacePatternInFile(path, "X", "guest"); + } + } + } + private void replacePatternInFile(String file, String regex, String replacement) throws IOException { Path path = Paths.get(file); Charset charset = StandardCharsets.UTF_8; diff --git a/artemis-cli/src/test/resources/broker-reload-disabled.xml b/artemis-cli/src/test/resources/broker-reload-disabled.xml new file mode 100644 index 0000000000..93b1542dbf --- /dev/null +++ b/artemis-cli/src/test/resources/broker-reload-disabled.xml @@ -0,0 +1,61 @@ + + + + + + + + + + ./target/paging + + ./target/bindings + + ./target/journal + + 2 + + ./target/large-messages + + -1 + + + tcp://${activemq.remoting.default.host:localhost}:${activemq.remoting.default.port:61616} + + + + + + + + + + + + DLQ + ExpiryQueue + 0 + 10Mb + 10 + BLOCK + + + + 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 5e8bffbc9a..c5fd448935 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 @@ -413,7 +413,7 @@ public final class FileConfigurationParser extends XMLConfigurationUtil { config.setConnectionTtlCheckInterval(getLong(e, "connection-ttl-check-interval", config.getConnectionTtlCheckInterval(), Validators.GT_ZERO)); - config.setConfigurationFileRefreshPeriod(getLong(e, "configuration-file-refresh-period", config.getConfigurationFileRefreshPeriod(), Validators.GT_ZERO)); + config.setConfigurationFileRefreshPeriod(getLong(e, "configuration-file-refresh-period", config.getConfigurationFileRefreshPeriod(), Validators.MINUS_ONE_OR_GT_ZERO)); config.setTemporaryQueueNamespace(getString(e, "temporary-queue-namespace", config.getTemporaryQueueNamespace(), Validators.NOT_NULL_OR_EMPTY)); 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 282de99545..306b1955d1 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 @@ -3122,18 +3122,21 @@ public class ActiveMQServerImpl implements ActiveMQServer { deployGroupingHandlerConfiguration(configuration.getGroupingHandlerConfiguration()); - this.reloadManager = new ReloadManagerImpl(getScheduledPool(), executorFactory.getExecutor(), configuration.getConfigurationFileRefreshPeriod()); + long configurationFileRefreshPeriod = configuration.getConfigurationFileRefreshPeriod(); + if (configurationFileRefreshPeriod > 0) { + this.reloadManager = new ReloadManagerImpl(getScheduledPool(), executorFactory.getExecutor(), configurationFileRefreshPeriod); - if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) { - reloadManager.addCallback(configuration.getConfigurationUrl(), uri -> reloadConfigurationFile(uri)); - } + if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) { + reloadManager.addCallback(configuration.getConfigurationUrl(), uri -> reloadConfigurationFile(uri)); + } - if (System.getProperty("logging.configuration") != null) { - try { - reloadManager.addCallback(new URL(System.getProperty("logging.configuration")), new LoggingConfigurationFileReloader()); - } catch (Exception e) { - // a syntax error with the logging system property shouldn't prevent the server from starting - ActiveMQServerLogger.LOGGER.problemAddingConfigReloadCallback(System.getProperty("logging.configuration"), e); + if (System.getProperty("logging.configuration") != null) { + try { + reloadManager.addCallback(new URL(System.getProperty("logging.configuration")), new LoggingConfigurationFileReloader()); + } catch (Exception e) { + // a syntax error with the logging system property shouldn't prevent the server from starting + ActiveMQServerLogger.LOGGER.problemAddingConfigReloadCallback(System.getProperty("logging.configuration"), e); + } } } diff --git a/docs/user-manual/en/config-reload.md b/docs/user-manual/en/config-reload.md index b07c203816..424c83949d 100644 --- a/docs/user-manual/en/config-reload.md +++ b/docs/user-manual/en/config-reload.md @@ -1,8 +1,8 @@ # Configuration Reload The system will perform a periodic check on the configuration files, configured -by `configuration-file-refresh-period`, with the default at 5000, in -milliseconds. +by `configuration-file-refresh-period`, with the default at `5000`, in +milliseconds. These checks can be disabled by specifying `-1`. Once the configuration file is changed (broker.xml) the following modules will be reloaded automatically: