Example usage for org.apache.commons.configuration Configuration setProperty

List of usage examples for org.apache.commons.configuration Configuration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration setProperty.

Prototype

void setProperty(String key, Object value);

Source Link

Document

Set a property, this will replace any previously set values.

Usage

From source file:org.janusgraph.olap.ShortestDistanceVertexProgram.java

@Override
public void storeState(final Configuration configuration) {
    configuration.setProperty(VERTEX_PROGRAM, ShortestDistanceVertexProgram.class.getName());
    configuration.setProperty(MAX_DEPTH, maxDepth);
}

From source file:org.jgrades.logging.dao.LoggingConfigurationDaoFileImpl.java

@Override
public void setConfiguration(LoggingConfiguration configuration) {
    try {/*w w w.j av a 2 s.c  o m*/
        Configuration externalConfig = externalConfiguration();
        externalConfig.setProperty(STRATEGY_PROPERTY_NAME, configuration.getLoggingStrategy().toString());
        externalConfig.setProperty(LEVEL_PROPERTY_NAME, configuration.getLevel());
        externalConfig.setProperty(MAX_FILE_SIZE_PROPERTY_NAME, configuration.getMaxFileSize());
        externalConfig.setProperty(MAX_DAYS_PROPERTY_NAME, configuration.getMaxDays());

        ((Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))
                .setLevel(Level.toLevel(configuration.getLevel().toString()));
    } catch (ConfigurationException e) {
        LOGGER.error("Problem with seetting new configuration to external logger config file", e);
        return;
    }
}

From source file:org.lable.oss.dynamicconfig.core.commonsconfiguration.ConcurrentConfigurationTest.java

@Test(expected = UnsupportedOperationException.class)
public void setPropertyTest() {
    CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class);
    Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null);
    concurrentConfiguration.setProperty("test", "test");
}

From source file:org.lable.oss.dynamicconfig.core.ConfigurationInitializer.java

static Configuration gatherPropertiesFor(ConfigurationSource desiredSource) {
    Configuration configuration = new BaseConfiguration();

    for (String propertyName : desiredSource.systemProperties()) {
        String value = System.getProperty(LIBRARY_PREFIX + "." + desiredSource.name() + "." + propertyName);
        if (value != null && !value.equals("")) {
            configuration.setProperty(propertyName, value);
        }/*from  w  w  w .ja  v a 2 s  .c o m*/
    }

    // 'appname' can be (and usually is) set locally. It can be overridden by a system property for development
    // and testing purposes.
    if (InstanceLocalSettings.INSTANCE.getAppName() != null) {
        configuration.setProperty(APPNAME_PROPERTY, InstanceLocalSettings.INSTANCE.getAppName());
    }

    for (String propertyName : COMMON_PROPERTIES) {
        String value = System.getProperty(LIBRARY_PREFIX + "." + propertyName);
        if (value != null && !value.equals("")) {
            configuration.setProperty(propertyName, value);
        }
    }

    return configuration;
}

From source file:org.lable.oss.dynamicconfig.PrecomputedTest.java

@Test
public void basicTest() {
    Configuration configuration = new BaseConfiguration();
    configuration.setProperty("a", "XXX");
    configuration.setProperty("b", "YYY");
    configuration.setProperty("c", 1);
    Precomputed<String> precomputed = Precomputed.monitorByKeys(configuration,
            config -> config.getString("a") + "--" + config.getString("b") + "--" + config.getInt("c", 0), "a",
            "b");

    assertThat(precomputed.get(), is("XXX--YYY--1"));

    // Not a monitored value, so no update.
    configuration.setProperty("c", 2);
    assertThat(precomputed.get(), is("XXX--YYY--1"));

    // Monitored value; update.
    configuration.setProperty("a", "ZZZ");
    assertThat(precomputed.get(), is("ZZZ--YYY--2"));

    // Monitored value; update.
    configuration.setProperty("b", "XXX");
    assertThat(precomputed.get(), is("ZZZ--XXX--2"));
}

From source file:org.lable.oss.dynamicconfig.PrecomputedTest.java

@Test
public void timestampTest() {
    Configuration configuration = new BaseConfiguration();
    configuration.setProperty("a", "AAA");
    configuration.setProperty(ConcurrentConfiguration.MODIFICATION_TIMESTAMP, System.nanoTime());
    Precomputed<String> precomputed = Precomputed.monitorByUpdate(configuration,
            config -> config.getString("a"));

    assertThat(precomputed.get(), is("AAA"));

    // Not a monitored value, so no update.
    configuration.setProperty("a", "BBB");
    assertThat(precomputed.get(), is("AAA"));

    // Touch the timestamp so an update will be required.
    configuration.setProperty(ConcurrentConfiguration.MODIFICATION_TIMESTAMP, System.nanoTime());
    assertThat(precomputed.get(), is("BBB"));
}

