Example usage for org.apache.commons.configuration Configuration getInt

List of usage examples for org.apache.commons.configuration Configuration getInt

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getInt.

Prototype

int getInt(String key);

Source Link

Document

Get a int associated with the given configuration key.

Usage

From source file:es.bsc.demiurge.openstackjclouds.OpenStackJclouds.java

public OpenStackJclouds() {
    Configuration c = Config.INSTANCE.getConfiguration().subset(CONFIG_OPENSTACK_SUBSET_PREFIX);

    OpenStackCredentials credentials = new OpenStackCredentials(c.getString(OS_CONFIG_IP),
            c.getInt(OS_CONFIG_KEYSTONE_PORT), c.getString(OS_CONFIG_KEYSTONE_TENANT),
            c.getString(OS_CONFIG_KEYSTONE_USER), c.getString(OS_CONFIG_KEYSTONE_PASSWORD),
            c.getInt(OS_CONFIG_GLANCE_PORT), c.getString(OS_CONFIG_KEYSTONE_TENANT_ID));
    openStackJcloudsApis = new OpenStackJcloudsApis(credentials);

    zone = openStackJcloudsApis.getNovaApi().getConfiguredZones().toArray()[0].toString();
    this.securityGroups = c.getStringArray(OS_CONFIG_SECURITY_GROUPS);
    glanceConnector = new OpenStackGlance(credentials);
    this.hostNames.addAll(Arrays.asList(Config.INSTANCE.getConfiguration().getStringArray(CONFIG_HOSTS)));
    StringBuilder sb = new StringBuilder("Registering hostNames: ");
    for (String hn : hostNames) {
        sb.append('[').append(hn).append("], ");
    }//from w w  w  .j a v a 2 s .c  o m
    logger.info(sb.toString());
}

From source file:com.knowbout.epg.processor.Parser.java

@SuppressWarnings("unchecked")

public Parser(Configuration config, File headendFile, File lineupFile, File stationFile, File programFile,
        File scheduleFile) {// w  w w . java  2  s.  c  o  m
    this.headendFile = headendFile;
    this.lineupFile = lineupFile;
    this.stationFile = stationFile;
    this.programFile = programFile;
    this.scheduleFile = scheduleFile;
    this.config = config;
    //Get the transaction count.  This can affect the performance a lot
    Configuration transactions = config.subset("transactions");
    headendTransaction = transactions.getInt("headends");
    lineupTransaction = transactions.getInt("lineups");
    stationTransaction = transactions.getInt("stations");
    programTransaction = transactions.getInt("programs");
    stationNames = new HashMap<String, String>();
    List<String> names = config.getList("stationNames.station", new ArrayList<String>());
    List<String> callSigns = config.getList("stationNames.station[@callSign]", new ArrayList<String>());
    for (int i = 0; i < callSigns.size() && i < names.size(); i++) {
        stationNames.put(callSigns.get(i), names.get(i));
    }
}

From source file:es.udc.gii.common.eaf.factory.XMLSimpleFactory.java

@Override
public Individual createIndividual(FitnessComparator<Individual> comparator) {
    Configuration conf = EAFConfiguration.getInstance().subset("Population.Individual");

    try {//  ww w . j av  a  2  s.co  m
        Individual ind = (Individual) Class.forName(conf.getString("Class")).newInstance();

        List chromosomes = conf.getList("Chromosome[@size]");

        if (chromosomes.isEmpty()) {
            throw new ConfigurationException("No chromosome specified.");
        }

        DoubleArray[] chrms = new DoubleArray[chromosomes.size()];

        for (int i = 0; i < chromosomes.size(); i++) {
            int chrom_size = conf.getInt("Chromosome(" + i + ")[@size]");
            chrms[i] = new ResizableDoubleArray(chrom_size);
            for (int j = 0; j < chrom_size; j++) {
                chrms[i].addElement(0.0);
            }
        }

        ind.setChromosomes(chrms);
        ind.setComparator(comparator);
        ind.configure(conf);
        //            ind.generate();

        return ind;

    } catch (Exception ex) {
        throw new ConfigurationException("Wrong individual configuration for " + conf.getString("Class") + " ?"
                + " \n Thrown exception: \n" + ex);
    }
}

