List of usage examples for org.apache.commons.configuration SubnodeConfiguration getInt
public int getInt(String key)
From source file:com.hipstogram.context.config.sections.ServerSection.java
public ServerSection(SubnodeConfiguration server) { this.port = server.getInt("port"); }
From source file:com.hipstogram.context.config.sections.KafkaSection.java
public KafkaSection(SubnodeConfiguration kafka) { this.port = kafka.getInt("port"); this.host = kafka.getString("host"); }
From source file:com.hipstogram.storm.context.config.sections.KafkaSection.java
public KafkaSection(SubnodeConfiguration kafka) { this.port = kafka.getInt("port"); this.host = kafka.getString("host"); this.topic = kafka.getString("topic"); }
From source file:com.hipstogram.context.config.sections.CassandraSection.java
public CassandraSection(SubnodeConfiguration cassandra) { this.port = cassandra.getInt("port"); this.host = cassandra.getString("host"); }
From source file:com.hipstogram.context.config.sections.MongoDBSection.java
public MongoDBSection(SubnodeConfiguration cassandra) { this.port = cassandra.getInt("port"); this.host = cassandra.getString("host"); }
From source file:com.hipstogram.context.config.sections.ZookeeperSection.java
public ZookeeperSection(SubnodeConfiguration zookeeper) { this.port = zookeeper.getInt("port"); this.host = zookeeper.getString("host"); }
From source file:com.versatus.jwebshield.securitylock.SecurityCheckListener.java
/** * @see ServletContextListener#contextInitialized(ServletContextEvent) *///ww w.jav a 2 s. c o m @Override public void contextInitialized(ServletContextEvent sce) { String file = sce.getServletContext().getInitParameter("configFile"); if (file != null) { try { XMLConfiguration config = new XMLConfiguration(file); SubnodeConfiguration fields = config.configurationAt("securityLock"); int triesToLock = fields.getInt("triesToLock"); // lockSql = fields.getString("lockSql"); // dbJndiName = fields.getString("dbJndiName"); timeToLock = fields.getInt("timeToLockMin"); // lockCheckSql = fields.getString("lockCheckSql"); DBHelper dbh = new DBHelper(config); securityLockService = new SecurityLockService(dbh, config); securityLockService.setTriesToLock(triesToLock); // logger.info("contextInitialized: lockCheckInterval=" // + lockCheckInterval); logger.info("contextInitialized: timeToLock=" + timeToLock); // logger.info("contextInitialized: lockSql=" + lockSql); // logger.info("contextInitialized: lockCheckSql=" + // lockCheckSql); // logger.info("contextInitialized: dbJndiName=" + dbJndiName); } catch (Exception cex) { logger.error("init: unable to load configFile " + file, cex); } } else { logger.error("init: No configFile specified"); } // TimerTask lockCheckTimer = new LockCheckTimerTask(); // timer.schedule(lockCheckTimer, 10000, (lockCheckInterval * 60 * // 1000)); }
From source file:com.oltpbenchmark.benchmarks.smallworldbank.SWBankWorker.java
@SuppressWarnings("unchecked") @Override/* w w w .ja v a 2s . co m*/ protected TransactionStatus executeWork(TransactionType txnType) throws UserAbortException, SQLException { // LOG.info("Num Proc. "+Runtime.getRuntime().availableProcessors()); long txid = -1; boolean isMalicous = false; try { if (txnType.getProcedureClass().equals(Balance.class)) { // LOG.info("Executing Balance transaction"); Balance proc = getProcedure(Balance.class); assert (proc != null); long acctId = rdg.nextLong(acctIdMin + 1, acctIdMax); // LOG.info("Executing "+txnType.getProcedureClass().getName()); proc.run(conn, acctId); AIMSLogger.logTransactionSpecs(1, String.format("%d,%d", acctId, this.getId())); } else if (txnType.getProcedureClass().equals(SendPayment.class) || txnType.getProcedureClass().equals(MSendPayment.class)) { if (txnType.getProcedureClass().equals(MSendPayment.class)) { isMalicous = true; } // generate random parameters long srcCustId = rdg.nextLong(custIdMin, custIdMax); long destCustId = rdg.nextLong(custIdMin, custIdMax); // make sure that it is not a self transfer while (destCustId == srcCustId) { destCustId = rdg.nextLong(custIdMin, custIdMax); } if (lastCustId > 0) { // this is not the first transaction // executed int coinflip = rdg.nextBinomial(1, tdp); if (coinflip == 1) { // connect srcCustId = lastCustId; // LOG.info(String.format("coinflip = %d",coinflip)); } } float balv = (float) rdg.nextUniform(0, 1) * 100; SendPayment proc = getProcedure(SendPayment.class); assert (proc != null); // LOG.info("Executing "+txnType.getProcedureClass().getName()); txid = proc.run(conn, srcCustId, destCustId, balv, isMalicous); // lastCustIds.add(destCustId); lastCustId = srcCustId; AIMSLogger.logTransactionSpecs(2, String.format("%d,%d,%3f,%d", srcCustId, destCustId, balv, this.getId())); } else if (txnType.getProcedureClass().equals(Distribute.class) || txnType.getProcedureClass().equals(MDistribute.class)) { List<SubnodeConfiguration> sncs = this.getBenchmarkModule().getWorkloadConfiguration() .getXmlConfig().configurationsAt("transactiontypes/transactiontype[name='Distribute']"); if (txnType.getProcedureClass().equals(MDistribute.class)) { isMalicous = true; } if (sncs.size() != 1) { throw new RuntimeException("Duplicate transaction types: Distribute"); } assert (sncs.size() == 1); // LOG.info("size of sncs:"+sncs.size()); SubnodeConfiguration snc = sncs.get(0); int fanout_min = snc.getInt("fanout_min"); int fanout_max = snc.getInt("fanout_max"); // int fanout_mu = snc.getInt("fanout_mu"); // int fanout_sigma = snc.getInt("fanout_sigma"); int fanout_n = snc.getInt("fanout_n"); double fanout_p = snc.getDouble("fanout_p"); // LOG.info("Distribute:" + snc.getInt("fanout_mu")); // LOG.info("Distribute:" + snc.getInt("fanout_sigma")); // LOG.info(String.format("n = %d, p= %f",fanout_n, fanout_p)); int fanout_val = rdg.nextBinomial(fanout_n, fanout_p); // LOG.info(String.format("max = %d, min= %d", fanout_max, // fanout_min)); // int fanout_val = rdg.nextInt(fanout_min, fanout_max); // LOG.info("here"); if (fanout_val < fanout_min) { fanout_val = fanout_min; } if (fanout_val > fanout_max) { fanout_val = fanout_max; } // LOG.info("Random Fanout = " + fanout_val); long[] accIds = nextDistinctKLongs(acctIdMin, acctIdMax, fanout_val + 1); long[] dest_accids = Arrays.copyOfRange(accIds, 1, accIds.length); double[] dest_vals = nextKDoubles(0, 1, 100, fanout_val); Distribute proc = getProcedure(Distribute.class); txid = proc.run(conn, accIds[0], dest_accids, dest_vals, isMalicous); // LOG.info(snc.getString("name")); // LOG.info(snc.getInt("id")); // if (snc.getString("name").equalsIgnoreCase("Distribute")) { // LOG.info("Distribute:" + snc.getInt("fanin")); // LOG.info("Distribute:" + snc.getInt("fanout")); // } StringBuilder sb1 = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); for (int i = 0; i < dest_vals.length; i++) { if (i != 0) { sb1.append(':'); sb2.append(':'); } sb1.append(dest_accids[i]); sb2.append(String.format("%3f", dest_vals[i])); } AIMSLogger.logTransactionSpecs(3, String.format("%d,%s,%s,%d", accIds[0], sb1.toString(), sb2.toString(), this.getId())); } else if (txnType.getProcedureClass().equals(Collect.class) || txnType.getProcedureClass().equals(MCollect.class)) { if (txnType.getProcedureClass().equals(MCollect.class)) { isMalicous = true; } List<SubnodeConfiguration> sncs = this.getBenchmarkModule().getWorkloadConfiguration() .getXmlConfig().configurationsAt("transactiontypes/transactiontype[name='Collect']"); if (sncs.size() != 1) { throw new RuntimeException("Duplicate transaction types: Collect"); } assert (sncs.size() == 1); SubnodeConfiguration snc = sncs.get(0); int fanin_min = snc.getInt("fanin_min"); int fanin_max = snc.getInt("fanin_max"); int fanin_n = snc.getInt("fanin_n"); double fanin_p = snc.getDouble("fanin_p"); int fanin_val = rdg.nextBinomial(fanin_n, fanin_p); if (fanin_val < fanin_min) { fanin_val = fanin_min; } if (fanin_val > fanin_max) { fanin_val = fanin_max; } // LOG.info("Random Fanin = " + fanin_val); long[] accIds = nextDistinctKLongs(acctIdMin, acctIdMax, fanin_val + 1); long[] src_accids = Arrays.copyOfRange(accIds, 1, accIds.length); double[] src_vals = nextKDoubles(0, 1, 100, fanin_val); Collect proc = getProcedure(Collect.class); txid = proc.run(conn, src_accids, accIds[0], src_vals, isMalicous); StringBuilder sb1 = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); for (int i = 0; i < src_vals.length; i++) { if (i != 0) { sb1.append(':'); sb2.append(':'); } sb1.append(src_accids[i]); sb2.append(String.format("%3f", src_vals[i])); } AIMSLogger.logTransactionSpecs(4, String.format("%s,%d,%s,%d", sb1.toString(), accIds[0], sb2.toString(), this.getId())); } else if (txnType.getProcedureClass().equals(ReportCheckingPerBranch.class)) { ReportCheckingPerBranch proc = getProcedure(ReportCheckingPerBranch.class); long b_count = (Math.round( SWBankConstants.BRANCH_PER_COUNTRY * this.getWorkloadConfiguration().getScaleFactor()) * 100); // LOG.info("CHECK: b_count = "+b_count); proc.run(conn, b_count); } else if (txnType.getProcedureClass().equals(ReportCheckingPerBranch2.class)) { ReportCheckingPerBranch2 proc = getProcedure(ReportCheckingPerBranch2.class); long b_count = (Math.round( SWBankConstants.BRANCH_PER_COUNTRY * this.getWorkloadConfiguration().getScaleFactor()) * 100); // LOG.info("CHECK: b_count = "+b_count); proc.run(conn, b_count); } else if (txnType.getProcedureClass().equals(ReportSavingPerBranch.class)) { ReportSavingPerBranch proc = getProcedure(ReportSavingPerBranch.class); long b_count = (Math.round( SWBankConstants.BRANCH_PER_COUNTRY * this.getWorkloadConfiguration().getScaleFactor()) * 100); // LOG.info("SAV: b_count = "+b_count); proc.run(conn, b_count); } else if (txnType.getProcedureClass().equals(ReportActiveCustomers.class)) { ReportActiveCustomers proc = getProcedure(ReportActiveCustomers.class); proc.run(conn); } else if (txnType.getProcedureClass().equals(ListCountries.class)) { ListCountries proc = getProcedure(ListCountries.class); proc.run(conn); } else { throw new InvalidTransactionTypeException( "Invalid transaction type: " + txnType.getProcedureClass().getName()); } } catch (InvalidTransactionTypeException e) { e.printStackTrace(); return TransactionStatus.RETRY_DIFFERENT; } catch (RuntimeException e) { conn.rollback(); // LOG.info("Unknown transaction type"); e.printStackTrace(); return TransactionStatus.RETRY; } conn.commit(); // send ids message after commiting transaction if (isMalicous) { LOG.info(String.format("Sending alert in %d msec", mddelay)); exservice.schedule(new IDMessageSender(conn, txid), mddelay, TimeUnit.MILLISECONDS); } return TransactionStatus.SUCCESS; }
From source file:com.oltpbenchmark.multitenancy.schedule.Schedule.java
private HashMap<Integer, ScheduleEvents> parseEvents() { HashMap<Integer, ScheduleEvents> newMap = new HashMap<Integer, ScheduleEvents>(); try {//from w w w .j a v a 2 s.c o m // read config file XMLConfiguration xmlConfig = new XMLConfiguration(scenarioFile); xmlConfig.setExpressionEngine(new XPathExpressionEngine()); // iterate over all defined events and parse configuration int size = xmlConfig .configurationsAt(ScenarioConfigElements.EVENTS_KEY + "/" + ScenarioConfigElements.EVENT_KEY) .size(); for (int i = 1; i < size + 1; i++) { SubnodeConfiguration event = xmlConfig.configurationAt( ScenarioConfigElements.EVENTS_KEY + "/" + ScenarioConfigElements.EVENT_KEY + "[" + i + "]"); // create settings for a benchmark run BenchmarkSettings benchSettings = new BenchmarkSettings(event); // get schedule times long eventStart = 0, eventStop = -1, eventRepeat = -1; if (event.containsKey(ScenarioConfigElements.EVENT_START_KEY)) eventStart = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_START_KEY)); else LOG.debug("There is no start time defined for an event, it will be started immediately!"); if (event.containsKey(ScenarioConfigElements.EVENT_REPEAT_KEY)) eventRepeat = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_REPEAT_KEY)); if (event.containsKey(ScenarioConfigElements.EVENT_STOP_KEY)) eventStop = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_STOP_KEY)); // validate schedule times if (eventRepeat > -1 && eventStop == -1 && duration == -1) { LOG.fatal( "Infinitely event execution was defined: Repeated event without repeating end and scenario end"); System.exit(-1); } if (eventRepeat == 0) { LOG.fatal("An Event cannot be repeated simoultaneously (avoid infinite loop)!"); System.exit(-1); } if (eventStart > eventStop && eventStop != -1) { LOG.fatal("Event cannot be stopped until starting it!"); System.exit(-1); } // get tenant IDs int firstTenantID = 1, tenantsPerExecution = 1, tenantIdIncement = 1; if (event.containsKey(ScenarioConfigElements.FIRST_TENANT_ID_KEY)) firstTenantID = (event.getInt(ScenarioConfigElements.FIRST_TENANT_ID_KEY)); if (event.containsKey(ScenarioConfigElements.TENANTS_PER_EXECUTION_KEY)) tenantsPerExecution = (event.getInt(ScenarioConfigElements.TENANTS_PER_EXECUTION_KEY)); if (event.containsKey(ScenarioConfigElements.TENANT_ID_INCREMENT_KEY)) tenantIdIncement = (event.getInt(ScenarioConfigElements.TENANT_ID_INCREMENT_KEY)); // validate tenant IDs if (tenantsPerExecution < 0) { LOG.fatal("Value '" + tenantsPerExecution + "' for tenants per executions is not valid!"); System.exit(-1); } // execution times and assign to tenants if (duration != -1 && duration < eventStop) eventStop = duration; int exec = 0; long execTime = eventStart; while ((execTime <= eventStop) || (eventStop == -1 && exec == 0)) { // iterate over all tenants in this execution for (int j = 0; j < tenantsPerExecution; j++) { int currentTenantID = firstTenantID + (exec * tenantsPerExecution * tenantIdIncement) + (j * tenantIdIncement); if (!newMap.containsKey(currentTenantID)) { ScheduleEvents tenEvents = new ScheduleEvents(); tenEvents.addEvent(execTime, benchSettings); newMap.put(currentTenantID, tenEvents); tenantList.add(currentTenantID); } else newMap.get(currentTenantID).addEvent(execTime, benchSettings); } if (eventRepeat == -1) break; execTime += eventRepeat; exec++; } } } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } return newMap; }
From source file:org.accada.reader.rprm.core.ReaderDevice.java
/** * Resets all internal state variables of the reader to a default * configuration. The documentation of the reader shall provide a definition * what the default settings are/*from ww w . j av a 2 s . c o m*/ * @param propFile * The location of the property file * @throws ReaderProtocolException * "Reader not found", "Failed to read properties file", * "wrong valueTrigger in property file", "wrong edgeTrigger in * property file" */ public final void resetToDefaultSettings(final String propFile, final String defaultPropFile) throws ReaderProtocolException { // operational status is DOWN before resetting setOperStatus(OperationalStatus.DOWN); //init lists sources = new Hashtable(); dataSelectors = new Hashtable(); notificationChannels = new Hashtable(); triggers = new Hashtable(); tagSelectors = new Hashtable(); tagFields = new Hashtable(); readPoints = new Hashtable(); readers = new Hashtable<String, HardwareAbstraction>(); valueTriggers = new Hashtable(); edgeTriggers = new Hashtable(); currentSource = null; alarmChannels = new Hashtable<String, AlarmChannel>(); ioPorts = new Hashtable<String, IOPort>(); // properties XMLConfiguration conf; URL fileurl = ResourceLocator.getURL(propFile, defaultPropFile, this.getClass()); try { conf = new XMLConfiguration(fileurl); } catch (ConfigurationException e) { System.out.println(e.getMessage()); throw new ReaderProtocolException("Failed to read properties file (" + propFile + ")", MessagingConstants.ERROR_UNKNOWN); } // get properties setEPC(conf.getString("epc")); setName(conf.getString("name")); setManufacturer(conf.getString("manufacturer")); setManufacturerDescription(conf.getString("manufacturerDescription")); setModel(conf.getString("model")); setHandle(conf.getInt("handle")); setRole(conf.getString("role")); setMaxSourceNumber(conf.getInt("maxSourceNumber")); setMaxTagSelectorNumber(conf.getInt("maxTagSelectorNumber")); setMaxTriggerNumber(conf.getInt("maxTriggerNumber")); // get readers SubnodeConfiguration readerConf = conf.configurationAt("readers"); for (int i = 0; i <= readerConf.getMaxIndex("reader"); i++) { // key to current reader String key = "reader(" + i + ")"; // reader's name String readerName = readerConf.getString(key + ".name"); //System.out.println(readerName); // get reader if (!readers.containsKey(readerName)) { // reflection String rClass = readerConf.getString(key + ".class"); String prop = readerConf.getString(key + ".properties"); try { Class cls = Class.forName(rClass); Class[] partypes = new Class[] { String.class, String.class }; Constructor ct = cls.getConstructor(partypes); Object[] arglist = new Object[] { readerName, prop }; HardwareAbstraction ha = (HardwareAbstraction) ct.newInstance(arglist); readers.put(readerName, ha); } catch (Exception e) { log.error(e.getMessage() + "|" + e.getCause()); throw new ReaderProtocolException("Reader not found", MessagingConstants.ERROR_UNKNOWN); } } } // configure readpoints SubnodeConfiguration rpConf = conf.configurationAt("readers"); for (int i = 0; i <= rpConf.getMaxIndex("reader"); i++) { // key to current reader String key = "reader(" + i + ")"; // name of the reader String readerName = rpConf.getString(key + ".name"); // get reader HardwareAbstraction tempHardwareAbstraction = (HardwareAbstraction) readers.get(readerName); // get readpoints for (int j = 0; j <= rpConf.getMaxIndex(key + ".readpoint"); j++) { String rp = rpConf.getString(key + ".readpoint(" + j + ")"); // System.out.println(" "+rps[j]); AntennaReadPoint.create(rp, this, tempHardwareAbstraction); } } // configure sources SubnodeConfiguration sourceConf = conf.configurationAt("sources"); for (int i = 0; i <= sourceConf.getMaxIndex("source"); i++) { String key = "source(" + i + ")"; // name of the source String sourceName = sourceConf.getString(key + ".name"); // get source Source tempSource; if (!sources.containsKey(sourceName)) { tempSource = Source.create(sourceName, this); } else { tempSource = getSource(sourceName); } // fixed if (sourceConf.getString(key + ".fixed").equals("true")) { tempSource.setFixed(true); } else { tempSource.setFixed(false); } // reader's readpoints for (int j = 0; j <= sourceConf.getMaxIndex(key + ".readpoint"); j++) { String rp = sourceConf.getString(key + ".readpoint(" + j + ")"); // System.out.println(" "+rp); tempSource.addReadPoints(new ReadPoint[] { getReadPoint(rp) }); } } // set current Source setCurrentSource(getSource(conf.getString("currentSource"))); // set defaults setDefaults(); // get io triggers getIoTriggers(conf); // information used for the reader management implementation setDescription(conf.getString("description")); setLocationDescription(conf.getString("locationDescription")); setContact(conf.getString("contact")); serialNumber = conf.getString("serialNumber"); dhcpServerFinder .setMacAddress(DHCPServerFinder.macAddressStringToByteArray(conf.getString("macAddress"), "-")); operStatusAlarmControl = new TTOperationalStatusAlarmControl("OperStatusAlarmControl", false, AlarmLevel.ERROR, 0, OperationalStatus.ANY, OperationalStatus.ANY); freeMemoryAlarmControl = new EdgeTriggeredAlarmControl("FreeMemoryAlarmControl", false, AlarmLevel.CRITICAL, 0, 100, 1000, EdgeTriggeredAlarmDirection.FALLING); if ((alarmManager == null) && (mgmtAgent != null)) { AlarmProcessor alarmProcessor = null; switch (MessageLayer.mgmtAgentType) { case SNMP: alarmProcessor = new SnmpAlarmProcessor((SnmpAgent) mgmtAgent); break; // case ...: } alarmManager = new AlarmManager(alarmProcessor, this); alarmManager.start(); } // configure alarm channels SubnodeConfiguration alarmChanConf = conf.configurationAt("alarmChannels"); String host = ""; int port = -1; for (int i = 0; i <= alarmChanConf.getMaxIndex("alarmChannel"); i++) { String key = "alarmChannel(" + i + ")"; // name of the alarm channel String alarmChanName = alarmChanConf.getString(key + ".name"); // get alarm channel try { host = alarmChanConf.getString(key + ".host"); port = alarmChanConf.getInt(key + ".port"); try { AlarmChannel.create(alarmChanName, new Address("udp://" + host + ":" + port), this); } catch (MalformedURLException mfue) { log.error(alarmChanName + ": invalid address"); } host = ""; port = -1; } catch (ReaderProtocolException rpe) { // next } } // operational status is UP after resetting setOperStatus(OperationalStatus.UP); }