ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1586521 - in /ace/trunk/org.apache.ace.agent: src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
Date Fri, 11 Apr 2014 01:17:55 GMT
Author: jawi
Date: Fri Apr 11 01:17:55 2014
New Revision: 1586521

URL: http://svn.apache.org/r1586521
Log:
Slightly different approach for previous commit:

- ensure we can define the default server URL to use, and actually
  use this when reconfiguring the discovery handler;
- also make the discovery configuration update a little more smarter
  by not doing anything if nothing has changed from the defaults.


Modified:
    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/DiscoveryHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java?rev=1586521&r1=1586520&r2=1586521&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
Fri Apr 11 01:17:55 2014
@@ -27,7 +27,6 @@ import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -84,6 +83,9 @@ 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 volatile List<String> m_serverURLs;
     private volatile boolean m_checkURLs;
 
@@ -98,8 +100,8 @@ public class DiscoveryHandlerImpl extend
     DiscoveryHandlerImpl(String[] serverURLs, boolean checkServerURLs) {
         super("discovery");
 
-        m_serverURLs = Arrays.asList(serverURLs);
-        m_checkURLs = checkServerURLs;
+        m_defaultServerURLs = m_serverURLs = Arrays.asList(serverURLs);
+        m_defaultCheckURLs = m_checkURLs = checkServerURLs;
     }
 
     @Override
@@ -119,22 +121,36 @@ public class DiscoveryHandlerImpl extend
             return;
         }
 
-        List<String> serverURLs = new ArrayList<String>();
+        List<String> serverURLs;
         String urlsValue = payload.get(CONFIG_DISCOVERY_SERVERURLS);
-        if (urlsValue == null || "".equals(urlsValue.trim())) {
-            serverURLs.addAll(Arrays.asList(DEFAULT_SERVER_URL));
+        if (urlsValue != null && !"".equals(urlsValue.trim())) {
+            String[] urls = urlsValue.trim().split("\\s*,\\s*");
+            serverURLs = Arrays.asList(urls);
         }
         else {
-            String[] urls = urlsValue.trim().split("\\s*,\\s*");
-            serverURLs.addAll(Arrays.asList(urls));
+            serverURLs = m_defaultServerURLs;
         }
-        m_serverURLs = serverURLs;
 
         String checkingValue = payload.get(CONFIG_DISCOVERY_CHECKING);
-        m_checkURLs = Boolean.parseBoolean(checkingValue);
+        boolean checkURLs;
+        if (checkingValue != null && !"".equals(checkingValue.trim())) {
+            checkURLs = Boolean.parseBoolean(checkingValue);
+        }
+        else {
+            checkURLs = m_defaultCheckURLs;
+        }
 
-        logDebug("Config changed: urls: %s, checking: %s", urlsValue, checkingValue);
-        m_checkedURLs.clear();
+        List<String> oldServerURLs = m_serverURLs;
+        boolean oldCheckURLs = m_checkURLs;
+
+        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();
+        }
     }
 
     /**

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=1586521&r1=1586520&r2=1586521&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
Fri Apr 11 01:17:55 2014
@@ -31,7 +31,6 @@ import org.apache.ace.agent.DiscoveryHan
 import org.apache.ace.agent.EventsHandler;
 import org.apache.ace.agent.testutil.BaseAgentTest;
 import org.apache.ace.agent.testutil.TestWebServer;
-import org.apache.ace.test.constants.TestConstants;
 import org.osgi.framework.BundleContext;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
@@ -63,7 +62,7 @@ public class DiscoveryHandlerImplTest ex
         m_agentContextImpl = mockAgentContext();
         m_agentContext = m_agentContextImpl;
         // Make sure the default server URL is not reachable, as used for this test...
-        m_agentContextImpl.setHandler(DiscoveryHandler.class, new DiscoveryHandlerImpl("http://localhost:"
+ TestConstants.PORT, true));
+        m_agentContextImpl.setHandler(DiscoveryHandler.class, new DiscoveryHandlerImpl("http://localhost:9999",
true));
         m_agentContextImpl.setHandler(EventsHandler.class, new EventsHandlerImpl(bc));
         m_agentContextImpl.setHandler(ConfigurationHandler.class, new ConfigurationHandlerImpl(bc));
         m_agentContextImpl.setHandler(ConnectionHandler.class, new ConnectionHandlerImpl());



Mime
View raw message