List of usage examples for org.apache.commons.configuration Configuration getInt
int getInt(String key);
From source file:dk.dbc.opensearch.datadock.DatadockMain.java
/** * * /*from www. jav a2 s.co m*/ * @param args * @throws ConfigurationException */ public DatadockMain(String[] args) throws ConfigurationException { /** Try obtaining home path of datadock. If property 'datadock.home' is not set, * current working directory is assumed to be home. */ String datadockHome = System.getProperty("datadock.home"); if (datadockHome == null) { datadockHome = new File(".").getAbsolutePath(); } else { datadockHome = new File(datadockHome).getAbsolutePath(); } log.info(String.format("Using datadock.home: %s", datadockHome)); System.out.println(String.format("Using datadock.home: %s", datadockHome)); Configuration config = null; // Try reading properties file from -Dproperties.file String localPropFileName = System.getProperty("properties.file"); // If -Dpropfile is not set try reading from either ../config/datadock.properties or ./config/datadock.properties if (localPropFileName != null) { config = new PropertiesConfiguration(localPropFileName); } else { localPropFileName = "../config/" + propFileName; if (new File(localPropFileName).exists()) { config = new PropertiesConfiguration(localPropFileName); } localPropFileName = "./config/" + propFileName; if (new File(localPropFileName).exists()) { config = new PropertiesConfiguration(localPropFileName); } } // Throw new ConfigurationException if properties file could not be located. if (config == null) { throw new ConfigurationException( String.format("Could not load configuration from configuration file: %s; CWD: %s", localPropFileName, new File(".").getAbsoluteFile())); } log.info(String.format("Using properties file: %s", localPropFileName)); try { String configFile = config.getString("Log4j"); if (new File(configFile).exists()) { Log4jConfiguration.configure(configFile); } else { if (configFile.startsWith("../")) { configFile = configFile.replaceFirst("../", ""); if (new File(configFile).exists()) { Log4jConfiguration.configure(configFile); } else { throw new ConfigurationException( String.format("Could not locate config file at: %s", config.getString("Log4j"))); } } else { throw new ConfigurationException( String.format("Could not locate config file at: %s", config.getString("Log4j"))); } } log.info(String.format("Using config file: %s", configFile)); } catch (ConfigurationException ex) { String errMsg = String.format("Logger could not be configured, will continue without logging: %s", ex.getMessage()); log.error(errMsg); System.out.println(errMsg); } pollTime = config.getInt("MainPollTime"); queueSize = config.getInt("QueueSize"); corePoolSize = config.getInt("CorePoolSize"); maxPoolSize = config.getInt("MaxPoolSize"); keepAliveTime = config.getInt("KeepAliveTime"); log.debug(String.format("Starting Datadock with pollTime = %s", pollTime)); log.debug(String.format("Starting Datadock with queueSize = %s", queueSize)); log.debug(String.format("Starting Datadock with corePoolSize = %s", corePoolSize)); log.debug(String.format("Starting Datadock with maxPoolSize = %s", maxPoolSize)); log.debug(String.format("Starting Datadock with keepAliveTime = %s", keepAliveTime)); pluginFlowXmlPath = new File(config.getString("PluginFlowXmlPath")); pluginFlowXsdPath = new File(config.getString("PluginFlowXsdPath")); if (null == pluginFlowXmlPath || null == pluginFlowXsdPath) { throw new ConfigurationException( "Failed to initialize configuration values for File objects properly (pluginFlowXmlPath or pluginFlowXsdPath)"); } log.debug(String.format("Starting Datadock with pluginFlowXmlPath = %s", pluginFlowXmlPath)); log.debug(String.format("Starting Datadock with pluginFlowXsdPath = %s", pluginFlowXsdPath)); maxToHarvest = config.getInt("MaxToHarvest"); dataBaseNames = config.getList("OracleDataBaseNames"); oracleCacheName = config.getString("OracleCacheName"); oracleUrl = config.getString("OracleUrl"); oracleUser = config.getString("OracleUserID"); oraclePassWd = config.getString("OraclePassWd"); minLimit = config.getString("OracleMinLimit"); maxLimit = config.getString("OracleMaxLimit"); initialLimit = config.getString("OracleInitialLimit"); connectionWaitTimeout = config.getString("OracleConnectionWaitTimeout"); usePriorityFlag = config.getBoolean("UsePriorityField"); host = config.getString("Host"); port = config.getString("Port"); user = config.getString("User"); pass = config.getString("PassPhrase"); javascriptPath = config.getString("ScriptPath"); fileHarvestLightDir = config.getString("ToHarvest"); fileHarvestLightSuccessDir = config.getString("HarvestDone"); fileHarvestLightFailureDir = config.getString("HarvestFailure"); }
From source file:keel.Algorithms.Neural_Networks.NNEP_Common.algorithm.NeuralNetAlgorithm.java
/** * <p>//from w w w . j a v a2 s . co m * Configuration parameters for NeuralNetAlgorithm class are: * * <ul> * <li> * <code>species: ISpecies (complex)</code></p> * Individual species * </li><li> * <code>evaluator IEvaluator (complex)</code></p> * Individuals evaluator * </li><li> * <code>population-size (int)</code></p> * Population size * </li><li> * <code>max-of-generations (int)</code></p> * Maximum number of generations * </li> * <li> * <code>provider: IProvider (complex)</code></p> * Individuals provider * </li> * <li> * <code>mutator1: IMutator<I> (complex)</code></p> * Individuals mutator1 * </li> * <li> * <code>mutator2: IMutator<I> (complex)</code></p> * Individuals mutator2 * </li> * <li> * <code>creation-ratio (double)</code></p> * Ratio "elements created"/"elements remaining" * </li> * <li> * <code>percentage-second-mutator (int)</code></p> * Percentage of individuals mutated with second mutator * </li> * <li> * <code>max-generations-without-improving-mean (int)</code></p> * Maximum number of generations without improving mean fitness * </li> * <li> * <code>max-generations-without-improving-best (int)</code></p> * Maximum number of generations without improving best fitness * </li> * <li> * <code>fitness-difference (double)</code></p> * Difference between two fitness that we consider * enough to say that the fitness has improved * </li> * </ul> * </p> * @param configuration Configuration object to obtain the parameters */ @SuppressWarnings("unchecked") public void configure(Configuration configuration) { // Random generators factory try { // Species classname String randGenFactoryClassname = configuration.getString("rand-gen-factory[@type]"); // Species class Class<? extends IRandGenFactory> randGenFactoryClass = (Class<? extends IRandGenFactory>) Class .forName(randGenFactoryClassname); // Species instance IRandGenFactory randGenFactory = randGenFactoryClass.newInstance(); // Configure species if (randGenFactory instanceof IConfigure) { ((IConfigure) randGenFactory).configure(configuration.subset("rand-gen-factory")); } // Set species setRandGenFactory(randGenFactory); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Illegal random generators factory classname"); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("Problems creating an instance of random generators factory", e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("Problems creating an instance of random generators factory", e); } // Individual species try { // Species classname String speciesClassname = configuration.getString("species[@type]"); // Species class Class<ISpecies<I>> speciesClass = (Class<ISpecies<I>>) Class.forName(speciesClassname); // Species instance ISpecies<I> species = speciesClass.newInstance(); // Configure species if neccesary if (species instanceof IConfigure) { // Extract species configuration Configuration speciesConfiguration = configuration.subset("species"); // Configure species ((IConfigure) species).configure(speciesConfiguration); } // Set species setSpecies(species); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Illegal species classname"); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("Problems creating an instance of species", e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("Problems creating an instance of species", e); } // Individuals evaluator try { // Evaluator classname String evaluatorClassname = configuration.getString("evaluator[@type]"); // Evaluator class Class<IEvaluator<I>> evaluatorClass = (Class<IEvaluator<I>>) Class.forName(evaluatorClassname); // Evaluator instance IEvaluator<I> evaluator = evaluatorClass.newInstance(); // Configure evaluator if neccesary if (evaluator instanceof IConfigure) { // Extract species configuration Configuration evaluatorConfiguration = configuration.subset("evaluator"); // Configure evaluator ((IConfigure) evaluator).configure(evaluatorConfiguration); } // Set species setEvaluator(evaluator); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Illegal evaluator classname"); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("Problems creating an instance of evaluator", e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("Problems creating an instance of evaluator", e); } // Population size int populationSize = configuration.getInt("population-size"); setPopulationSize(populationSize); // Maximum of generations int maxOfGenerations = configuration.getInt("max-of-generations"); setMaxOfGenerations(maxOfGenerations); // Individuals provider try { // Provider classname String providerClassname = configuration.getString("provider[@type]"); // Provider class Class<IProvider<I>> providerClass = (Class<IProvider<I>>) Class.forName(providerClassname); // Provider instance IProvider<I> provider = providerClass.newInstance(); // Configure provider if neccesary if (provider instanceof IConfigure) { // Extract provider configuration Configuration providerConfiguration = configuration.subset("provider"); // Configure provider ((IConfigure) provider).configure(providerConfiguration); } // Set provider setProvider(provider); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Illegal provider classname"); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("Problems creating an instance of provider", e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("Problems creating an instance of provider", e); } // Individuals mutator1 try { // Mutator1 classname String mutator1Classname = configuration.getString("mutator1[@type]"); // Mutator1 classe Class<IMutator<I>> mutator1Class = (Class<IMutator<I>>) Class.forName(mutator1Classname); // Mutator1 instance IMutator<I> mutator1 = mutator1Class.newInstance(); // Configure mutator1 if neccesary if (mutator1 instanceof IConfigure) { // Extract mutator1 configuration Configuration mutator1Configuration = configuration.subset("mutator1"); // Configure mutator1 ((IConfigure) mutator1).configure(mutator1Configuration); } // Set mutator1 setMutator1(mutator1); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Illegal mutator1 classname"); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("Problems creating an instance of mutator1", e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("Problems creating an instance of mutator1", e); } // Individuals mutator2 try { // Mutator2 classname String mutator2Classname = configuration.getString("mutator2[@type]"); // Mutator2 class Class<IMutator<I>> mutator2Class = (Class<IMutator<I>>) Class.forName(mutator2Classname); // Mutator2 instance IMutator<I> mutator2 = mutator2Class.newInstance(); // Configure mutator2 if neccesary if (mutator2 instanceof IConfigure) { // Extract mutator2 configuration Configuration mutator2Configuration = configuration.subset("mutator2"); // Configure mutator2 ((IConfigure) mutator2).configure(mutator2Configuration); } // Set mutator2 setMutator2(mutator2); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Illegal mutator2 classname"); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("Problems creating an instance of mutator2", e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("Problems creating an instance of mutator2", e); } // Creation ratio double cratio = configuration.getDouble("creation-ratio"); setCratio(cratio); // Percentage of individuals mutated with second mutator int percenageMutator2 = configuration.getInt("percentage-second-mutator"); setPercentageSecondMutator(percenageMutator2); // Maximum of generations without improving mean fitness int mogmean = configuration.getInt("max-generations-without-improving-mean"); setMogmean(mogmean); // Maximum of generations without improving best fitness int mogbest = configuration.getInt("max-generations-without-improving-best"); setMogbest(mogbest); // Significative fitness difference double fitDif = configuration.getDouble("fitness-difference"); setFitDif(fitDif); }
From source file:ninja.utils.NinjaConstantTest.java
/** * This testcase makes sure that all constants defined * in NinjaConstant are working./*from w ww . ja v a 2s . c o m*/ * * File conf/all_constants.conf simply contains all contstants. * We simply read them in and check if the constants are okay. * * Aim is to prevent stupid spelling mistakes. * */ @Test public void testAllConstants() { Configuration configuration = SwissKnife.loadConfigurationInUtf8("conf/all_constants.conf"); assertEquals("LANGUAGES", configuration.getString(NinjaConstant.applicationLanguages)); assertEquals("PREFIX", configuration.getString(NinjaConstant.applicationCookiePrefix)); assertEquals("NAME", configuration.getString(NinjaConstant.applicationName)); assertEquals("SECRET", configuration.getString(NinjaConstant.applicationSecret)); assertEquals("SERVER_NAME", configuration.getString(NinjaConstant.serverName)); assertEquals(9999, configuration.getInt(NinjaConstant.sessionExpireTimeInSeconds)); assertEquals(false, configuration.getBoolean(NinjaConstant.sessionSendOnlyIfChanged)); assertEquals(false, configuration.getBoolean(NinjaConstant.sessionTransferredOverHttpsOnly)); assertEquals(true, configuration.getBoolean(NinjaConstant.sessionHttpOnly)); }
From source file:nl.tudelft.graphalytics.configuration.ConfigurationUtil.java
public static int getInteger(Configuration config, String property) throws InvalidConfigurationException { ensureConfigurationKeyExists(config, property); try {//from ww w . j av a 2s . c o m return config.getInt(property); } catch (ConversionException ignore) { throw new InvalidConfigurationException("Invalid value for property \"" + resolve(config, property) + "\": \"" + config.getString(property) + "\", expected an integer value."); } }
From source file:org.apache.camel.processor.idempotent.mongodb.test.TestIdempotentRepositoryInRoute.java
public TestIdempotentRepositoryInRoute() throws ConfigurationException { Configuration config = new PropertiesConfiguration("database.properties"); //set properties host1 = config.getString("host1"); port1 = config.getInt("port1"); dbName1 = config.getString("dbName1"); collectionName1 = config.getString("collectionName1"); this.prepareDB(); }
From source file:org.apache.camel.processor.idempotent.mongodb.test.TestMongoDbIdempotentRepository.java
public TestMongoDbIdempotentRepository() throws ConfigurationException { Configuration config = new PropertiesConfiguration("database.properties"); //set properties host1 = config.getString("host1"); port1 = config.getInt("port1"); dbName1 = config.getString("dbName1"); collectionName1 = config.getString("collectionName1"); host2 = config.getString("host2"); port2 = config.getInt("port2"); dbName2 = config.getString("dbName2"); collectionName2 = config.getString("collectionName2"); bean = MongoDbIdempotentRepository.mongoIdempotentRepository(host1); this.prepareDB(); }
From source file:org.apache.james.postage.configuration.ConfigurationLoader.java
public Map<String, PostageConfiguration> create(Configuration configuration) { log.debug("reading configuration."); Map<String, PostageConfiguration> postageConfigurations = new LinkedHashMap<String, PostageConfiguration>(); List<String> scenariosIds = configuration.getList("scenario[@id]"); log.debug("scenarios contained in configuration: " + scenariosIds.size()); Iterator<String> scenarioIter = scenariosIds.iterator(); int scenarioCount = 0; while (scenarioIter.hasNext()) { String scenarioId = scenarioIter.next(); if (postageConfigurations.containsKey(scenarioId)) { log.error("found in configuration more than one scenario which is named: " + scenarioId); continue; }/*from w w w . j a v a 2s .co m*/ PostageConfiguration postageConfiguration = new PostageConfiguration(scenarioId); String scenario = getIndexedPropertyName("scenario", scenarioCount); postageConfiguration.setDurationMinutes( configuration.getInt(getAttributedPropertyName(scenario, "runtimeMinutes"))); addDescription(postageConfiguration, configuration.subset(scenario + ".description")); String scenarioInternalUsers = scenario + ".users.internal"; UserList internals = new UserList( configuration.getInt(getAttributedPropertyName(scenarioInternalUsers, "count")), configuration.getString(getAttributedPropertyName(scenarioInternalUsers, "username-prefix")), configuration.getString(getAttributedPropertyName(scenarioInternalUsers, "domain")), configuration.getString(getAttributedPropertyName(scenarioInternalUsers, "password"))); postageConfiguration.setInternalUsers(internals); postageConfiguration.setInternalReuseExisting( configuration.getBoolean(getAttributedPropertyName(scenarioInternalUsers, "reuseExisting"))); String scenarioExternalUsers = scenario + ".users.external"; UserList externals = new UserList( configuration.getInt(getAttributedPropertyName(scenarioExternalUsers, "count")), configuration.getString(getAttributedPropertyName(scenarioExternalUsers, "username-prefix")), configuration.getString(getAttributedPropertyName(scenarioExternalUsers, "domain"))); postageConfiguration.setExternalUsers(externals); String scenarioTestserver = scenario + ".testserver"; postageConfiguration.setTestserverHost( configuration.getString(getAttributedPropertyName(scenarioTestserver, "host"))); postageConfiguration.setTestserverPortPOP3( configuration.getInt(getAttributedPropertyName(scenarioTestserver + ".pop3", "port"))); postageConfiguration.setTestserverPOP3FetchesPerMinute( configuration.getInt(getAttributedPropertyName(scenarioTestserver + ".pop3", "count-per-min"))); postageConfiguration.setTestserverPortSMTPInbound( configuration.getInt(getAttributedPropertyName(scenarioTestserver + ".smtp-inbound", "port"))); postageConfiguration.setTestserverPortSMTPForwarding(configuration .getInt(getAttributedPropertyName(scenarioTestserver + ".smtp-forwarding", "port"))); postageConfiguration.setTestserverSMTPForwardingWaitSeconds(configuration.getInt( getAttributedPropertyName(scenarioTestserver + ".smtp-forwarding", "latecomer-wait-seconds"))); postageConfiguration.setTestserverRemoteManagerPort( configuration.getInt(getAttributedPropertyName(scenarioTestserver + ".remotemanager", "port"))); postageConfiguration.setTestserverRemoteManagerUsername(configuration .getString(getAttributedPropertyName(scenarioTestserver + ".remotemanager", "name"))); postageConfiguration.setTestserverRemoteManagerPassword(configuration .getString(getAttributedPropertyName(scenarioTestserver + ".remotemanager", "password"))); postageConfiguration.setTestserverSpamAccountUsername(configuration .getString(getAttributedPropertyName(scenarioTestserver + ".spam-account", "name"))); postageConfiguration.setTestserverSpamAccountPassword(configuration .getString(getAttributedPropertyName(scenarioTestserver + ".spam-account", "password"))); postageConfiguration.setTestserverPortJMXRemoting(configuration .getInt(getAttributedPropertyName(scenarioTestserver + ".jvm-resources", "jmx-remoting-port"))); addSendProfiles(postageConfiguration, configuration, scenario); postageConfigurations.put(postageConfiguration.getId(), postageConfiguration); scenarioCount++; } return postageConfigurations; }
From source file:org.apache.james.postage.configuration.ConfigurationLoader.java
private void addMailSender(SendProfile profile, Configuration configuration, String profilePath) { List<String> mailSenders = configuration.getList(profilePath + ".send[@count-per-min]"); Iterator<String> mailSenderIter = mailSenders.iterator(); int mailSenderCount = 0; while (mailSenderIter.hasNext()) { mailSenderIter.next(); // ignore String mailSenderPath = getIndexedPropertyName(profilePath + ".send", mailSenderCount); MailSender mailSender = new MailSender(profile); mailSender.setSubject(configuration.getString(getAttributedPropertyName(mailSenderPath, "subject"), "Apache JAMES Postage test mail")); mailSender.setSendPerMinute(// w w w .j a v a 2 s. c om configuration.getInt(getAttributedPropertyName(mailSenderPath, "count-per-min"))); mailSender.setSizeMinText( configuration.getInt(getAttributedPropertyName(mailSenderPath, "text-size-min"), 0)); mailSender.setSizeMaxText( configuration.getInt(getAttributedPropertyName(mailSenderPath, "text-size-max"), 0)); mailSender.setSizeMinBinary( configuration.getInt(getAttributedPropertyName(mailSenderPath, "binary-size-min"), 0)); mailSender.setSizeMaxBinary( configuration.getInt(getAttributedPropertyName(mailSenderPath, "binary-size-max"), 0)); mailSender.setMailFactoryClassname( configuration.getString(getAttributedPropertyName(mailSenderPath, "mail-factory-class"), null)); profile.addMailSender(mailSender); mailSenderCount++; } }
From source file:org.apache.marmotta.loader.hbase.HBaseLoaderBackend.java
/** * Create the RDFHandler to be used for bulk-loading, optionally using the configuration passed as argument. * * @param configuration// ww w.java 2 s.c om * @return a newly created RDFHandler instance */ @Override public LoaderHandler createLoader(Configuration configuration) { Configuration titanCfg = new MapConfiguration(new HashMap<String, Object>()); titanCfg.setProperty("storage.backend", "hbase"); //titanCfg.setProperty("storage.batch-loading", true); if (configuration.containsKey("backend.hbase.host")) { titanCfg.setProperty("storage.hostname", configuration.getString("backend.hbase.host")); } if (configuration.containsKey("backend.hbase.port")) { titanCfg.setProperty("storage.port", configuration.getInt("backend.hbase.port")); } if (configuration.containsKey("backend.hbase.table")) { titanCfg.setProperty("storage.tablename", configuration.getString("backend.hbase.table")); } titanCfg.setProperty("ids.block-size", configuration.getInt("backend.hbase.id-block-size", 500000)); titanCfg.setProperty("storage.buffer-size", 100000); return new TitanLoaderHandler(titanCfg); }
From source file:org.apache.tamaya.commons.CommonsConfigPropertySource.java
public CommonsConfigPropertySource(String name, Configuration commonsConfig) { this.commonsConfig = Objects.requireNonNull(commonsConfig); this.name = Objects.requireNonNull(name); try {/*from w w w.j ava 2 s .c o m*/ this.ordinal = commonsConfig.getInt(PropertySource.TAMAYA_ORDINAL); } catch (Exception e) { this.ordinal = 0; } }