Search in sources :

Example 1 with DynamicStringProperty

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());
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) DynamicStringProperty(com.netflix.config.DynamicStringProperty) FixedDelayPollingScheduler(com.netflix.config.FixedDelayPollingScheduler) Test(org.junit.Test)

Example 2 with DynamicStringProperty

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));
    }
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) DynamicStringProperty(com.netflix.config.DynamicStringProperty) FixedDelayPollingScheduler(com.netflix.config.FixedDelayPollingScheduler) File(java.io.File) JDBCConfigurationSource(com.netflix.config.sources.JDBCConfigurationSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 3 with DynamicStringProperty

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));
    }
}
Also used : DynamicStringProperty(com.netflix.config.DynamicStringProperty) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Example 4 with DynamicStringProperty

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);
}
Also used : DynamicStringProperty(com.netflix.config.DynamicStringProperty)

Example 5 with DynamicStringProperty

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);
}
Also used : DynamicStringProperty(com.netflix.config.DynamicStringProperty)

Aggregations

DynamicStringProperty (com.netflix.config.DynamicStringProperty)10 Test (org.junit.Test)3 DynamicConfiguration (com.netflix.config.DynamicConfiguration)2 FixedDelayPollingScheduler (com.netflix.config.FixedDelayPollingScheduler)2 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 DynamicPropertyFactory (com.netflix.config.DynamicPropertyFactory)1 JDBCConfigurationSource (com.netflix.config.sources.JDBCConfigurationSource)1 ValidationException (com.netflix.config.validation.ValidationException)1 IpPort (io.servicecomb.foundation.common.net.IpPort)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Nullable (javax.annotation.Nullable)1 DataSource (javax.sql.DataSource)1