List of usage examples for org.apache.commons.configuration Configuration getDouble
Double getDouble(String key, Double defaultValue);
From source file:edu.berkeley.sparrow.examples.ProtoFrontendAsync.java
public static void main(String[] args) { try {//from w ww .j a v a 2s . com OptionParser parser = new OptionParser(); parser.accepts("c", "configuration file").withRequiredArg().ofType(String.class); parser.accepts("help", "print help statement"); OptionSet options = parser.parse(args); if (options.has("help")) { parser.printHelpOn(System.out); System.exit(-1); } // Logger configuration: log to the console BasicConfigurator.configure(); LOG.setLevel(Level.DEBUG); Configuration conf = new PropertiesConfiguration(); if (options.has("c")) { String configFile = (String) options.valueOf("c"); conf = new PropertiesConfiguration(configFile); } Random r = new Random(); double lambda = conf.getDouble("job_arrival_rate_s", DEFAULT_JOB_ARRIVAL_RATE_S); int tasksPerJob = conf.getInt("tasks_per_job", DEFAULT_TASKS_PER_JOB); int benchmarkIterations = conf.getInt("benchmark.iterations", DEFAULT_BENCHMARK_ITERATIONS); int benchmarkId = conf.getInt("benchmark.id", DEFAULT_TASK_BENCHMARK); int schedulerPort = conf.getInt("scheduler_port", SchedulerThrift.DEFAULT_SCHEDULER_THRIFT_PORT); TProtocolFactory factory = new TBinaryProtocol.Factory(); TAsyncClientManager manager = new TAsyncClientManager(); long lastLaunch = System.currentTimeMillis(); // Loop and generate tasks launches while (true) { // Lambda is the arrival rate in S, so we need to multiply the result here by // 1000 to convert to ms. long delay = (long) (generateInterarrivalDelay(r, lambda) * 1000); long curLaunch = lastLaunch + delay; long toWait = Math.max(0, curLaunch - System.currentTimeMillis()); lastLaunch = curLaunch; if (toWait == 0) { LOG.warn("Generated workload not keeping up with real time."); } List<TTaskSpec> tasks = generateJob(tasksPerJob, benchmarkId, benchmarkIterations); TUserGroupInfo user = new TUserGroupInfo(); user.setUser("*"); user.setGroup("*"); TSchedulingRequest req = new TSchedulingRequest(); req.setApp("testApp"); req.setTasks(tasks); req.setUser(user); TNonblockingTransport tr = new TNonblockingSocket("localhost", schedulerPort); SchedulerService.AsyncClient client = new SchedulerService.AsyncClient(factory, manager, tr); //client.registerFrontend("testApp", new RegisterCallback()); client.submitJob(req, new SubmitCallback(req, tr)); } } catch (Exception e) { LOG.error("Fatal exception", e); } }
From source file:com.boozallen.cognition.ingest.storm.spout.StormKafkaSpout.java
@Override public void configure(Configuration conf) { spoutConfig = getSpoutConfig(conf);//from ww w . j av a2 s. c o m permitsPerSecond = conf.getDouble(PERMITS_PER_SECOND, DEFAULT_PERMITS_PER_SECOND); }
From source file:com.germinus.easyconf.ComponentProperties.java
protected static Object getTypedPropertyWithDefault(String key, Class theClass, Configuration properties, Object defaultValue) {/*w w w .ja v a 2 s . co m*/ if (theClass.equals(Float.class)) { return properties.getFloat(key, (Float) defaultValue); } else if (theClass.equals(Integer.class)) { return properties.getInteger(key, (Integer) defaultValue); } else if (theClass.equals(String.class)) { return properties.getString(key, (String) defaultValue); } else if (theClass.equals(Double.class)) { return properties.getDouble(key, (Double) defaultValue); } else if (theClass.equals(Long.class)) { return properties.getLong(key, (Long) defaultValue); } else if (theClass.equals(Boolean.class)) { return properties.getBoolean(key, (Boolean) defaultValue); } else if (theClass.equals(List.class)) { return properties.getList(key, (List) defaultValue); } else if (theClass.equals(BigInteger.class)) { return properties.getBigInteger(key, (BigInteger) defaultValue); } else if (theClass.equals(BigDecimal.class)) { return properties.getBigDecimal(key, (BigDecimal) defaultValue); } else if (theClass.equals(Byte.class)) { return properties.getByte(key, (Byte) defaultValue); } else if (theClass.equals(Short.class)) { return properties.getShort(key, (Short) defaultValue); } throw new IllegalArgumentException("Class " + theClass + " is not" + "supported for properties"); }
From source file:net.sf.jclal.activelearning.scenario.StreamBasedSelectiveSamplingScenario.java
/** * * @param configuration The configuration of Stream Scenario. * The XML labels supported are:/*from w w w.j ava 2 s . c o m*/ * <ul> * <li><b>threshold= double</b></li> * </ul> */ @Override public void configure(Configuration configuration) { super.configure(configuration); //Set threshold double thresholdT = configuration.getDouble("threshold", threshold); setThreshold(thresholdT); }
From source file:com.cisco.oss.foundation.directory.config.ServiceDirectoryConfigTest.java
@Test public void testGetProperty() { Configuration config = ServiceDirectory.getServiceDirectoryConfig(); assertFalse(config.getBoolean("ddd")); assertTrue(config.getDouble("notexists", 89.1) == 89.1); try {//w ww. j av a 2s. c o m config.getDouble("notexists"); } catch (Exception e) { assertTrue(e instanceof NoSuchElementException); } assertFalse(config.containsKey("not_property")); }
From source file:net.sf.jclal.activelearning.scenario.StreamBasedOnlineSelectiveSamplingScenario.java
/** * * @param configuration/*from www. j a v a 2 s. c o m*/ * The configuration of Stream Scenario. The XML labels supported * are: * <ul> * <li><b>threshold= double</b></li> * </ul> */ @Override public void configure(Configuration configuration) { super.configure(configuration); // Set threshold double thresholdT = configuration.getDouble("threshold", threshold); setThreshold(thresholdT); }
From source file:net.sf.jclal.sampling.AbstractSampling.java
/** * * @param configuration The configuration object for Abstract sampling. * <p>//from w w w .java 2 s. com * <b>percentage-to-select= double</b></p> */ @Override public void configure(Configuration configuration) { double percentageInstancesToLabelledTemp = configuration.getDouble("percentage-to-select", 10); String perc = "\n<percentage-to-select>" + percentageInstancesToLabelledTemp + "</percentage-to-select>"; if (percentageInstancesToLabelledTemp <= 0) { throw new ConfigurationRuntimeException(perc + ". percentage-to-select > 0"); } if (percentageInstancesToLabelledTemp > 100) { throw new ConfigurationRuntimeException(perc + ". percentage-to-select <= 100"); } setPercentageInstancesToLabelled(percentageInstancesToLabelledTemp); }
From source file:com.boozallen.cognition.ingest.storm.bolt.logging.LogRecordDateBolt.java
@Override public void configure(Configuration conf) throws ConfigurationException { super.configure(conf); dateFormat = conf.getString(DATE_FORMAT, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); sample = conf.getDouble(SAMPLE, 0.01); Validate.notBlank(dateFormat);/*w w w. java 2s. c om*/ validateDateFormat(); }
From source file:com.google.api.ads.adwords.keywordoptimizer.DefaultRoundStrategy.java
/** * Creates a new {@link DefaultRoundStrategy} and takes its parameters from a property file. *///from w w w.j av a 2 s.co m public DefaultRoundStrategy(OptimizationContext context) { Configuration config = context.getConfiguration(); maxNumberOfSteps = config.getInt(KeywordOptimizerProperty.RoundStrategyMaxSteps.getName(), 10); minImprovementBetweenSteps = config .getDouble(KeywordOptimizerProperty.RoundStrategyMinImprovementBetweenSteps.getName(), 0); maxPopulationSize = config.getInt(KeywordOptimizerProperty.RoundStrategyMaxPopulation.getName(), 100); maxNumberOfAlternatives = config.getInt(KeywordOptimizerProperty.RoundStrategyReplicateBest.getName(), 10); lastAvgScore = null; }
From source file:net.sf.jclal.evaluation.method.HoldOut.java
/** * @param configuration The configuration of Hold Out. * *The XML labels supported are:/*from ww w .jav a2 s . com*/ * * <ul> * <li><b>percentage-split= double</b></li> * </ul> */ @Override public void configure(Configuration configuration) { super.configure(configuration); // the percent of instances used to train double percentTrain = configuration.getDouble("percentage-split", percentageToSplit); String perc = "\n<percentage-split>" + percentTrain + "</percentage-split>"; if (percentTrain <= 0) { throw new ConfigurationRuntimeException(perc + ". percentage-split > 0"); } if (percentTrain >= 100) { throw new ConfigurationRuntimeException(perc + ". percentage-split < 100"); } setPercentageToSplit(percentTrain); }