From source file:es.udc.gii.common.eaf.algorithm.EvolutionaryAlgorithm.java

@Override
public void configure(Configuration conf) {
    try {/*from  w w w.  j  ava 2 s . c om*/
        setComparator((FitnessComparator) Class.forName(conf.getString("Comparator")).newInstance());

        setUseCustomInitPopulation(conf.containsKey("UseCustomRandomInitPopulation"));

        setDebug(conf.containsKey("Debug"));

        if (conf.containsKey("FitnessHistoryCapacity")) {
            this.fitness_history_capacity = conf.getInt("FitnessHistoryCapacity");
            this.fitness_history = new ArrayList<Individual>();

        } else {
            this.fitness_history = null;
        }

    } catch (Exception ex) {

        System.exit(0);
    }
}

From source file:com.salesmanager.checkout.subscription.SubscriptionAction.java

private void prepareZones() {

    if (value != null && value.getProductId() > 0) {
        setCountries(RefUtil.getCountries(value.getLang()));

        if (this.customer == null) {

            customer = SessionUtil.getCustomer(getServletRequest());

            if (customer == null) {

                customer = new Customer();
                customer.setCustomerBillingCountryId(value.getCountryId());

            }//from  ww w .ja  v a 2s .  co m

        }

        customer.setLocale(getLocale());

        SessionUtil.setCustomer(customer, getServletRequest());

        Collection zones = RefUtil.getZonesByCountry(customer.getCustomerBillingCountryId(), value.getLang());

        if (zones != null && zones.size() > 0) {
            setZonesByCountry(zones);
        } else {
            setZone(customer.getBillingState());
        }

    } else {

        if (this.customer == null) {

            customer = SessionUtil.getCustomer(getServletRequest());

        }
        if (customer != null) {

            customer.setLocale(super.getLocale());

            setCountries(RefUtil.getCountries(super.getLocale().getLanguage()));

            Collection zones = RefUtil.getZonesByCountry(customer.getCustomerBillingCountryId(),
                    LocaleUtil.getDefaultLocale().getLanguage());

            if (zones != null && zones.size() > 0) {
                setZonesByCountry(zones);
            } else {
                setZone(customer.getBillingState());
            }
        } else {

            setCountries(RefUtil.getCountries(LocaleUtil.getDefaultLocale().getLanguage()));

            Configuration conf = PropertiesUtil.getConfiguration();
            int defaultCountry = conf.getInt("core.system.defaultcountryid");
            customer = new Customer();
            customer.setCustomerBillingCountryId(defaultCountry);
            customer.setLocale(super.getLocale());

            Collection zones = RefUtil.getZonesByCountry(customer.getCustomerBillingCountryId(),
                    LocaleUtil.getDefaultLocale().getLanguage());

            if (zones != null && zones.size() > 0) {
                setZonesByCountry(zones);
            } else {
                setZone(customer.getBillingState());
            }

            SessionUtil.setCustomer(customer, getServletRequest());

        }

    }

}

From source file:es.udc.gii.common.eaf.algorithm.mga.MMGAAlgorithm.java

/**
 * Configures the algorithm./*  w  w w. ja v a  2  s  . c  o  m*/
 */
@Override
public void configure(Configuration conf) {
    try {
        super.configure(conf);

        if (conf.containsKey("ParetoFrontReplaceOperator.Class")) {
            setParetoFrontReplaceOperator((ParetoFrontReplaceOperator) Class
                    .forName(conf.getString("ParetoFrontReplaceOperator.Class")).newInstance());
        } else {
            (new ConfWarning("MMGAAlgorithm.ParetoFrontReplaceOperator", "ParetoFrontReplaceOperator")).warn();
            setParetoFrontReplaceOperator(new ParetoFrontReplaceOperator());
        }

        getParetoFrontReplaceOperator().configure(conf.subset("ParetoFrontReplaceOperator"));

        if (conf.containsKey("PopulationMemorySize")) {
            setPopulationMemorySize(conf.getInt("PopulationMemorySize"));
        } else {
            int memSize = getParetoFrontReplaceOperator().getMaximumParetoFrontSize() / 3;

            (new ConfWarning("MMGAAlgorithm.PopulationMemorySize", memSize)).warn();
            setPopulationMemorySize(memSize);
        }

        if (conf.containsKey("PopulationMemoryReplaceOperator.Class")) {
            setPopulationMemoryReplaceOperator((PopulationMemoryReplaceOperator) Class
                    .forName(conf.getString("PopulationMemoryReplaceOperator.Class")).newInstance());
        } else {
            (new ConfWarning("MMGAAlgorithm.PopulationMemoryReplaceOperator",
                    "PopulationMemoryReplaceOperator")).warn();
            setPopulationMemoryReplaceOperator(new PopulationMemoryReplaceOperator());
        }

        getPopulationMemoryReplaceOperator().setPopMemSize(getPopulationMemorySize());
        getPopulationMemoryReplaceOperator().configure(conf.subset("PopulationMemoryReplaceOperator"));

    } catch (Exception ex) {
        throw new ConfigurationException(this.getClass(), ex);
    }
}

