List of usage examples for org.apache.commons.configuration Configuration getInt
int getInt(String key);
From source file:org.apache.whirr.service.solr.SolrClusterActionHandler.java
@Override protected void beforeStop(ClusterActionEvent event) throws IOException { ClusterSpec clusterSpec = event.getClusterSpec(); Configuration config = getConfiguration(clusterSpec, SOLR_DEFAULT_CONFIG); int jettyStopPort = config.getInt(SOLR_JETTY_STOP_PORT); String stopFunc = getStopFunction(config, getRole(), "stop_" + getRole()); LOG.info("Stopping Solr"); addStatement(event, call(stopFunc, SOLR_HOME, String.valueOf(jettyStopPort), safeSecretString(config.getString(SOLR_JETTY_STOP_SECRET)), SOLR_HOME + "/example/start.jar")); }
From source file:org.apache.wookie.helpers.WidgetKeyManager.java
/** * Registers a new API key and notifies the requestor via email of the key values. * /*from w w w. j av a 2 s . co m*/ * @param key * @param domain * @throws EmailException if there is a problem sending the email notification about this key * @throws SystemUnavailableException if there is a problem generating the key */ public static void createKey(HttpServletRequest request, String email, Messages localizedMessages) throws SystemUnavailableException, EmailException { IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager(); HttpSession session = request.getSession(true); String username = (String) session.getAttribute("userName"); IStoreUser isu = null; if (username != null) isu = persistenceManager.getStoreUser(username); int userid = (isu != null) ? isu.getId() : 0; IApiKey key = persistenceManager.newInstance(IApiKey.class); key.setEmail(email); key.setUserId(userid); // generate a nonce RandomGUID r = new RandomGUID(); String nonce = "nonce-" + r.toString(); //$NON-NLS-1$ // now use SHA hash on the nonce String hashKey = HashGenerator.getInstance().encrypt(nonce + email); // get rid of any chars that might upset a url... hashKey = hashKey.replaceAll("=", ".eq."); //$NON-NLS-1$ //$NON-NLS-2$ hashKey = hashKey.replaceAll("\\?", ".qu."); //$NON-NLS-1$ //$NON-NLS-2$ hashKey = hashKey.replaceAll("&", ".am."); //$NON-NLS-1$ //$NON-NLS-2$ hashKey = hashKey.replaceAll("\\+", ".pl."); //$NON-NLS-1$ //$NON-NLS-2$ key.setValue(hashKey); persistenceManager.save(key); //insert a new entry to apiKeyWidgets table /*try { persistenceManager.commit(); }catch (PersistenceCommitException pce){ System.out.println("commit failed"); pce.printStackTrace(); } */ System.out.println("1"); IApiKey[] keyJustEntered = persistenceManager.findByValue(IApiKey.class, "value", hashKey); System.out.println("2"); Integer apiKeyId = new Integer(keyJustEntered[0].getId().toString()); System.out.println("key just entered" + apiKeyId); System.out.println("WidgetKeyManager createKey() apiKeyId=" + apiKeyId.intValue()); //JPAPersistenceManager.terminate(); //persistenceManager.begin(); //IApikeyWidget apiW = persistenceManager.newInstance(IApikeyWidget.class); ApikeyWidgetImpl apiW = new ApikeyWidgetImpl(); apiW.setAPIkeyID(apiKeyId.intValue()); apiW.setWidgetId(0);//set 0 as default to allow access to all widgets persistenceManager.save(apiW); System.out.println("4"); /*try { persistenceManager.commit(); System.out.println("commited"); }catch (PersistenceCommitException pce){ System.out.println("commit failed"); pce.printStackTrace(); }*/ String message = localizedMessages.getString("WidgetKeyManager.0") + hashKey + " \n"; //$NON-NLS-1$//$NON-NLS-2$ message += "\n" + localizedMessages.getString("WidgetKeyManager.1"); //$NON-NLS-1$ //$NON-NLS-2$ Configuration properties = (Configuration) request.getSession().getServletContext() .getAttribute("properties"); //$NON-NLS-1$ String server = properties.getString("widget.email.server"); int port = properties.getInt("widget.email.port"); String contact = properties.getString("widget.email.contact"); System.out.println("API hashKey=" + hashKey); //sendEmail(server, port, contact, email, message, properties.getString("widget.email.username"), properties.getString("widget.email.password")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ }
From source file:org.apache.wookie.proxy.ConnectionsPrefsManager.java
public static void setProxySettings(HttpClient client, Configuration properties) { if (!fParsedFile) init(properties); // just do this once - will have to reboot for changes to take effect HostConfiguration hConf = client.getHostConfiguration(); hConf.setProxy("wwwcache.open.ac.uk", 80); //client.s/* ww w. jav a 2 s .co m*/ if (isProxyServerSet()) { int port; try { port = properties.getInt("widget.proxy.port"); } catch (Exception ex) { port = 8080; // default for now if not specified } String username = properties.getString("widget.proxy.username"); String password = properties.getString("widget.proxy.password"); hConf = client.getHostConfiguration(); hConf.setProxy(fHostname, port); hConf.setProxy("wwwcache.open.ac.uk", 80); //AuthScope scopeProxy = new AuthScope(fHostname,port , AuthScope.ANY_REALM); // if(fUseNTLMAuthentication){ // String domain = System.getenv("USERDOMAIN"); //$NON-NLS-1$ // String computerName = System.getenv("COMPUTERNAME");//$NON-NLS-1$ // if (domain!=null && computerName!=null){ // NTCredentials userNTLMCredentials = new NTCredentials(username, password, computerName, domain); // client.getState().setProxyCredentials(scopeProxy, userNTLMCredentials); // } // else { // fLogger.error("Cannot find domain or computername for NTLM proxy authentication"); // } // } // else{ // client.getState().setProxyCredentials(scopeProxy, new UsernamePasswordCredentials(username, password)); // } } }
From source file:org.bhave.experiment.data.producer.AbstractDataProducer.java
/** * Produces the data using the same order of the * {@link Statistics#getColumnNames()/* ww w. ja va2 s . c om*/ * }. * * The order of the statistics objects is also taken into account. * * @param model * the model from which the properties were measured * @param props * a set of properties with statistics measured from the model * * @return a string using a semi-column separation for the data values */ protected String produceCSVData(Model model, Properties props) { Configuration currentConfig = model.getConfiguration(); // assumes we use CombinedParameterSweep to construct the experiment // parameter space // the runs are also embeded in the configuration long step = model.getStep(); int cfgid = currentConfig.getInt(CombinedParameterSweep.CFG_ID_PARAM); int run = currentConfig.getInt(CombinedParameterSweep.RUN_PARAM); StringBuilder data = new StringBuilder(); // add first three properties data.append(cfgid).append(';'); data.append(run).append(';'); data.append(step).append(';'); // add the rest of the properties for (String key : this.getDataColumnNames()) { data.append(props.getProperty(key)).append(';'); } return data.toString(); }
From source file:org.bhave.network.model.impl.DefaultBAForestModel.java
@Override public void configure(Configuration configuration) throws ConfigurationException { int numNodes = configuration.getInt(PARAM_NUM_NODES); if (numNodes < 2) { throw new ConfigurationException("numNodes must be >= 2"); }//from w w w.j a v a 2s .c om }
From source file:org.bhave.network.model.impl.DefaultBAModel.java
@Override public void configure(Configuration configuration) throws ConfigurationException { int numNodes = configuration.getInt(PARAM_NUM_NODES); int d = configuration.getInt(PARAM_MIN_DEG); if (numNodes < 2 || d < 1) { throw new ConfigurationException(PARAM_NUM_NODES + " must be >= 2 && d >= 1"); }/* w w w . ja v a 2 s . c o m*/ }
From source file:org.bhave.network.model.impl.DefaultKRegularModel.java
@Override public void configure(Configuration configuration) throws ConfigurationException { int numNodes = configuration.getInt(NUM_NODES_PARAM); int k = configuration.getInt(K_PARAM); if (numNodes < 0) { throw new ConfigurationException(NUM_NODES_PARAM + " must be > 0"); }// w w w. j a v a 2s . c om if (k < 1 || k > (numNodes / 2)) { throw new ConfigurationException(K_PARAM + " must be within 1 <= k <= (" + NUM_NODES_PARAM + ") / 2"); } }
From source file:org.bhave.sweeper.CombinedParameterSweepTest.java
@Test public void test() { IntegerSequenceSweep sweep1 = new IntegerSequenceSweep("p1", 0, -1, -1); assertEquals(2, sweep1.size());//w w w.ja va 2s . com IntegerSequenceSweep sweep2 = new IntegerSequenceSweep("p2", 0, 2, 1); assertEquals(3, sweep2.size()); IntegerSequenceSweep sweep3 = new IntegerSequenceSweep("p3", 0, 2, 1); assertEquals(3, sweep3.size()); SingleValueSweep<Integer> sweep4 = new SingleValueSweep<>("p4", 1); List<ParameterSweep> params = new LinkedList<>(); params.add(sweep1); params.add(sweep2); params.add(sweep3); params.add(sweep4); CombinedParameterSweep paramSpace = new DefaultCombinedParameterSweep(params, 1); assertEquals(sweep1.size() * sweep2.size() * sweep3.size(), paramSpace.size()); for (Configuration config : paramSpace) { System.out.println( "[" + config.getInt("p1") + "," + config.getInt("p2") + "," + config.getInt("p3") + "]"); } }
From source file:org.bhave.sweeper.CombinedParameterSweepTest.java
@Test public void testMultipleRuns() { System.out.println("Test: multiple runs"); SingleValueSweep<Integer> sweep = new SingleValueSweep<>("p1", 1); IntegerSequenceSweep sweepSeq = new IntegerSequenceSweep("p2", 0, -1, -1); List<ParameterSweep> params = new LinkedList<>(); params.add(sweep);/* w ww .j av a 2 s . co m*/ params.add(sweepSeq); DefaultCombinedParameterSweep paramSpace = new DefaultCombinedParameterSweep(params, 7); for (Configuration config : paramSpace) { System.out.println("CFG_ID:" + config.getInt(CombinedParameterSweep.CFG_ID_PARAM)); System.out.println("RUN: " + config.getInt(DefaultCombinedParameterSweep.RUN_PARAM)); System.out.println("[" + config.getInt("p1") + "," + config.getInt("p2") + "]"); } assertEquals((sweep.size() * sweepSeq.size()) * 7, paramSpace.size()); }
From source file:org.bhave.sweeper.impl.DefaultCombinedParameterSweep.java
/** * This creates a file to store the configuration ids and the respective * parameter values for each configuration * * the file also has a header with the parameter names * * @param filename/*from w ww .jav a2 s . com*/ * @return * @throws java.io.IOException */ @Override public File writeSweepFile(String filename) throws IOException { File file = new File(filename); BufferedWriter writer; writer = new BufferedWriter(new FileWriter(file)); Iterator<Configuration> paramIT = this.iterator(); StringBuilder sb = new StringBuilder(CombinedParameterSweep.CFG_ID_PARAM); sb.append(';'); List<ParameterSweep> parameters = this.getParameterSweeps(); for (ParameterSweep sweep : parameters) { sb.append(sweep.getParameterName()).append(';'); } writer.write(sb.toString()); writer.newLine(); int i = 0; while (paramIT.hasNext()) { Configuration cfg = paramIT.next(); if (i == 0) { sb = new StringBuilder(); sb.append(cfg.getInt(CombinedParameterSweep.CFG_ID_PARAM)); sb.append(';'); for (ParameterSweep sweep : parameters) { String param = sweep.getParameterName(); sb.append(cfg.getProperty(param).toString()).append(';'); } writer.write(sb.toString()); writer.newLine(); } i = (i + 1) % runs; } writer.close(); return file; }