diff --git a/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/NetworkConnectorsProcessor.java b/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/NetworkConnectorsProcessor.java index ed429b4c7d0..fffc11feaa5 100644 --- a/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/NetworkConnectorsProcessor.java +++ b/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/NetworkConnectorsProcessor.java @@ -18,6 +18,9 @@ import org.apache.activemq.schema.core.DtoNetworkConnector; +import java.util.ArrayList; +import java.util.List; + public class NetworkConnectorsProcessor extends DefaultConfigurationProcessor { public NetworkConnectorsProcessor(RuntimeConfigurationBroker plugin, Class configurationClass) { @@ -31,4 +34,32 @@ public ConfigurationProcessor findProcessor(Object o) { } return super.findProcessor(o); } + + @Override + protected void applyModifications(List current, List modification) { + // Remove items not in modification + for (Object currentObj : new ArrayList<>(current)) { + if (!modification.contains(currentObj)) { + ConfigurationProcessor processor = findProcessor(currentObj); + if (processor != null) { + processor.remove(currentObj); + } else { + remove(currentObj); + } + } + } + // Add new items from modification + for (Object modObj : modification) { + if (!current.contains(modObj)) { + ConfigurationProcessor processor = findProcessor(modObj); + if (processor != null) { + processor.addNew(modObj); + } else { + addNew(modObj); + } + } else { + plugin.debug("Skipping unchanged network connector: " + modObj); + } + } + } } diff --git a/activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java b/activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java index 822d5cf95d3..0bdf17c04ec 100644 --- a/activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java +++ b/activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java @@ -110,11 +110,17 @@ public void testRemove() throws Exception { assertTrue("broker alive", brokerService.isStarted()); assertEquals("correct network connectors", 2, brokerService.getNetworkConnectors().size()); - NetworkConnector two = brokerService.getNetworkConnectors().get(1); + NetworkConnector two = null; + for (NetworkConnector nc : brokerService.getNetworkConnectors()) { + if ("two".equals(nc.getName())) { + two = nc; + break; + } + } applyNewConfig(brokerConfig, configurationSeed + "-one-nc", SLEEP); - assertTrue("expected mod on time", Wait.waitFor(new Wait.Condition() { + assertTrue("expected mod on time, but found " + brokerService.getNetworkConnectors().size() + " connectors", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return 1 == brokerService.getNetworkConnectors().size(); @@ -135,4 +141,23 @@ public boolean isSatisified() throws Exception { assertNotNull(brokerService.getManagementContext().getObjectInstance( brokerService.createNetworkConnectorObjectName(remainingNetworkConnector))); } + + @Test + public void testUnchangedNetworkConnector() throws Exception { + final String brokerConfig = configurationSeed + "-two-nc-broker"; + applyNewConfig(brokerConfig, configurationSeed + "-two-nc"); + startBroker(brokerConfig); + assertTrue("broker alive", brokerService.isStarted()); + assertEquals("two network connectors", 2, brokerService.getNetworkConnectors().size()); + + // apply a config that changes the order only + applyNewConfig(brokerConfig, configurationSeed + "-two-b-nc", SLEEP); + + assertTrue("expected mod on time", Wait.waitFor(new Wait.Condition() { + @Override + public boolean isSatisified() throws Exception { + return 2 == brokerService.getNetworkConnectors().size(); + } + })); + } } diff --git a/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-b-nc.xml b/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-b-nc.xml new file mode 100644 index 00000000000..1994b227e4d --- /dev/null +++ b/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-b-nc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + +