List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration
public PropertiesConfiguration(URL url) throws ConfigurationException
From source file:com.caricah.iotracah.bootstrap.system.handler.impl.DefaultConfigHandler.java
/** * All system configurations providers are loaded via spi * and are given the configurations the system already has. * They are further expected to provide their configurations in * and additive way. Since the order of loading the configs is not * guranteed all the setting keys should be uniquely identified * and that task is left to the implementations to enforce. * * @param configuration/*from www .java 2s . c o m*/ * @return * @throws UnRetriableException */ @Override public Configuration populateConfiguration(Configuration configuration) throws UnRetriableException { try { String configDirectory = getConfigurationDirectory(); log.debug(" populateConfiguration : obtained config directory - {}", configDirectory); Path configurationFile = getConfigurationFileInDirectory(configDirectory); if (null == configurationFile) { configurationFile = ResourceFileUtil.getFileFromResource(getClass(), getConfigurationFileName()) .toPath(); } if (configuration instanceof CompositeConfiguration) { ((CompositeConfiguration) configuration) .addConfiguration(new PropertiesConfiguration(configurationFile.toFile())); return configuration; } else { CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); if (null != configuration) { compositeConfiguration.addConfiguration(configuration); } compositeConfiguration.addConfiguration(new PropertiesConfiguration(configurationFile.toFile())); return compositeConfiguration; } } catch (IOException | ConfigurationException e) { log.error(" getConfiguration : ", e); throw new UnRetriableException(e); } }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java
@SuppressWarnings("unchecked") @Test/*from w ww. ja va 2 s. c om*/ public void testSaveGraphNeo4jResourceNoneCacheTypeOption() throws IOException, ConfigurationException { options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE, BlueprintsNeo4jResourceOptions.CACHE_TYPE.NONE); resource.save(options); File configFile = new File(testFilePath + configFileName); assert configFile.exists(); PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assert configuration.containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE); assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_NEO4J_CACHE_TYPE) .equals(BlueprintsNeo4jResourceOptions.CACHE_TYPE.NONE.toString()); assert getKeyCount(configuration) == defaultPropertyCount + 1 : "The number of properties in the configuration file is not consistent with the given options"; }
From source file:com.linkedin.pinot.core.segment.index.SegmentMetadataImpl.java
public SegmentMetadataImpl(File indexDir) throws ConfigurationException, IOException { LOGGER.debug("SegmentMetadata location: {}", indexDir); if (indexDir.isDirectory()) { _metadataFile = new File(indexDir, V1Constants.MetadataKeys.METADATA_FILE_NAME); } else {/*from w ww. ja v a 2s . co m*/ _metadataFile = indexDir; } _segmentMetadataPropertiesConfiguration = new PropertiesConfiguration(_metadataFile); _columnMetadataMap = new HashMap<String, ColumnMetadata>(); _allColumns = new HashSet<String>(); _schema = new Schema(); _indexDir = new File(indexDir, V1Constants.MetadataKeys.METADATA_FILE_NAME).getAbsoluteFile().getParent(); init(); loadCreationMeta(new File(indexDir, V1Constants.SEGMENT_CREATION_META)); setTimeIntervalAndGranularity(); LOGGER.debug("loaded metadata for {}", indexDir.getName()); }
From source file:com.amazon.janusgraph.TestGraphUtil.java
public Configuration loadProperties() { PropertiesConfiguration storageConfig; try {//from ww w . j a va2 s . c o m storageConfig = new PropertiesConfiguration(propertiesFile); } catch (ConfigurationException e) { throw new RuntimeException(e); } return storageConfig; }
From source file:fr.jetoile.hadoopunit.test.kafka.KafkaConsumerUtils.java
private void loadConfig() throws ConfigException { try {/* w w w .jav a2 s. c o m*/ configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE); } catch (ConfigurationException e) { throw new ConfigException("bad config", e); } kafkaHostname = configuration.getString(HadoopUnitConfig.KAFKA_HOSTNAME_KEY); kafkaPort = configuration.getInt(HadoopUnitConfig.KAFKA_PORT_KEY); }
From source file:com.ibm.replication.iidr.warehouse.CollectCDCStats.java
public CollectCDCStats(CollectCDCStatsParms parms) throws ConfigurationException, EmbeddedScriptException, IllegalAccessException, InstantiationException, ClassNotFoundException, SQLException, IOException, CollectCDCStatsParmsException { this.parms = parms; PropertiesConfiguration versionInfo = new PropertiesConfiguration( "conf" + File.separator + "version.properties"); logger = LogManager.getLogger(); logger.info("Version: " + versionInfo.getString("buildVersion") + "." + versionInfo.getString("buildRelease") + "." + versionInfo.getString("buildMod") + ", date: " + versionInfo.getString("buildDate")); // Debug logging? if (parms.debug) { LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig("com.ibm.replication.iidr"); loggerConfig.setLevel(Level.DEBUG); ctx.updateLoggers();// www . ja v a 2 s . c o m } // Load settings settings = new Settings(parms.propertiesFile); // TODO Set locale hard-coded to avoid date conversion errors, to be // fixed later Locale.setDefault(new Locale("en", "US")); // Get current session's locale currentLocale = Locale.getDefault(); logger.debug("Current locale (language_country): " + currentLocale.toString() + ", metrics will be parsed according to this locale"); localNumberFormat = NumberFormat.getInstance(currentLocale); // Check if the event log bookmarks will be used if (settings.logEventsToDB || settings.logEventsToCsv) { bookmarks = new Bookmarks("EventLogBookmarks.properties"); } // Start the timer thread to flush the output on a regular basis timer = new Timer(settings); new Thread(timer).start(); // Create a script object to be used to execute CHCCLP commands script = new EmbeddedScript(); try { script.open(); while (keepOn) { processSubscriptions(); logger.info("Sleeping for " + settings.checkFrequencySeconds + " seconds"); Thread.sleep(settings.checkFrequencySeconds * 1000); } } catch (EmbeddedScriptException e1) { logger.error(e1.getMessage()); throw new EmbeddedScriptException(99, "Error in running CHCCLP script"); } catch (InterruptedException e) { logger.info("Stop of program requested"); } catch (Exception e2) { logger.error("Error while collecting status and statistics: " + e2.getMessage()); } finally { disconnectServerDS(); script.close(); disconnectFromDatabase(); } }
From source file:gbc.jtimecalc.AbstractTimeDifferenceCalculatorTest.java
@SuppressWarnings("unchecked") public void loadExpectedMessages(String language) { try {/*from w w w . jav a 2 s . c o m*/ PropertiesConfiguration conf = new PropertiesConfiguration(AbstractTimeDifferenceCalculatorTest.class .getClassLoader().getResource("resources_" + language + ".properties")); messages = new HashMap<String, String>(); List<String> msgMap = conf.getList("messages"); for (String line : msgMap) { String[] tmp = line.split("="); if (tmp.length == 2) { messages.put(tmp[0], tmp[1]); } } } catch (ConfigurationException e) { logger.error(e); } }
From source file:cross.datastructures.pipeline.ResultAwareCommandPipeline.java
/** * * @param workflow// w ww. j av a 2s .c om * @return */ protected PropertiesConfiguration getHashes(IWorkflow workflow) { File hashesFile = getHashesFile(workflow); if (hashes == null) { try { hashes = new PropertiesConfiguration(hashesFile); hashes.setAutoSave(true); hashes.setReloadingStrategy(new FileChangedReloadingStrategy()); log.debug("Hashes: {}", ConfigurationUtils.toString(hashes)); return hashes; } catch (ConfigurationException ex) { log.error("Could not load configuration at " + hashesFile, ex); throw new ExitVmException(ex); } } else { return hashes; } }
From source file:edu.brown.api.BenchmarkConfig.java
@SuppressWarnings("unchecked") public void loadConfigFile(File path) { try {/*from www . ja v a 2 s . c om*/ this.config = new PropertiesConfiguration(benchmark_conf_path); } catch (Exception ex) { throw new RuntimeException("Failed to load benchmark configuration file " + benchmark_conf_path); } Class<?> confClass = this.getClass(); for (Object key : CollectionUtil.iterable(this.config.getKeys())) { String f_name = key.toString(); String f_value = this.config.getString(f_name); // Always store whatever the property as a client parameter String paramName = (HStoreConstants.BENCHMARK_PARAM_PREFIX + f_name).toUpperCase(); LOG.debug(String.format("Passing benchmark parameter to clients: %s = %s", paramName, f_value)); clientParameters.put(paramName, f_value); Field f = null; try { f = confClass.getField(f_name); } catch (Exception ex) { // XXX LOG.warn("Invalid configuration property '" + f_name + "'. Ignoring..."); continue; } assert (f != null); Class<?> f_class = f.getType(); Object value = null; if (f_class.equals(int.class)) { value = this.config.getInt(f_name); } else if (f_class.equals(long.class)) { value = this.config.getLong(f_name); } else if (f_class.equals(double.class)) { value = this.config.getDouble(f_name); } else if (f_class.equals(boolean.class)) { value = this.config.getBoolean(f_name); } else if (f_class.equals(String.class)) { value = this.config.getString(f_name); } else { LOG.warn(String.format("Unexpected value type '%s' for property '%s'", f_class.getSimpleName(), f_name)); } try { f.set(this, value); LOG.info(String.format("SET %s = %s", f_name, value)); } catch (Exception ex) { throw new RuntimeException("Failed to set value '" + value + "' for field '" + f_name + "'", ex); } } // FOR }
From source file:fr.inria.atlanmod.neoemf.data.blueprints.neo4j.option.BlueprintsNeo4jResourceSaveTest.java
/** * Test the existence of the cache_type properties in the configuration file. * <p>/* w ww .j a va 2 s. c o m*/ * This test use the option {@link BlueprintsNeo4jResourceOptions#CACHE_TYPE} * but does not test it (it is done in {@link #testSaveGraphNeo4jResourceNeo4jTypeOption()}) * <p> * In addition, there is no verification on the OPTIONS_GRAPH_NEO4J_STORE_DIR (it is done in * {@link #testSaveGraphNeo4jResourceNeo4jTypeOption()} */ @Test public void testSaveGraphNeo4jResourceWeakCacheTypeOption() throws IOException, ConfigurationException { Map<String, Object> options = BlueprintsNeo4jOptionsBuilder.newBuilder().weakCache().asMap(); resource.save(options); File configFile = new File(file() + configFileName); assertThat(configFile).exists(); PropertiesConfiguration configuration = new PropertiesConfiguration(configFile); assertConfigurationHasEntry(configuration, BlueprintsNeo4jResourceOptions.CACHE_TYPE, BlueprintsNeo4jResourceOptions.CacheType.WEAK.toString()); assertConfigurationHasSize(configuration, 1); }