From source file:de.nec.nle.siafu.model.DiscreteOverlay.java

/**
 * Create a discrete overlay using the thresholds int he configuration
 * object./*from  w  w  w .ja  v a2s  . c om*/
 * 
 * @param name
 *            the name of the overlay
 * @param is
 *            the InputStream with the image that represents the values
 * @param simulationConfig
 *            the configuration file where the threshold details are given
 */
public DiscreteOverlay(final String name, final InputStream is, final Configuration simulationConfig) {
    super(name, is);

    // A tree to sort the thresholds
    TreeMap<Integer, String> intervals = new TreeMap<Integer, String>();

    // Find out how many thresholds we have
    String[] property;
    try {
        property = simulationConfig.getStringArray("overlays." + name + ".threshold[@tag]");
        if (property.length == 0)
            throw new ConfigurationRuntimeException();
    } catch (ConfigurationRuntimeException e) {
        throw new RuntimeException("You forgot the description of " + name + " in the config file");
    }

    thresholds = new int[property.length];
    tags = new String[property.length];

    // Read the thresholds
    for (int i = 0; i < property.length; i++) {
        String tag = simulationConfig.getString("overlays." + name + ".threshold(" + i + ")[@tag]");
        int pixelValue = simulationConfig.getInt("overlays." + name + ".threshold(" + i + ")[@pixelvalue]");
        intervals.put(pixelValue, tag);
    }

    // Store the sorted thresholds
    int i = 0;
    for (int key : intervals.keySet()) {
        thresholds[i] = key;
        tags[i] = intervals.get(key);
        i++;
    }
}

From source file:es.udc.gii.common.eaf.algorithm.parallel.evaluation.DistributedEvaluation.java

/**
 * Configures this class.<p>//from w  w  w . j  a  va  2  s. com
 *
 * Configuration example:<p>
 *
 * <pre>
 *    ...
 *    &lt;EvaluationStrategy&gt;
 *       &lt;Class&gt;es.udc.gii.common.eaf.algorithm.parallel.evaluation.DistributedEvaluation&lt;Class&gt;
 *       &lt;ChunkSize&gt;3&lt;/ChunkSize&gt;
 *       &lt;Races&gt;2&lt;/Races&gt;
 *       &lt;CollectStatistics/&gt;
 *    &lt;/EvaluationStrategy&gt;     
 *    ...
 * </pre><p>
 *
 * This configures a master-slave model with 2 masters (races). The master
 * sends 3 individuals each time a slave asks for individuals (chunk size).
 * Statistics about the whole process are collected (<code>CollectStatistics</code>). <p>
 * 
 * If <code>ChunkSize</code> is set to 0, then a chunk is choosen so that:
 * let S be the size of the population to be evaluated, let n be the number
 * of proceses (master and slaves), then the chunk size will be S/n
 * (integer division).
 *
 * @param conf Configuration.
 */
@Override
public void configure(Configuration conf) {
    evaluationStrategy = new SerialEvaluationStrategy();
    evaluationStrategy.configure(conf);

    topology = new EvaluationTopology();
    if (conf.containsKey("Races")) {
        topology.setRaces(conf.getInt("Races"));
    } else {
        topology.setRaces(1); // all nodes
    }
    topology.initialize();

    setChunkSize(conf.getInt("ChunkSize"));
    setCollectStatistics(conf.containsKey("CollectStatistics"));

    this.chunkIndex = new int[getTopology().getSize()];
}