From source file:org.lable.oss.dynamicconfig.PrecomputedTest.java

@Test
public void nullTest() {
    Configuration configuration = new BaseConfiguration();
    Precomputed<String> precomputed = Precomputed.monitorByKeys(configuration,
            config -> String.valueOf(config.getString("a")) + "-" + String.valueOf(config.getString("b")), "a",
            "b");

    assertThat(precomputed.get(), is("null-null"));

    configuration.setProperty("a", "XXX");
    configuration.setProperty("b", "YYY");
    assertThat(precomputed.get(), is("XXX-YYY"));

    configuration.setProperty("a", null);
    assertThat(precomputed.get(), is("null-YYY"));

    //configuration.setProperty("a", "AAA");
    configuration.setProperty("b", null);
    assertThat(precomputed.get(), is("null-null"));

    configuration.setProperty("b", "XXX");
    assertThat(precomputed.get(), is("null-XXX"));
}

From source file:org.lable.oss.dynamicconfig.provider.FileBasedConfigSourceIT.java

@Test
public void testLoad() throws URISyntaxException, InterruptedException, IOException, ConfigurationException {
    final String INPUT = "test.yml";
    URL testUrl = getClass().getResource("/" + INPUT);
    final String testYaml = testUrl.toURI().getPath();
    FileBasedConfigSource source = new FileBasedConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("path", testYaml);
    source.configure(config);/*from ww  w  .j av a  2  s. c o m*/

    HierarchicalConfigurationDeserializer deserializer = new YamlDeserializer();

    final CountDownLatch latch = new CountDownLatch(1);
    Catcher catcher = new Catcher(latch);
    source.load(deserializer, catcher);
    boolean notTimedOut = latch.await(2, TimeUnit.SECONDS);

    assertThat("Expected callback wasn't called within a reasonable time.", notTimedOut, is(true));
    assertThat(source.config.getName(), is(INPUT));
    assertThat(catcher.caughtConfig.getString("type.unicodeString"), is(""));
}

From source file:org.lable.oss.dynamicconfig.provider.FileBasedConfigSourceIT.java

@Ignore
@Test//  w w w .j  a  va 2 s  .  c o m
public void testListen() throws URISyntaxException, InterruptedException, IOException, ConfigurationException {
    final String VALUE_A = "key: AAA\n";
    final String VALUE_B = "key: BBB\n";
    final String VALUE_C = "key: CCC\n";

    File configFile = File.createTempFile("configuration", ".yml");
    Files.write(configFile.toPath(), VALUE_A.getBytes());

    FileBasedConfigSource source = new FileBasedConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("path", configFile.getPath());
    source.configure(config);
    HierarchicalConfigurationDeserializer deserializer = new YamlDeserializer();

    final List<String> results = new ArrayList<>();
    source.listen(deserializer, fresh -> results.add(fresh.getString("key")));

    // Sleep a little bit between file modification to ensure we have a testable sequence of events.
    TimeUnit.MILLISECONDS.sleep(200);
    // Change the contents of the file. Triggers the listener the first time.
    Files.write(configFile.toPath(), VALUE_B.getBytes());
    TimeUnit.MILLISECONDS.sleep(200);
    // Change it again. Triggers the listener a second time.
    Files.write(configFile.toPath(), VALUE_A.getBytes());
    TimeUnit.MILLISECONDS.sleep(200);
    // Remove the file. Has no impact on the listener.
    Files.delete(configFile.toPath());
    TimeUnit.MILLISECONDS.sleep(200);
    // And recreate it. Triggers the listener.
    Files.write(configFile.toPath(), VALUE_C.getBytes());
    TimeUnit.MILLISECONDS.sleep(200);

    assertThat(results.get(0), is("BBB"));
    assertThat(results.get(1), is("AAA"));
    assertThat(results.get(2), is("CCC"));
    assertThat(results.size(), is(3));
}

From source file:org.lable.oss.dynamicconfig.provider.FileBasedConfigSourceTest.java

@Test(expected = ConfigurationException.class)
public void testConfigurationNonExistingFile() throws Exception {
    FileBasedConfigSource source = new FileBasedConfigSource();
    Configuration config = new BaseConfiguration();
    config.setProperty("path", "bogusPath");
    source.configure(config);// w  ww .  ja  v a  2 s  .co m
}