org.apache.commons.configuration.CompositeConfiguration Java Examples

The following examples show how to use org.apache.commons.configuration.CompositeConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestConfigurationSubscription.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testAddReloadBasicsConfig() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    DeterministicScheduler mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub =
            new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
    assertEquals(null, conf.getProperty("prop1"));

    // add
    writer.setProperty("prop1", "1");
    writer.save();
    // ensure the file change reloading event can be triggered
    ensureConfigReloaded();
    mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    assertEquals("1", conf.getProperty("prop1"));

}
 
Example #2
Source File: TestConfigurationSubscription.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testInitialConfigLoad() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("prop1", "1");
    writer.setProperty("prop2", "abc");
    writer.setProperty("prop3", "123.0");
    writer.setProperty("prop4", "11132");
    writer.setProperty("prop5", "true");
    writer.save();

    ScheduledExecutorService mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub =
            new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
    assertEquals(1, conf.getInt("prop1"));
    assertEquals("abc", conf.getString("prop2"));
    assertEquals(123.0, conf.getFloat("prop3"), 0);
    assertEquals(11132, conf.getInt("prop4"));
    assertEquals(true, conf.getBoolean("prop5"));
}
 
Example #3
Source File: TestConfUtils.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testLoadConfiguration() {
    Configuration conf1 = new CompositeConfiguration();
    conf1.setProperty("key1", "value1");
    conf1.setProperty("key2", "value2");
    conf1.setProperty("key3", "value3");

    Configuration conf2 = new CompositeConfiguration();
    conf2.setProperty("bkc.key1", "bkc.value1");
    conf2.setProperty("bkc.key4", "bkc.value4");

    assertEquals("value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals(null, conf1.getString("key4"));

    ConfUtils.loadConfiguration(conf1, conf2, "bkc.");

    assertEquals("bkc.value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals("bkc.value4", conf1.getString("key4"));
    assertEquals(null, conf1.getString("bkc.key1"));
    assertEquals(null, conf1.getString("bkc.key4"));
}
 
Example #4
Source File: TestConfUtils.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadConfiguration() {
    Configuration conf1 = new CompositeConfiguration();
    conf1.setProperty("key1", "value1");
    conf1.setProperty("key2", "value2");
    conf1.setProperty("key3", "value3");

    Configuration conf2 = new CompositeConfiguration();
    conf2.setProperty("bkc.key1", "bkc.value1");
    conf2.setProperty("bkc.key4", "bkc.value4");

    assertEquals("value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals(null, conf1.getString("key4"));

    ConfUtils.loadConfiguration(conf1, conf2, "bkc.");

    assertEquals("bkc.value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals("bkc.value4", conf1.getString("key4"));
    assertEquals(null, conf1.getString("bkc.key1"));
    assertEquals(null, conf1.getString("bkc.key4"));
}
 
Example #5
Source File: SshdSettingsBuilder.java    From artifactory_ssh_proxy with Apache License 2.0 6 votes vote down vote up
protected Configuration createConfiguration(final String overriddenPath) {
    try {

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("got overriddenPath {}", overriddenPath);
        }

        CompositeConfiguration compositeConfig = new CompositeConfiguration();
        // TODO: see how Systems and properties interact.
        compositeConfig.addConfiguration(new SystemConfiguration());
        compositeConfig.addConfiguration(findPropertiesConfiguration(overriddenPath));

        return compositeConfig;
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: StartupConfiguration.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
/** Takes two configuration and returns their union, with the second overriding the first.
 *
 * @param base the base configuration.
 * @param additional the additional set of properties, some of which may override those specified in <code>base</code>.
 * @return the union of the two configurations, as specified above.
 */
private static Configuration append(Configuration base, Configuration additional) {
	final CompositeConfiguration result = new CompositeConfiguration();
	result.addConfiguration(additional);
	result.addConfiguration(base);
	return result;
}
 
Example #7
Source File: Config.java    From IGUANA with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Loads a Properties Configuration file assoc. with the fileName
 * 
 * @param fileName
 */
public static synchronized void loadAdditionalProperties(String fileName) {
    try {
        ((CompositeConfiguration) getInstance()).addConfiguration(new PropertiesConfiguration(fileName));
    } catch (ConfigurationException e) {
        LOGGER.error("Could not load Properties from the properties file (\"" + fileName
                + "\"). This Iguana instance won't work as expected.", e);
    }
}
 
Example #8
Source File: PalmettoConfiguration.java    From Palmetto with GNU Affero General Public License v3.0 5 votes vote down vote up
public static synchronized void loadAdditionalProperties(String fileName) {
    try {
        ((CompositeConfiguration) getInstance()).addConfiguration(new PropertiesConfiguration(fileName));
    } catch (ConfigurationException e) {
        LOGGER.error("Couldnt load Properties from the properties file (\"" + fileName
                + "\"). This GERBIL instance won't work as expected.", e);
    }
}
 
Example #9
Source File: ClientConfig.java    From juddi with Apache License 2.0 5 votes vote down vote up
/**
 * Use this method to attempt to save the jUDDI configuration file after
 * you've modified it using the Apache Commons Configuration settings.
 * This is especially useful if you've constructed a user interface for manipulating
 * the configuration like a properties sheet and is used by the juddi-gui (web ui)
 * @since 3.2.1
 * @throws org.apache.commons.configuration.ConfigurationException
 */
public void saveConfigRaw() throws ConfigurationException{
 XMLConfiguration saveConfiguration = new XMLConfiguration(configurationFile);
    Configuration cc = new CompositeConfiguration(saveConfiguration);
    Iterator<String> keys = this.config.getKeys();
    while (keys.hasNext()){
        String key = keys.next();
        if (key.startsWith("client") || key.startsWith("config"))
        {
            cc.setProperty(key, config.getProperty(key));
        }
    }
    saveConfiguration.save();

}
 
Example #10
Source File: DatabaseJobHistoryStoreSchemaManager.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public void run(String[] args) throws Exception {
  if (args.length < 1 || args.length > 2) {
    printUsage();
  }
  Closer closer = Closer.create();
  try {
    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    if (args.length == 2) {
      config.addConfiguration(new PropertiesConfiguration(args[1]));
    }
    Properties properties = getProperties(config);
    DatabaseJobHistoryStoreSchemaManager schemaManager =
            closer.register(DatabaseJobHistoryStoreSchemaManager.builder(properties).build());
    if (String.CASE_INSENSITIVE_ORDER.compare("migrate", args[0]) == 0) {
      schemaManager.migrate();
    } else if (String.CASE_INSENSITIVE_ORDER.compare("info", args[0]) == 0) {
      schemaManager.info();
    } else {
      printUsage();
    }
  } catch (Throwable t) {
    throw closer.rethrow(t);
  } finally {
    closer.close();
  }
}
 
Example #11
Source File: ArchaiusConfiguration.java    From kork with Apache License 2.0 5 votes vote down vote up
@PreDestroy
public void shutdown() {
  if (configurationInstance != null) {
    pollingScheduler.stop();
    ((CompositeConfiguration) ConfigurationManager.getConfigInstance())
        .removeConfiguration(configurationInstance);
  }
}
 
Example #12
Source File: GerbilConfiguration.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public static synchronized void loadAdditionalProperties(String fileName) {
    try {
        ((CompositeConfiguration) getInstance()).addConfiguration(new PropertiesConfiguration(fileName));
    } catch (ConfigurationException e) {
        LOGGER.error("Couldnt load Properties from the properties file (\"" + fileName
                + "\"). This GERBIL instance won't work as expected.", e);
    }
}
 
Example #13
Source File: ManagerApiMicroServiceConfig.java    From apiman with Apache License 2.0 5 votes vote down vote up
/**
 * @see io.apiman.manager.api.core.config.ApiManagerConfig#loadProperties()
 */
@Override
protected Configuration loadProperties() {
    CompositeConfiguration config = (CompositeConfiguration) super.loadProperties();
    try {
        String propsUrl = System.getProperty(APIMAN_PROPERTIES_URL);
        if (propsUrl == null) {
            propsUrl = getClass().getClassLoader().getResource("micro-apiman.properties").toString(); //$NON-NLS-1$
        }
        config.addConfiguration(new PropertiesConfiguration(new URL(propsUrl)));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return config;
}
 
Example #14
Source File: LocalBookkeeperEnsemble.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public void startStandalone(ServerConfiguration conf, boolean enableStreamStorage) throws Exception {
    LOG.debug("Local ZK/BK starting ...");
    conf.setAdvertisedAddress(advertisedAddress);

    runZookeeper(1000);
    initializeZookeper();
    runBookies(conf);
    if (enableStreamStorage) {
        runStreamStorage(new CompositeConfiguration());
    }
}
 
Example #15
Source File: LocalBookkeeperEnsemble.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public void start(boolean enableStreamStorage) throws  Exception {
    LOG.debug("Local ZK/BK starting ...");
    ServerConfiguration conf = new ServerConfiguration();
    // Use minimal configuration requiring less memory for unit tests
    conf.setLedgerStorageClass(DbLedgerStorage.class.getName());
    conf.setProperty("dbStorage_writeCacheMaxSizeMb", 2);
    conf.setProperty("dbStorage_readAheadCacheMaxSizeMb", 1);
    conf.setProperty("dbStorage_rocksDB_writeBufferSizeMB", 1);
    conf.setProperty("dbStorage_rocksDB_blockCacheSize", 1024 * 1024);
    conf.setFlushInterval(60000);
    conf.setJournalSyncData(false);
    conf.setProperty("journalMaxGroupWaitMSec", 0L);
    conf.setAllowLoopback(true);
    conf.setGcWaitTime(60000);
    conf.setNumAddWorkerThreads(0);
    conf.setNumReadWorkerThreads(0);
    conf.setNumHighPriorityWorkerThreads(0);
    conf.setNumJournalCallbackThreads(0);
    conf.setServerNumIOThreads(1);
    conf.setNumLongPollWorkerThreads(1);
    conf.setAllocatorPoolingPolicy(PoolingPolicy.UnpooledHeap);

    runZookeeper(1000);
    initializeZookeper();
    runBookies(conf);

    if (enableStreamStorage) {
        runStreamStorage(new CompositeConfiguration());
    }
}
 
Example #16
Source File: BenchmarkWorker.java    From openmessaging-benchmark with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    final Arguments arguments = new Arguments();
    JCommander jc = new JCommander(arguments);
    jc.setProgramName("benchmark-worker");

    try {
        jc.parse(args);
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        jc.usage();
        System.exit(-1);
    }

    if (arguments.help) {
        jc.usage();
        System.exit(-1);
    }

    Configuration conf = new CompositeConfiguration();
    conf.setProperty(Stats.STATS_PROVIDER_CLASS, PrometheusMetricsProvider.class.getName());
    conf.setProperty("prometheusStatsHttpPort", arguments.statsPort);
    Stats.loadStatsProvider(conf);
    StatsProvider provider = Stats.get();
    provider.start(conf);

    Runtime.getRuntime().addShutdownHook(new Thread(
        () -> provider.stop(),
        "benchmark-worker-shutdown-thread"));

    // Dump configuration variables
    log.info("Starting benchmark with config: {}", writer.writeValueAsString(arguments));

    // Start web server
    Javalin app = Javalin.start(arguments.httpPort);

    new WorkerHandler(app, provider.getStatsLogger("benchmark"));
}
 
Example #17
Source File: FreemarkerTemplateEngine.java    From jbake with MIT License 4 votes vote down vote up
@Deprecated
public FreemarkerTemplateEngine(final CompositeConfiguration config, final ContentStore db, final File destination, final File templatesPath) {
    super(config, db, destination, templatesPath);
    createTemplateConfiguration();
}
 
Example #18
Source File: JadeTemplateEngine.java    From jbake with MIT License 4 votes vote down vote up
@Deprecated
public JadeTemplateEngine(final CompositeConfiguration config, final ContentStore db, final File destination, final File templatesPath) {
    super(config, db, destination, templatesPath);
}
 
Example #19
Source File: AbstractTemplateEngine.java    From jbake with MIT License 4 votes vote down vote up
@Deprecated
protected AbstractTemplateEngine(final Configuration config, final ContentStore db, final File destination, final File templatesPath) {
    this(new JBakeConfigurationFactory().createDefaultJbakeConfiguration(templatesPath.getParentFile(),destination, (CompositeConfiguration) config),db);
}
 
Example #20
Source File: ConfigFactory.java    From apiman with Apache License 2.0 4 votes vote down vote up
public static final CompositeConfiguration createConfig() {
    CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
    compositeConfiguration.addConfiguration(new SystemPropertiesConfiguration());
    compositeConfiguration.addConfiguration(ConfigFileConfiguration.create("apiman.properties", "apiman.config.url")); //$NON-NLS-1$ //$NON-NLS-2$
    return compositeConfiguration;
}
 
Example #21
Source File: Oven.java    From jbake with MIT License 4 votes vote down vote up
@Deprecated
public void setConfig(final CompositeConfiguration config) {
    ((DefaultJBakeConfiguration) utensils.getConfiguration()).setCompositeConfiguration(config);
}
 
Example #22
Source File: Oven.java    From jbake with MIT License 4 votes vote down vote up
@Deprecated
public CompositeConfiguration getConfig() {
    return ((DefaultJBakeConfiguration) utensils.getConfiguration()).getCompositeConfiguration();
}
 
Example #23
Source File: DefaultJBakeConfiguration.java    From jbake with MIT License 4 votes vote down vote up
public void setCompositeConfiguration(CompositeConfiguration configuration) {
    this.compositeConfiguration = configuration;
}
 
Example #24
Source File: DefaultJBakeConfiguration.java    From jbake with MIT License 4 votes vote down vote up
public CompositeConfiguration getCompositeConfiguration() {
    return compositeConfiguration;
}
 
Example #25
Source File: DefaultJBakeConfiguration.java    From jbake with MIT License 4 votes vote down vote up
public DefaultJBakeConfiguration(File sourceFolder, CompositeConfiguration configuration) {
    this.compositeConfiguration = configuration;
    setSourceFolder(sourceFolder);
    setupDefaultDestination();
    setupPathsRelativeToSourceFile();
}
 
Example #26
Source File: ConfigUtil.java    From jbake with MIT License 4 votes vote down vote up
public JBakeConfiguration loadConfig(File source) throws ConfigurationException {
    CompositeConfiguration configuration = load(source);
    return new DefaultJBakeConfiguration(source, configuration);
}
 
Example #27
Source File: TagsRenderer.java    From jbake with MIT License 4 votes vote down vote up
@Override
public int render(Renderer renderer, ContentStore db, File destination, File templatesPath, CompositeConfiguration config) throws RenderingException {
    JBakeConfiguration configuration = new JBakeConfigurationFactory().createDefaultJbakeConfiguration(templatesPath.getParentFile(), config);
    return render(renderer, db, configuration);
}
 
Example #28
Source File: RenderingTool.java    From jbake with MIT License 4 votes vote down vote up
@Deprecated
//TODO: remove at 3.0.0
int render(Renderer renderer, ContentStore db, File destination, File templatesPath, CompositeConfiguration config) throws RenderingException;
 
Example #29
Source File: ArchiveRenderer.java    From jbake with MIT License 4 votes vote down vote up
@Override
public int render(Renderer renderer, ContentStore db, File destination, File templatesPath, CompositeConfiguration config) throws RenderingException {

    JBakeConfiguration configuration = new JBakeConfigurationFactory().createDefaultJbakeConfiguration(templatesPath.getParentFile(), config);
    return render(renderer, db, configuration);
}
 
Example #30
Source File: TestConfigurationSubscription.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60000)
public void testExceptionInConfigLoad() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("prop1", "1");
    writer.save();

    DeterministicScheduler mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub =
            new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);

    final AtomicInteger count = new AtomicInteger(1);
    conf.addConfigurationListener(new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            LOG.info("config changed {}", event);
            // Throw after so we actually see the update anyway.
            if (!event.isBeforeUpdate()) {
                count.getAndIncrement();
                throw new RuntimeException("config listener threw and exception");
            }
        }
    });

    int i = 0;
    int initial = 0;
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }

    initial = count.get();
    while (count.get() == initial) {
        writer.setProperty("prop1", Integer.toString(i++));
        writer.save();
        mockScheduler.tick(100, TimeUnit.MILLISECONDS);
    }
}