Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -31,4 +34,32 @@ public ConfigurationProcessor findProcessor(Object o) {
}
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
}));
}
}
Original file line number Diff line number Diff line change
@@ -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>