ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1629681 - in /ace/trunk/org.apache.ace.agent: src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
Date Mon, 06 Oct 2014 15:37:24 GMT
Author: marrs
Date: Mon Oct  6 15:37:24 2014
New Revision: 1629681

URL: http://svn.apache.org/r1629681
Log:
ACE-475 ACE-479 Fixed the problem with the discovery code not picking up settings from the
launcher.

Modified:
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
    ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java?rev=1629681&r1=1629680&r2=1629681&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
(original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
Mon Oct  6 15:37:24 2014
@@ -46,17 +46,13 @@ public class ConfigurationHandlerImpl ex
     public static final String CONFIG_STORAGE_SUBDIR = "config";
     /** File name use for storage. */
     public static final String CONFIG_STORAGE_FILENAME = "config.properties";
-
     private final BundleContext m_context;
-
     private ResettableTimer m_timer;
     private volatile ConcurrentMap<Object, Object> m_configProps;
 
     public ConfigurationHandlerImpl(BundleContext context) {
         super("configuration");
-
         m_context = context;
-
         m_configProps = new ConcurrentHashMap<Object, Object>();
     }
 
@@ -180,7 +176,7 @@ public class ConfigurationHandlerImpl ex
     private File getConfigDir() throws IOException {
         File dir = new File(getAgentContext().getWorkDir(), CONFIG_STORAGE_SUBDIR);
         if (!dir.exists() && !dir.mkdir()) {
-            throw new IOException("Unable to acces configuration directory: " + dir.getAbsolutePath());
+            throw new IOException("Unable to access configuration directory: " + dir.getAbsolutePath());
         }
         return dir;
     }
@@ -188,7 +184,7 @@ public class ConfigurationHandlerImpl ex
     private File getConfigFile() throws IOException {
         File file = new File(getConfigDir(), CONFIG_STORAGE_FILENAME);
         if (!file.exists() && !file.createNewFile()) {
-            throw new IOException("Unable to acces configuration file: " + file.getAbsolutePath());
+            throw new IOException("Unable to access configuration file: " + file.getAbsolutePath());
         }
         return file;
     }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java?rev=1629681&r1=1629680&r2=1629681&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
(original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
Mon Oct  6 15:37:24 2014
@@ -83,8 +83,8 @@ public class DiscoveryHandlerImpl extend
     private static final long DEFAULT_CACHE_MILLISECONDS = 30000;
     private final Map<String, CheckedURL> m_checkedURLs = new HashMap<String, CheckedURL>();
 
-    private final List<String> m_defaultServerURLs;
-    private final boolean m_defaultCheckURLs;
+    private List<String> m_defaultServerURLs;
+    private boolean m_defaultCheckURLs;
 
     private volatile List<String> m_serverURLs;
     private volatile boolean m_checkURLs;
@@ -99,13 +99,14 @@ public class DiscoveryHandlerImpl extend
 
     DiscoveryHandlerImpl(String[] serverURLs, boolean checkServerURLs) {
         super("discovery");
-
         m_defaultServerURLs = m_serverURLs = Arrays.asList(serverURLs);
         m_defaultCheckURLs = m_checkURLs = checkServerURLs;
     }
 
     @Override
     protected void onInit() throws Exception {
+        String urls = getConfigurationHandler().get(CONFIG_DISCOVERY_SERVERURLS, mergeUrls(m_defaultServerURLs));
+        m_defaultServerURLs = m_serverURLs = splitUrls(urls);
         getEventsHandler().addListener(this);
     }
 
@@ -124,8 +125,7 @@ public class DiscoveryHandlerImpl extend
         List<String> serverURLs;
         String urlsValue = payload.get(CONFIG_DISCOVERY_SERVERURLS);
         if (urlsValue != null && !"".equals(urlsValue.trim())) {
-            String[] urls = urlsValue.trim().split("\\s*,\\s*");
-            serverURLs = Arrays.asList(urls);
+            serverURLs = splitUrls(urlsValue);
         }
         else {
             serverURLs = m_defaultServerURLs;
@@ -146,12 +146,25 @@ public class DiscoveryHandlerImpl extend
         if (!oldServerURLs.equals(serverURLs) || oldCheckURLs != checkURLs) {
             m_serverURLs = serverURLs;
             m_checkURLs = checkURLs;
-
             logDebug("Discovery configuration changed: urls: %s, checking: %s", m_serverURLs,
m_checkURLs);
-            
             m_checkedURLs.clear();
         }
     }
+    
+    List<String> splitUrls(String urlsValue) {
+        return Arrays.asList(urlsValue.trim().split("\\s*,\\s*"));
+    }
+    
+    String mergeUrls(List<String> urls) {
+    	StringBuilder sb = new StringBuilder();
+    	for (String url : urls) {
+    		if (sb.length() > 0) {
+    			sb.append(',');
+    		}
+    		sb.append(url);
+    	}
+    	return sb.toString();
+    }
 
     /**
      * Returns the first available URL from a the ordered list of the configured server URLs.
If the
@@ -179,7 +192,6 @@ public class DiscoveryHandlerImpl extend
     }
 
     private URL getURL(String serverURL, boolean checkURL) {
-
         try {
             if (!checkURL) {
                 return new URL(serverURL);
@@ -202,7 +214,6 @@ public class DiscoveryHandlerImpl extend
                     }
                 }
             }
-
             try {
                 tryConnect(checkedURL.m_url);
                 logDebug("Succesfully connected to serverURL: %s", serverURL);

Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java?rev=1629681&r1=1629680&r2=1629681&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
(original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
Mon Oct  6 15:37:24 2014
@@ -22,6 +22,7 @@ import static org.testng.Assert.assertEq
 import static org.testng.Assert.assertNull;
 
 import java.net.URL;
+import java.util.List;
 
 import org.apache.ace.agent.AgentConstants;
 import org.apache.ace.agent.AgentContext;
@@ -156,4 +157,17 @@ public class DiscoveryHandlerImplTest ex
         DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class);
         assertNull(discoveryHandler.getServerUrl());
     }
+    
+    @Test
+    public void testSplitAndMergeUrls() throws Exception {
+        DiscoveryHandlerImpl discoveryHandler = (DiscoveryHandlerImpl) m_agentContext.getHandler(DiscoveryHandler.class);
+        String urlsValue = "http://a/,http://b/,http://c/";
+		List<String> urls = discoveryHandler.splitUrls(urlsValue);
+        assertEquals(urls.size(), 3);
+        assertEquals(urls.get(0), "http://a/");
+        assertEquals(urls.get(1), "http://b/");
+        assertEquals(urls.get(2), "http://c/");
+        String mergedUrls = discoveryHandler.mergeUrls(urls);
+        assertEquals(mergedUrls, urlsValue);
+    }
 }



Mime
View raw message