List of usage examples for org.apache.commons.configuration SubnodeConfiguration getLong
public long getLong(String key)
From source file:de.clusteval.framework.repository.config.RepositoryConfig.java
/** * This method parses a repository configuration from the file at the given * absolute path./* w ww .j a v a2s . c o m*/ * * <p> * A repository configuration contains several sections and possible * options: * <ul> * <li><b>[mysql]</b></li> * <ul> * <li><b>host</b>: The ip address of the mysql host server.</li> * <li><b>database</b>: The mysql database name.</li> * <li><b>user</b>: The username used to connect to the database.</li> * <li><b>password</b>: The mysql password used to connect to the database. * The password is prompted from the console and not parsed from the file.</li> * </ul> * <li><b>[threading]</b></li> * <li><b>NameOfTheThreadSleepTime</b>: Sleeping time of the thread * 'NameOfTheThread'. This option can be used to control the frequency, with * which the threads check for changes on the filesystem.</li> </ul> * * @param absConfigPath * The absolute path of the repository configuration file. * @return The parsed repository configuration. * @throws RepositoryConfigNotFoundException * @throws RepositoryConfigurationException */ public static RepositoryConfig parseFromFile(final File absConfigPath) throws RepositoryConfigNotFoundException, RepositoryConfigurationException { if (!absConfigPath.exists()) throw new RepositoryConfigNotFoundException( "Repository config \"" + absConfigPath + "\" does not exist!"); Logger log = LoggerFactory.getLogger(RepositoryConfig.class); log.debug("Parsing repository config \"" + absConfigPath + "\""); try { HierarchicalINIConfiguration props = new HierarchicalINIConfiguration(absConfigPath); props.setThrowExceptionOnMissing(true); boolean usesMysql = false; MysqlConfig mysqlConfig = null; if (props.getSections().contains("mysql") && !ClustevalBackendServer.getBackendServerConfiguration().getNoDatabase()) { usesMysql = true; String mysqlUsername, mysqlDatabase, mysqlHost; SubnodeConfiguration mysql = props.getSection("mysql"); mysqlUsername = mysql.getString("user"); mysqlDatabase = mysql.getString("database"); mysqlHost = mysql.getString("host"); mysqlConfig = new MysqlConfig(usesMysql, mysqlUsername, mysqlDatabase, mysqlHost); } else mysqlConfig = new MysqlConfig(usesMysql, "", "", ""); Map<String, Long> threadingSleepTimes = new HashMap<String, Long>(); if (props.getSections().contains("threading")) { SubnodeConfiguration threading = props.getSection("threading"); Iterator<String> it = threading.getKeys(); while (it.hasNext()) { String key = it.next(); if (key.endsWith("SleepTime")) { String subKey = key.substring(0, key.indexOf("SleepTime")); try { threadingSleepTimes.put(subKey, threading.getLong(key)); } catch (Exception e) { // in case anything goes wrong, we just ignore this // option e.printStackTrace(); } } } } return new RepositoryConfig(mysqlConfig, threadingSleepTimes); } catch (ConfigurationException e) { throw new RepositoryConfigurationException(e.getMessage()); } catch (NoSuchElementException e) { throw new RepositoryConfigurationException(e.getMessage()); } }