From source file:dk.itst.oiosaml.sp.service.SPFilter.java

private void setRuntimeConfiguration(Configuration conf) {
    Audit.configureLog4j(SAMLConfiguration.getStringPrefixedWithBRSHome(conf, Constants.PROP_LOG_FILE_NAME));
    restartCRLChecker(conf);/*from   w  ww .jav a  2s . c  om*/
    setFilterInitialized(true);
    setConfiguration(conf);
    if (!IdpMetadata.getInstance().enableDiscovery()) {
        log.info("Discovery profile disabled, only one metadata file found");
    } else {
        if (conf.getString(Constants.DISCOVERY_LOCATION) == null) {
            throw new IllegalStateException(
                    "Discovery location cannot be null when discovery profile is active");
        }
    }
    setHostname();
    sessionHandlerFactory = SessionHandlerFactory.Factory.newInstance(conf);
    sessionHandlerFactory.getHandler()
            .resetReplayProtection(conf.getInt(Constants.PROP_NUM_TRACKED_ASSERTIONIDS));

    log.info("Home url: " + conf.getString(Constants.PROP_HOME));
    log.info("Assurance level: " + conf.getInt(Constants.PROP_ASSURANCE_LEVEL));
    log.info("SP entity ID: " + SPMetadata.getInstance().getEntityID());
    log.info("Base hostname: " + hostname);
}

From source file:com.nesscomputing.service.discovery.client.DiscoveryClientModule.java

@Provides
@Singleton/*  w  ww. j a v a 2  s  . com*/
@Named(ZOOKEEPER_CONNECT_NAME)
Map<Integer, InetSocketAddress> getZookeeperServers(final Config config,
        final DiscoveryClientConfig clientConfig) {
    Map<Integer, InetSocketAddress> results = Maps.newHashMap();

    if (!clientConfig.isEnabled()) {
        LOG.warn("Service Discovery is administratively disabled.");
    } else {
        final Configuration zookeeperConfig = config.getConfiguration("ness.zookeeper");

        // This can be explicitly given to support the "Three servers, one host" configuration.
        final String[] servers = zookeeperConfig.getStringArray("clientConnect");

        if (ArrayUtils.isNotEmpty(servers)) {
            LOG.debug("Found explicit 'ness.zookeeper.clientConnect' string (%s)",
                    StringUtils.join(servers, ","));
            int serverId = 1;
            for (String server : servers) {
                final String parts[] = StringUtils.split(server, ":");
                InetSocketAddress serverAddress = new InetSocketAddress(parts[0], Integer.parseInt(parts[1]));
                results.put(serverId++, serverAddress);
            }
        } else {
            LOG.debug("Building connectString from server configuration.");

            final int clientPort = zookeeperConfig.getInt("clientPort");
            LOG.debug("ness.zookeeper.clientPort is %d", clientPort);

            for (final Iterator<?> it = zookeeperConfig.getKeys("server"); it.hasNext();) {
                final String key = it.next().toString();
                final String[] keyElements = StringUtils.split(key, ".");
                final String value = zookeeperConfig.getString(key);
                final Integer serverId = Integer.parseInt(keyElements[keyElements.length - 1]);
                final String parts[] = StringUtils.split(value, ":");

                InetSocketAddress serverAddress = new InetSocketAddress(parts[0], clientPort);
                results.put(serverId, serverAddress);
                LOG.debug("Server # %d : %s", serverId, serverAddress);
            }

            // If there are less than two servers, this is running in standalone mode. In that case,
            // use the clientAddress, because that is what the server will be using.
            if (results.size() < 2) {
                LOG.info("Found less than two servers, falling back to clientPortAddress/clientPort!");
                final String clientAddress = zookeeperConfig.getString("clientPortAddress");
                Preconditions.checkState(clientAddress != null, "Client address must not be null!");

                final InetSocketAddress serverAddress = new InetSocketAddress(clientAddress, clientPort);
                LOG.debug("Server: %s", serverAddress);
                results = ImmutableMap.of(1, serverAddress);
            }
        }
        if (LOG.isDebugEnabled()) {
            for (Map.Entry<Integer, InetSocketAddress> entry : results.entrySet()) {
                LOG.debug("Server # %d : %s", entry.getKey(), entry.getValue());
            }
        }
    }

    return results;
}