use of com.netflix.config.DynamicStringProperty in project archaius by Netflix.
the class BlobStoreBackedConfigurationTest method testPropertyChange.
@Test
public void testPropertyChange() throws Exception {
BlobStoreConfigurationSource source = new BlobStoreConfigurationSource(ctx);
FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 1000, false);
DynamicConfiguration dynamicConfig = new DynamicConfiguration(source, scheduler);
ConfigurationManager.loadPropertiesFromConfiguration(dynamicConfig);
DynamicStringProperty test1 = DynamicPropertyFactory.getInstance().getStringProperty("test1", "");
DynamicStringProperty test2 = DynamicPropertyFactory.getInstance().getStringProperty("test2", "");
DynamicStringProperty test3 = DynamicPropertyFactory.getInstance().getStringProperty("test3", "");
assertEquals("val1", test1.get());
assertEquals("val2", test2.get());
assertEquals("val3", test3.get());
update();
Thread.sleep(1250);
assertEquals("vala", test1.get());
assertEquals("valb", test2.get());
assertEquals("valc", test3.get());
}
use of com.netflix.config.DynamicStringProperty in project archaius by Netflix.
the class JDBCConfigurationSourceTest method testSimpleInMemoryJDBCDynamicPropertySource.
@Test
public void testSimpleInMemoryJDBCDynamicPropertySource() throws Throwable {
final String dbName = "MySiteConfiguration";
DataSource ds = createDataConfigSource(dbName);
try {
JDBCConfigurationSource source = new JDBCConfigurationSource(ds, "select distinct property_key, property_value from MySiteProperties", "property_key", "property_value");
FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, false);
DynamicConfiguration configuration = new DynamicConfiguration(source, scheduler);
DynamicPropertyFactory.initWithConfigurationSource(configuration);
DynamicStringProperty defaultProp = DynamicPropertyFactory.getInstance().getStringProperty("this.prop.does.not.exist.use.default", "default");
assertEquals("default", defaultProp.get());
DynamicStringProperty prop1 = DynamicPropertyFactory.getInstance().getStringProperty("prop1", "default");
assertEquals("value1", prop1.get());
} finally {
//Clean up the data files generated by the embedded DB.
FileUtils.deleteDirectory(new File(".", dbName));
}
}
use of com.netflix.config.DynamicStringProperty in project eureka by Netflix.
the class DefaultEurekaServerConfig method getRemoteRegionAppWhitelist.
@Nullable
@Override
public Set<String> getRemoteRegionAppWhitelist(@Nullable String regionName) {
if (null == regionName) {
regionName = "global";
} else {
regionName = regionName.trim().toLowerCase();
}
DynamicStringProperty appWhiteListProp = configInstance.getStringProperty(namespace + "remoteRegion." + regionName + ".appWhiteList", null);
if (null == appWhiteListProp || null == appWhiteListProp.get()) {
return null;
} else {
String appWhiteListStr = appWhiteListProp.get();
String[] whitelistEntries = appWhiteListStr.split(",");
return new HashSet<String>(Arrays.asList(whitelistEntries));
}
}
use of com.netflix.config.DynamicStringProperty in project ribbon by Netflix.
the class DefaultClientConfigImpl method getProperty.
protected Object getProperty(String key) {
if (enableDynamicProperties) {
String dynamicValue = null;
DynamicStringProperty dynamicProperty = dynamicProperties.get(key);
if (dynamicProperty != null) {
dynamicValue = dynamicProperty.get();
}
if (dynamicValue == null) {
dynamicValue = DynamicProperty.getInstance(getConfigKey(key)).getString();
if (dynamicValue == null) {
dynamicValue = DynamicProperty.getInstance(getDefaultPropName(key)).getString();
}
}
if (dynamicValue != null) {
return dynamicValue;
}
}
return properties.get(key);
}
use of com.netflix.config.DynamicStringProperty in project ribbon by Netflix.
the class DefaultClientConfigImpl method setPropertyInternal.
protected void setPropertyInternal(final String propName, Object value) {
String stringValue = (value == null) ? "" : String.valueOf(value);
properties.put(propName, stringValue);
if (!enableDynamicProperties) {
return;
}
String configKey = getConfigKey(propName);
final DynamicStringProperty prop = DynamicPropertyFactory.getInstance().getStringProperty(configKey, null);
Runnable callback = new Runnable() {
@Override
public void run() {
String value = prop.get();
if (value != null) {
properties.put(propName, value);
} else {
properties.remove(propName);
}
}
// equals and hashcode needed
// since this is anonymous object is later used as a set key
@Override
public boolean equals(Object other) {
if (other == null) {
return false;
}
if (getClass() == other.getClass()) {
return toString().equals(other.toString());
}
return false;
}
@Override
public String toString() {
return propName;
}
@Override
public int hashCode() {
return propName.hashCode();
}
};
prop.addCallback(callback);
dynamicProperties.put(propName, prop);
}
Aggregations