List of usage examples for org.apache.commons.configuration PropertiesConfiguration setAutoSave
public void setAutoSave(boolean autoSave)
From source file:eu.ascetic.zabbixdatalogger.datasource.ZabbixDirectDbDataSourceAdaptor.java
/** * This creates a new database connector for use. It establishes a database * connection immediately ready for use. *//*from ww w. j av a 2s . c om*/ public ZabbixDirectDbDataSourceAdaptor() { HISTORY_TABLES.add("history"); HISTORY_TABLES.add("history_str"); HISTORY_TABLES.add("history_uint"); HISTORY_TABLES.add("history_text"); try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. databaseURL = config.getString("data.logger.zabbix.db.url", databaseURL); config.setProperty("data.logger.zabbix.db.url", databaseURL); databaseDriver = config.getString("data.logger.zabbix.db.driver", databaseDriver); try { Class.forName(databaseDriver); } catch (ClassNotFoundException ex) { //If the driver is not found on the class path revert to MariaDB. databaseDriver = "org.mariadb.jdbc.Driver"; } config.setProperty("data.logger.zabbix.db.driver", databaseDriver); databasePassword = config.getString("data.logger.zabbix.db.password", databasePassword); config.setProperty("data.logger.zabbix.db.password", databasePassword); databaseUser = config.getString("data.logger.zabbix.db.user", databaseUser); config.setProperty("data.logger.zabbix.db.user", databaseUser); begins = config.getString("data.logger.filter.begins", begins); config.setProperty("data.logger.filter.begins", begins); isHost = config.getBoolean("data.logger.filter.isHost", isHost); config.setProperty("data.logger.filter.isHost", isHost); onlyAvailableHosts = config.getBoolean("data.logger.zabbix.only.available.hosts", onlyAvailableHosts); config.setProperty("data.logger.zabbix.only.available.hosts", onlyAvailableHosts); if (onlyAvailableHosts) { ALL_ZABBIX_HOSTS = ALL_ZABBIX_HOSTS + " AND h.available = 1"; } } catch (ConfigurationException ex) { DB_LOGGER.log(Level.SEVERE, "Error loading the configuration of the Zabbix data logger"); } try { connection = getConnection(); } catch (IOException | SQLException | ClassNotFoundException ex) { DB_LOGGER.log(Level.SEVERE, "Failed to establish the connection to the Zabbix DB", ex); } }
From source file:eu.tango.energymodeller.datasourceclient.ZabbixDirectDbDataSourceAdaptor.java
/** * This creates a new database connector for use. It establishes a database * connection immediately ready for use. *///from w w w. jav a 2 s.c om public ZabbixDirectDbDataSourceAdaptor() { HISTORY_TABLES.add("history"); HISTORY_TABLES.add("history_str"); HISTORY_TABLES.add("history_uint"); HISTORY_TABLES.add("history_text"); try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. databaseURL = config.getString("energy.modeller.zabbix.db.url", "jdbc:mysql://<ADD_ZABBIX_DB_SERVER_ADDRESS_HERE>:3306/zabbix"); config.setProperty("energy.modeller.zabbix.db.url", databaseURL); databaseDriver = config.getString("energy.modeller.zabbix.db.driver", databaseDriver); try { Class.forName(databaseDriver); } catch (ClassNotFoundException ex) { //If the driver is not found on the class path revert to MariaDB. databaseDriver = "com.mysql.jdbc.Driver"; } config.setProperty("energy.modeller.zabbix.db.driver", databaseDriver); databasePassword = config.getString("energy.modeller.zabbix.db.password", ""); config.setProperty("energy.modeller.zabbix.db.password", databasePassword); databaseUser = config.getString("energy.modeller.zabbix.db.user", databaseUser); config.setProperty("energy.modeller.zabbix.db.user", databaseUser); vmGroup = config.getString("energy.modeller.vm.group", vmGroup); config.setProperty("energy.modeller.vm.group", vmGroup); hostGroup = config.getString("energy.modeller.host.group", hostGroup); config.setProperty("energy.modeller.host.group", hostGroup); generalPowerConsumer = config.getString("energy.modeller.dfs.group", generalPowerConsumer); config.setProperty("energy.modeller.dfs.group", generalPowerConsumer); onlyAvailableHosts = config.getBoolean("energy.zabbix.only.available.hosts", onlyAvailableHosts); config.setProperty("energy.zabbix.only.available.hosts", onlyAvailableHosts); if (onlyAvailableHosts) { allZabbixHosts = allZabbixHosts + " AND h.available = 1"; } } catch (ConfigurationException ex) { DB_LOGGER.log(Level.SEVERE, "Error loading the configuration of the IaaS energy modeller", ex); } try { connection = getConnection(); } catch (IOException | SQLException | ClassNotFoundException ex) { DB_LOGGER.log(Level.SEVERE, "Failed to establish the connection to the Zabbix DB", ex); } }
From source file:eu.tango.energymodeller.datastore.DataGatherer.java
/** * This creates a data gather component for the energy modeller. * * @param datasource The data source that provides information about the * host resources and the virtual machines running on them. * @param connector The database connector used to do this. It is best to * give this component its own database connection as it will make heavy use * of it.//from w w w .jav a 2 s. c om */ public DataGatherer(HostDataSource datasource, DatabaseConnector connector) { this.datasource = datasource; this.database = connector; populateHostList(); try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. logVmsToDisk = config.getBoolean("energy.modeller.data.gatherer.log.vms", logVmsToDisk); config.setProperty("energy.modeller.data.gatherer.log.vms", logVmsToDisk); logAppsToDisk = config.getBoolean("energy.modeller.data.gatherer.log.apps", logAppsToDisk); config.setProperty("energy.modeller.data.gatherer.log.apps", logAppsToDisk); loggerOutputFile = config.getString("energy.modeller.data.gatherer.log.vms.filename", loggerOutputFile); config.setProperty("energy.modeller.data.gatherer.log.vms.filename", loggerOutputFile); loggerOutputFile = config.getString("energy.modeller.data.gatherer.log.apps.filename", appLoggerOutputFile); config.setProperty("energy.modeller.data.gatherer.log.apps.filename", appLoggerOutputFile); loggerConsiderIdleEnergy = config.getBoolean("energy.modeller.data.gatherer.log.consider_idle_energy", loggerConsiderIdleEnergy); config.setProperty("energy.modeller.data.gatherer.log.consider_idle_energy", loggerConsiderIdleEnergy); useWorkloadCache = config.getBoolean("energy.modeller.data.gatherer.log.use_workload_cache", useWorkloadCache); config.setProperty("energy.modeller.data.gatherer.log.use_workload_cache", useWorkloadCache); if (useWorkloadCache) { workloadCache = WorkloadStatisticsCache.getInstance(); workloadCache.setInUse(true); } } catch (ConfigurationException ex) { Logger.getLogger(DataGatherer.class.getName()).log(Level.INFO, "Error loading the configuration of the IaaS energy modeller", ex); } }
From source file:eu.tango.energymodeller.datastore.DefaultDatabaseConnector.java
/** * This reads the settings for the database connection from file. *///from ww w .j a v a2 s. c om protected final void loadSettings() { try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. databaseURL = config.getString("energy.modeller.db.url", databaseURL); config.setProperty("energy.modeller.db.url", databaseURL); databaseDriver = config.getString("energy.modeller.db.driver", databaseDriver); try { Class.forName(databaseDriver); } catch (ClassNotFoundException ex) { //If the driver is not found on the class path revert to mysql connector. databaseDriver = "com.mysql.jdbc.Driver"; } config.setProperty("energy.modeller.db.driver", databaseDriver); databasePassword = config.getString("energy.modeller.db.password", ""); config.setProperty("energy.modeller.db.password", databasePassword); databaseUser = config.getString("energy.modeller.db.user", databaseUser); config.setProperty("energy.modeller.db.user", databaseUser); } catch (ConfigurationException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.INFO, "Error loading database configuration information", ex); } }
From source file:eu.tango.energymodeller.EnergyModeller.java
/** * This is common code for the constructors *///from ww w .j a va2 s. c o m private void startup(boolean performDataGathering) { try { if (datasource == null) { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. String datasourceStr = config.getString("energy.modeller.datasource", "SlurmDataSourceAdaptor"); setDataSource(datasourceStr); config.setProperty("energy.modeller.datasource", datasourceStr); String predictorStr = config.getString("energy.modeller.predictor", "CpuAndAcceleratorEnergyPredictor"); setEnergyPredictor(predictorStr); config.setProperty("energy.modeller.predictor", predictorStr); if (!new File(CONFIG_FILE).exists()) { config.save(); } } } catch (ConfigurationException ex) { Logger.getLogger(EnergyModeller.class.getName()).log(Level.INFO, "Error loading the configuration of the energy modeller", ex); } dataGatherer = new DataGatherer(datasource, database); dataGatherer.setPerformDataGathering(performDataGathering); try { dataGatherThread = new Thread(dataGatherer); dataGatherThread.setDaemon(true); dataGatherThread.start(); } catch (Exception ex) { Logger.getLogger(EnergyModeller.class.getName()).log(Level.SEVERE, "The energry modeller failed to start correctly", ex); } }
From source file:org.jboss.forge.addon.configuration.ConfigurationFactoryImpl.java
private Configuration getConfiguration(File file) { try {/* ww w . j a va 2s .c o m*/ PropertiesConfiguration commonsConfig = new PropertiesConfiguration(file); commonsConfig.setEncoding("UTF-8"); commonsConfig.setReloadingStrategy(new FileChangedReloadingStrategy()); commonsConfig.setAutoSave(true); return new ConfigurationAdapter(commonsConfig); } catch (org.apache.commons.configuration.ConfigurationException e) { throw new ConfigurationException("Error while creating configuration from " + file, e); } }
From source file:org.jgrades.data.context.DataContext.java
@Bean public org.apache.commons.configuration.Configuration appConfiguration() { try {/*from ww w . j av a 2 s . co m*/ File appPropertiesFile = new File(appPropertiesFilePath); if (!appPropertiesFile.exists()) { appPropertiesFile.createNewFile(); } PropertiesConfiguration appConf = new PropertiesConfiguration(appPropertiesFile); appConf.setAutoSave(true); return appConf; } catch (IOException | ConfigurationException e) { LOGGER.warn("Exception during getting app properties file. Empty configuration will be returned", e); return new PropertiesConfiguration(); } }
From source file:org.jgrades.logging.dao.LoggingConfigurationDaoFileImpl.java
private Configuration externalConfiguration() throws ConfigurationException { PropertiesConfiguration extConf = new PropertiesConfiguration(externalConfigFilePath); extConf.setAutoSave(true); return extConf; }
From source file:org.pentaho.hadoop.PropertiesConfigurationProperties.java
private static PropertiesConfiguration initPropertiesConfiguration(FileObject fileObject) throws FileSystemException, ConfigurationException { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(fileObject.getURL()); propertiesConfiguration.setAutoSave(true); FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy(); fileChangedReloadingStrategy.setRefreshDelay(1000L); propertiesConfiguration.setReloadingStrategy(fileChangedReloadingStrategy); return propertiesConfiguration; }
From source file:org.sakuli.utils.SakuliPropertyPlaceholderConfigurer.java
@PreDestroy public void restoreProperties() { try {/* w ww. j a va 2s .co m*/ for (Map.Entry<String, Map<String, Object>> entry : modifiedSahiConfigProps.entrySet()) { String propFile = entry.getKey(); logger.debug("restore properties file '{}' with properties '{}'", propFile, entry.getValue()); PropertiesConfiguration propConfig = new PropertiesConfiguration(propFile); propConfig.setAutoSave(true); for (Map.Entry<String, Object> propEntry : entry.getValue().entrySet()) { String propKey = propEntry.getKey(); if (propConfig.containsKey(propKey)) { propConfig.clearProperty(propKey); } propConfig.addProperty(propKey, propEntry.getValue()); } } } catch (ConfigurationException e) { logger.error("Error in restore sahi config properties", e); } }