activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1515461 - in /activemq/trunk: activemq-broker/src/main/java/org/apache/activemq/network/ activemq-client/src/main/java/org/apache/activemq/util/ activemq-runtime-config/src/main/java/org/apache/activemq/plugin/ activemq-runtime-config/src/...
Date Mon, 19 Aug 2013 15:18:56 GMT
Author: gtully
Date: Mon Aug 19 15:18:55 2013
New Revision: 1515461

URL: http://svn.apache.org/r1515461
Log:
https://issues.apache.org/jira/browse/AMQ-4682 - implement network connector modification,
match, stop, apply restart

Added:
    activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-nc.xml
      - copied, changed from r1514891, activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-mod-one-nc.xml
Modified:
    activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/network/DiscoveryNetworkConnector.java
    activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/TypeConversionSupport.java
    activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
    activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java
    activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-mod-one-nc.xml
    activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-one-nc.xml

Modified: activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/network/DiscoveryNetworkConnector.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/network/DiscoveryNetworkConnector.java?rev=1515461&r1=1515460&r2=1515461&view=diff
==============================================================================
--- activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/network/DiscoveryNetworkConnector.java
(original)
+++ activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/network/DiscoveryNetworkConnector.java
Mon Aug 19 15:18:55 2013
@@ -54,6 +54,7 @@ public class DiscoveryNetworkConnector e
     private DiscoveryAgent discoveryAgent;
     private Map<String, String> parameters;
     private final ConcurrentMap<URI, DiscoveryEvent> activeEvents = new ConcurrentHashMap<URI,
DiscoveryEvent>();
+    private URI discoveryUri;
     public DiscoveryNetworkConnector() {
     }
 
@@ -62,6 +63,7 @@ public class DiscoveryNetworkConnector e
     }
 
     public void setUri(URI discoveryURI) throws IOException {
+        this.discoveryUri = discoveryURI;
         setDiscoveryAgent(DiscoveryAgentFactory.createDiscoveryAgent(discoveryURI));
         try {
             parameters = URISupport.parseParameters(discoveryURI);
@@ -72,6 +74,10 @@ public class DiscoveryNetworkConnector e
         }
     }
 
