This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch activemq-6.1.x
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/activemq-6.1.x by this push:
     new 22f49842ec [AMQ-9738] Remove requirement for network connector order 
in runtime configuration (#1466)
22f49842ec is described below

commit 22f49842ec630f25e4121f4bfa2a1bfcadf2ccae
Author: Tyler Harms <[email protected]>
AuthorDate: Tue Nov 4 08:02:12 2025 -0600

    [AMQ-9738] Remove requirement for network connector order in runtime 
configuration (#1466)
    
    * Override network connector modifications functionality
    
    * Add a new test instead of modifying the original
    
    ---------
    
    Co-authored-by: Tyler harms <[email protected]>
---
 .../plugin/NetworkConnectorsProcessor.java         | 31 ++++++++++++++++++++
 .../org/apache/activemq/NetworkConnectorTest.java  | 29 ++++++++++++++++--
 .../activemq/networkConnectorTest-two-b-nc.xml     | 34 ++++++++++++++++++++++
 3 files changed, 92 insertions(+), 2 deletions(-)

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 ed429b4c7d..fffc11feaa 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 @@ package org.apache.activemq.plugin;
 
 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 class NetworkConnectorsProcessor extends 
DefaultConfigurationProcessor {
         }
         return super.findProcessor(o);
     }
+
+    @Override
+    protected void applyModifications(List<Object> current, List<Object> 
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 822d5cf95d..0bdf17c04e 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 class NetworkConnectorTest extends 
RuntimeConfigTestSupport {
         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 class NetworkConnectorTest extends 
RuntimeConfigTestSupport {
         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 0000000000..1994b227e4
--- /dev/null
+++ 
b/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-b-nc.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans
+        xmlns="http://www.springframework.org/schema/beans";
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+        xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+  http://activemq.apache.org/schema/core 
http://activemq.apache.org/schema/core/activemq-core.xsd";>
+
+  <broker xmlns="http://activemq.apache.org/schema/core"; start="false" 
persistent="false" >
+    <plugins>
+      <runtimeConfigurationPlugin checkPeriod="1000" />
+    </plugins>
+
+    <networkConnectors>
+      <networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" 
name="two"/>
+      <networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" 
name="one"/>
+    </networkConnectors>
+  </broker>
+</beans>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to