Author: bramk
Date: Thu Aug 22 09:32:08 2013
New Revision: 1516396
URL: http://svn.apache.org/r1516396
Log:
ACE-347 Flipped system property override default
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java?rev=1516396&r1=1516395&r2=1516396&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
(original)
+++
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
Thu Aug 22 09:32:08 2013
@@ -22,17 +22,15 @@ import java.util.Set;
/**
* Agent control delegate interface that is responsible for managing persisted
configuration. External launchers may
- * override or set values within the {@link CONFIG_KEY_NAMESPACE} through
system properties when the agent starts.
- * However, once a configuration value has been set the corresponding system
property will be ignored unless the
- * override flag is set. This ensures a simple system restart will not
override configuration set by runtime
- * controllers. <br/>
+ * override or set values within the {@link CONFIG_KEY_NAMESPACE} through
system properties when the agent starts. If
+ * the launcher wants to retain existing persisted values, instead of
overwriting them, it should specify an additional
+ * property with the same name post-fixed with {@link CONFIG_KEY_RETAIN} set
to <code>true</code>. <br/>
* <br/>
- * Example: A launcher that wants to ensure the syncinterval is set to 3000
should specify the following two system
- * properties:<br/>
+ * Example: A launcher that wants to ensure the syncinterval is set to 3000
only when not configuration is already set
+ * should specify the following two system properties:<br/>
* <code>agent.controller.syncinterval=3000</code><br/>
- * <code>agent.controller.syncinterval.override=true</code>
+ * <code>agent.controller.syncinterval.retain=true</code>
*/
-// TODO Configuration by launcher will probably be the primary use case.
Should we flip the override default?
public interface ConfigurationHandler {
/**
@@ -41,9 +39,9 @@ public interface ConfigurationHandler {
String CONFIG_KEY_NAMESPACE = "ace.agent";
/**
- * Override postfix; The postfix for override property keys.
+ * Retain postfix; The postfix for override property keys.
*/
- String CONFIG_KEY_OVERRIDEPOSTFIX = ".override";
+ String CONFIG_KEY_RETAIN = ".retain";
/**
* Return an unmodifiable copy of the configuration keys.
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=1516396&r1=1516395&r2=1516396&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
Thu Aug 22 09:32:08 2013
@@ -142,9 +142,9 @@ public class ConfigurationHandlerImpl ex
ensureLoadConfig();
for (Entry<Object, Object> entry : System.getProperties().entrySet()) {
String key = (String) entry.getKey();
- if (key.startsWith(CONFIG_KEY_NAMESPACE) &&
!key.endsWith(CONFIG_KEY_OVERRIDEPOSTFIX)) {
- if (!m_configProps.containsKey(key)
- ||
Boolean.parseBoolean(System.getProperties().getProperty(key +
CONFIG_KEY_OVERRIDEPOSTFIX))) {
+ if (key.startsWith(CONFIG_KEY_NAMESPACE) &&
!key.endsWith(CONFIG_KEY_RETAIN)) {
+ boolean retain =
Boolean.parseBoolean(System.getProperties().getProperty(key +
CONFIG_KEY_RETAIN));
+ if (!retain || !m_configProps.containsKey(key)) {
m_configProps.put(entry.getKey(), entry.getValue());
}
}
Modified:
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java?rev=1516396&r1=1516395&r2=1516396&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
(original)
+++
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
Thu Aug 22 09:32:08 2013
@@ -92,7 +92,7 @@ public class ConfigurationHandlerImplTes
assertEquals(configurationHandler.get(systemKey1, "qqq"), "value1");
assertEquals(configurationHandler.get(systemKey2, "qqq"), "value2");
- // should be persisted
+ // System props should be persisted
System.clearProperty(systemKey1);
System.clearProperty(systemKey2);
@@ -105,7 +105,7 @@ public class ConfigurationHandlerImplTes
assertEquals(configurationHandler.get(systemKey1, "qqq"), "value1");
assertEquals(configurationHandler.get(systemKey2, "qqq"), "value2");
- // should not overwrite by default
+ // System props should override by default
System.setProperty(systemKey1, "value1");
System.setProperty(systemKey2, "value2");
@@ -118,15 +118,15 @@ public class ConfigurationHandlerImplTes
assertNotNull(configurationHandler.keySet());
assertEquals(2, configurationHandler.keySet().size());
- assertEquals(configurationHandler.get(systemKey1, "qqq"), "newvalue1");
- assertEquals(configurationHandler.get(systemKey2, "qqq"), "newvalue2");
+ assertEquals(configurationHandler.get(systemKey1, "qqq"), "value1");
+ assertEquals(configurationHandler.get(systemKey2, "qqq"), "value2");
- // should overwrite if flag is set
+ // System props should not override if retain is set
- System.setProperty(systemKey1, "value1");
- System.setProperty(systemKey2, "value2");
- System.setProperty(systemKey1 +
ConfigurationHandlerImpl.CONFIG_KEY_OVERRIDEPOSTFIX, "true");
- System.setProperty(systemKey2 +
ConfigurationHandlerImpl.CONFIG_KEY_OVERRIDEPOSTFIX, "true");
+ System.setProperty(systemKey1, "valueX");
+ System.setProperty(systemKey2, "valueY");
+ System.setProperty(systemKey1 +
ConfigurationHandlerImpl.CONFIG_KEY_RETAIN, "true");
+ System.setProperty(systemKey2 +
ConfigurationHandlerImpl.CONFIG_KEY_RETAIN, "true");
configurationHandler = new ConfigurationHandlerImpl();
startHandler(configurationHandler, m_agentContext);