+    public URI getUri() {
+        return discoveryUri;
+    }
+
     @Override
     public void onServiceAdd(DiscoveryEvent event) {
         // Ignore events once we start stopping.

Modified: activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/TypeConversionSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/TypeConversionSupport.java?rev=1515461&r1=1515460&r2=1515461&view=diff
==============================================================================
--- activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/TypeConversionSupport.java
(original)
+++ activemq/trunk/activemq-client/src/main/java/org/apache/activemq/util/TypeConversionSupport.java
Mon Aug 19 15:18:55 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.util;
 
+import java.math.BigInteger;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Date;
@@ -80,6 +81,8 @@ public final class TypeConversionSupport
         CONVERSION_MAP.put(new ConversionKey(Float.class, String.class), toStringConverter);
         CONVERSION_MAP.put(new ConversionKey(Double.class, String.class), toStringConverter);
         CONVERSION_MAP.put(new ConversionKey(UTF8Buffer.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(URI.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(BigInteger.class, String.class), toStringConverter);
 
         CONVERSION_MAP.put(new ConversionKey(String.class, Boolean.class), new Converter()
{
             @Override

Modified: activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java?rev=1515461&r1=1515460&r2=1515461&view=diff
==============================================================================
--- activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
(original)
+++ activemq/trunk/activemq-runtime-config/src/main/java/org/apache/activemq/plugin/RuntimeConfigurationBroker.java
Mon Aug 19 15:18:55 2013
@@ -17,10 +17,12 @@
 package org.apache.activemq.plugin;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
+import java.util.TreeMap;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
@@ -111,25 +113,87 @@ public class RuntimeConfigurationBroker 
     }
 
     private void processNetworkConnectors(Broker currentConfiguration, Broker modifiedConfiguration)
{
-        List<Broker.NetworkConnectors> currentNc = filterElement(
+        List<Broker.NetworkConnectors> currentNCsElems = filterElement(
                 currentConfiguration.getContents(), Broker.NetworkConnectors.class);
-        List<Broker.NetworkConnectors> modNc = filterElement(
+        List<Broker.NetworkConnectors> modifiedNCsElems = filterElement(
                 modifiedConfiguration.getContents(), Broker.NetworkConnectors.class);
 
         int modIndex = 0, currentIndex = 0;
-        for (; modIndex < modNc.size() && currentIndex < currentNc.size();
modIndex++, currentIndex++) {
-            if (!modNc.get(modIndex).getContents().get(0).equals(
-                    currentNc.get(currentIndex).getContents().get(0))) {
-                // change in order will fool this logic
-                LOG.error("not supported: mod to existing network Connector, new: "
-                        + modNc.get(modIndex).getContents().get(0));
+        for (; modIndex < modifiedNCsElems.size() && currentIndex < currentNCsElems.size();
modIndex++, currentIndex++) {
+            // walk the list of individual nc's...
+            applyModifications(currentNCsElems.get(currentIndex).getContents(),
+                    modifiedNCsElems.get(modIndex).getContents());
+        }
+
+        for (; modIndex < modifiedNCsElems.size(); modIndex++) {
+            // new networkConnectors element; add all
+            for (Object nc : modifiedNCsElems.get(modIndex).getContents()) {
+                addNetworkConnector(nc);
+            }
+        }
+
+        for (; currentIndex < currentNCsElems.size(); currentIndex++) {
+            // removal of networkConnectors element; remove all
+            for (Object nc : modifiedNCsElems.get(modIndex).getContents()) {
+                removeNetworkConnector(nc);
+            }
+        }
+    }
+
+    private void applyModifications(List<Object> current, List<Object> modification)
{
+        int modIndex = 0, currentIndex = 0;
+        for (; modIndex < modification.size() && currentIndex < current.size();
modIndex++, currentIndex++) {
+            Object currentNc = current.get(currentIndex);
+            Object candidateNc = modification.get(modIndex);
+            if (! currentNc.equals(candidateNc)) {
+                LOG.info("modification to:" + currentNc + " , with: " + candidateNc);
+                removeNetworkConnector(currentNc);
+                addNetworkConnector(candidateNc);
             }
         }
 
-        for (; modIndex < modNc.size(); modIndex++) {
-            // additions
-            addNetworkConnector(modNc.get(modIndex).getContents().get(0));
+        for (; modIndex < modification.size(); modIndex++) {
+            addNetworkConnector(modification.get(modIndex));
+        }
+
+        for (; currentIndex < current.size(); currentIndex++) {
+            removeNetworkConnector(current.get(currentIndex));
+        }
+    }
+
+    private void removeNetworkConnector(Object o) {
+        if (o instanceof NetworkConnector) {
+            NetworkConnector toRemove = (NetworkConnector) o;
+            for (org.apache.activemq.network.NetworkConnector existingCandidate :
+                    getBrokerService().getNetworkConnectors()) {
+                if (configMatch(toRemove, existingCandidate)) {
+                    if (getBrokerService().removeNetworkConnector(existingCandidate)) {
+                        try {
+                            existingCandidate.stop();
+                            LOG.info("stopped and removed networkConnector: " + existingCandidate);
+                        } catch (Exception e) {
+                            LOG.error("Failed to stop removed network connector: " + existingCandidate);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private boolean configMatch(NetworkConnector dto, org.apache.activemq.network.NetworkConnector
candidate) {
+        TreeMap<String, String> dtoProps = new TreeMap<String, String>();
+        IntrospectionSupport.getProperties(dto, dtoProps, null);
+
+        TreeMap<String, String> candidateProps = new TreeMap<String, String>();
+        IntrospectionSupport.getProperties(candidate, candidateProps, null);
+
+        // every dto prop must be present in the candidate
+        for (String key : dtoProps.keySet()) {
+            if (!candidateProps.containsKey(key) || !candidateProps.get(key).equals(dtoProps.get(key)))
{
+                return false;
+            }
         }
+        return true;
     }
 
     private void addNetworkConnector(Object o) {

Modified: activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java?rev=1515461&r1=1515460&r2=1515461&view=diff
==============================================================================
--- activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java
(original)
+++ activemq/trunk/activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java
Mon Aug 19 15:18:55 2013
@@ -74,9 +74,9 @@ public class NetworkConnectorTest {
     }
 
 
-    @Ignore("not implemented yet!")
     @Test
     public void testModConnector() throws Exception {
+
         final String brokerConfig = configurationSeed + "-one-nc-broker";
         applyNewConfig(brokerConfig, configurationSeed + "-one-nc");
         startBroker(brokerConfig);
@@ -100,6 +100,23 @@ public class NetworkConnectorTest {
         assertEquals("same instance", modNetworkConnector, brokerService.getNetworkConnectors().get(0));
     }
 
+    @Test
+    public void testRemoveConnector() throws Exception {
+
+        final String brokerConfig = configurationSeed + "-two-nc-broker";
+        applyNewConfig(brokerConfig, configurationSeed + "-two-nc");
+        startBroker(brokerConfig);
+        assertTrue("broker alive", brokerService.isStarted());
+        assertEquals("correct network connectors", 2, brokerService.getNetworkConnectors().size());
+
+        applyNewConfig(brokerConfig, configurationSeed + "-one-nc", SLEEP);
+
+        assertEquals("one network connectors", 1, brokerService.getNetworkConnectors().size());
+
+        NetworkConnector remainingNetworkConnector = brokerService.getNetworkConnectors().get(0);
+        assertEquals("name match", "one", remainingNetworkConnector.getName());
+    }
+
     private void applyNewConfig(String configName, String newConfigName) throws Exception
{
         applyNewConfig(configName, newConfigName, 0l);
     }
@@ -107,7 +124,7 @@ public class NetworkConnectorTest {
     private void applyNewConfig(String configName, String newConfigName, long sleep) throws
Exception {
         Resource resource = Utils.resourceFromString("org/apache/activemq");
         FileOutputStream current = new FileOutputStream(new File(resource.getFile(), configName
+ ".xml"));
-        FileInputStream modifications = new FileInputStream(new File(resource.getFile(),
(newConfigName != null ? newConfigName : configName) + ".xml"));
+        FileInputStream modifications = new FileInputStream(new File(resource.getFile(),
newConfigName + ".xml"));
         modifications.getChannel().transferTo(0, Long.MAX_VALUE, current.getChannel());
         current.flush();
         LOG.info("Updated: " + current.getChannel());

Modified: activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-mod-one-nc.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-mod-one-nc.xml?rev=1515461&r1=1515460&r2=1515461&view=diff
==============================================================================
--- activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-mod-one-nc.xml
(original)
+++ activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-mod-one-nc.xml
Mon Aug 19 15:18:55 2013
@@ -28,7 +28,7 @@
     </plugins>
 
     <networkConnectors>
-      <networkConnector uri="static:(tcp://localhost:5555)" networkTTL="2" />
+      <networkConnector uri="static:(tcp://localhost:5555)" networkTTL="2" name="one"
/>
     </networkConnectors>
   </broker>
 </beans>

Modified: activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-one-nc.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-one-nc.xml?rev=1515461&r1=1515460&r2=1515461&view=diff
==============================================================================
--- activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-one-nc.xml
(original)
+++ activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-one-nc.xml
Mon Aug 19 15:18:55 2013
@@ -28,7 +28,7 @@
     </plugins>
 
     <networkConnectors>
-      <networkConnector uri="static:(tcp://localhost:5555)"/>
+      <networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" name="one"
/>
     </networkConnectors>
   </broker>
 </beans>

Copied: activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-nc.xml
(from r1514891, activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-mod-one-nc.xml)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-nc.xml?p2=activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-nc.xml&p1=activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-mod-one-nc.xml&r1=1514891&r2=1515461&rev=1515461&view=diff
==============================================================================
--- activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-mod-one-nc.xml
(original)
+++ activemq/trunk/activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-nc.xml
Mon Aug 19 15:18:55 2013
@@ -28,7 +28,8 @@
     </plugins>
 
     <networkConnectors>
-      <networkConnector uri="static:(tcp://localhost:5555)" networkTTL="2" />
+      <networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" name="one"/>
+      <networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" name="two"/>
     </networkConnectors>
   </broker>
 </beans>



Mime
View raw message