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, int defaultValue);

Source Link

Document

Get a int associated with the given configuration key.

Usage

From source file:com.github.nethad.clustermeister.provisioning.torque.TorqueConfiguration.java

private static int checkInt(Configuration configuration, String configOption, int defaultValue,
        String logMessage) {/*from   w  w w.j  a v  a  2s  .c  om*/
    int value = configuration.getInt(configOption, -1);
    if (value == -1) {
        logger.warn(loggerMessage(logMessage, configOption, String.valueOf(defaultValue)));
        return defaultValue;
    }
    return value;
}

From source file:com.github.anba.test262.environment.Environments.java

/**
 * Creates a new Rhino environment/*w  w  w  .  ja v a2 s .  com*/
 */
public static <T extends GlobalObject> EnvironmentProvider<T> rhino(final Configuration configuration) {
    final int version = configuration.getInt("rhino.version", Context.VERSION_DEFAULT);
    final String compiler = configuration.getString("rhino.compiler.default");
    List<?> enabledFeatures = configuration.getList("rhino.features.enabled", emptyList());
    List<?> disabledFeatures = configuration.getList("rhino.features.disabled", emptyList());
    final Set<Integer> enabled = intoCollection(filterMap(enabledFeatures, notEmptyString, toInteger),
            new HashSet<Integer>());
    final Set<Integer> disabled = intoCollection(filterMap(disabledFeatures, notEmptyString, toInteger),
            new HashSet<Integer>());

    /**
     * Initializes the global {@link ContextFactory} according to the
     * supplied configuration
     * 
     * @see ContextFactory#initGlobal(ContextFactory)
     */
    final ContextFactory factory = new ContextFactory() {
        @Override
        protected boolean hasFeature(Context cx, int featureIndex) {
            if (enabled.contains(featureIndex)) {
                return true;
            } else if (disabled.contains(featureIndex)) {
                return false;
            }
            return super.hasFeature(cx, featureIndex);
        }

        @Override
        protected Context makeContext() {
            Context context = super.makeContext();
            context.setLanguageVersion(version);
            return context;
        }
    };

    EnvironmentProvider<RhinoGlobalObject> provider = new EnvironmentProvider<RhinoGlobalObject>() {
        @Override
        public RhinoEnv<RhinoGlobalObject> environment(final String testsuite, final String sourceName,
                final Test262Info info) {
            Configuration c = configuration.subset(testsuite);
            final boolean strictSupported = c.getBoolean("strict", false);
            final String encoding = c.getString("encoding", "UTF-8");
            final String libpath = c.getString("lib_path");

            final Context cx = factory.enterContext();
            final AtomicReference<RhinoGlobalObject> $global = new AtomicReference<>();

            final RhinoEnv<RhinoGlobalObject> environment = new RhinoEnv<RhinoGlobalObject>() {
                @Override
                public RhinoGlobalObject global() {
                    return $global.get();
                }

                @Override
                protected String getEvaluator() {
                    return compiler;
                }

                @Override
                protected String getCharsetName() {
                    return encoding;
                }

                @Override
                public void exit() {
                    Context.exit();
                }
            };

            @SuppressWarnings({ "serial" })
            final RhinoGlobalObject global = new RhinoGlobalObject() {
                {
                    cx.initStandardObjects(this, false);
                }

                @Override
                protected boolean isStrictSupported() {
                    return strictSupported;
                }

                @Override
                protected String getDescription() {
                    return info.getDescription();
                }

                @Override
                protected void failure(String message) {
                    failWith(message, sourceName);
                }

                @Override
                protected void include(Path path) throws IOException {
                    // resolve the input file against the library path
                    Path file = Paths.get(libpath).resolve(path);
                    InputStream source = Files.newInputStream(file);
                    environment.eval(file.getFileName().toString(), source);
                }
            };

            $global.set(global);

            return environment;
        }
    };

    @SuppressWarnings("unchecked")
    EnvironmentProvider<T> p = (EnvironmentProvider<T>) provider;

    return p;
}

From source file:com.salesmanager.core.util.LocaleUtil.java

public static Locale getDefaultLocale() {
    Configuration conf = PropertiesUtil.getConfiguration();
    int defaultCountryId = conf.getInt("core.system.defaultcountryid", 38);

    Map countriesMap = RefCache.getAllcountriesmap(Constants.ENGLISH);

    if (countriesMap == null) {
        log.error("Cannot get object from database, check your database configuration");
    }/* w  w  w .jav a 2  s. co m*/

    Country country = (Country) countriesMap.get(defaultCountryId);
    Locale locale = new Locale(conf.getString("core.system.defaultlanguage", Constants.ENGLISH_CODE),
            country.getCountryIsoCode2());
    return locale;
}

From source file:com.manydesigns.mail.quartz.MailSenderJob.java

/**
 * Utility method to schedule the job at a fixed interval.
 *///from www.  j ava2s .c  o m
public static void schedule(MailSender mailSender, Configuration mailConfiguration, String group)
        throws SchedulerException {
    Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
    JobDetail job = JobBuilder.newJob(MailSenderJob.class).withIdentity("mail.sender", group).build();

    int pollInterval = mailConfiguration.getInt(MailProperties.MAIL_SENDER_POLL_INTERVAL,
            MailScheduler.DEFAULT_POLL_INTERVAL);

    Trigger trigger = TriggerBuilder.newTrigger().withIdentity("mail.sender.trigger", group).startNow()
            .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(pollInterval)
                    .repeatForever())
            .build();

    scheduler.getContext().put(MailSenderJob.MAIL_SENDER_KEY, mailSender);
    scheduler.scheduleJob(job, trigger);
}

From source file:com.microrisc.simply.iqrf.dpa.v201.DPA_SimplyFactory.java

/**
 * Creates and returns broadcast services implementation object.
 * @param configuration source configuration
 * @param connectorService connector to use
 * @return DPA broadcaster object/*from w w  w  .j a v a2s  .c  o m*/
 * @throws SimplyException if specified connector doesn't support DPA Broadcasting 
 */
private static BroadcastServices createBroadcastServices(Configuration configuration,
        ConnectorService connectorService) throws SimplyException {
    if (!(connectorService instanceof BroadcastingConnectorService)) {
        throw new SimplyException("Connector doesn't support broadcasting.");
    }

    int capacity = configuration.getInt("dpa.broadcasting.resultsContainer.capacity",
            HashMapResultsContainer.DEFAULT_CAPACITY);

    long maxTimeDuration = configuration.getLong("dpa.broadcasting.resultsContainer.maxTimeDuration",
            HashMapResultsContainer.DEFAULT_MAX_TIME_DURATION);

    return new BroadcastServicesDefaultImpl((BroadcastingConnectorService) connectorService,
            new HashMapCallRequestProcessingInfoContainer(capacity, maxTimeDuration));
}

From source file:com.comcast.viper.flume2storm.connection.KryoNetParameters.java

/**
 * Builds a new {@link KryoNetParameters} based on a Configuration
 * //from   w  w w  .j ava2 s. c o  m
 * @param config
 *          The configuration to use
 * @return The newly created {@link KryoNetParameters}
 * @throws F2SConfigurationException
 *           If the configuration specified is invalid
 */
public static KryoNetParameters from(final Configuration config) throws F2SConfigurationException {
    KryoNetParameters result = new KryoNetParameters();
    try {
        result.setConnectionTimeout(config.getInt(CONNECTION_TIMEOUT, CONNECTION_TIMEOUT_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, CONNECTION_TIMEOUT, e);
    }
    try {
        result.setTerminationTimeout(config.getInt(TERMINATION_TO, TERMINATION_TO_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, TERMINATION_TO, e);
    }
    try {
        result.setReconnectionDelay(config.getInt(RECONNECTION_DELAY, RECONNECTION_DELAY_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, RECONNECTION_DELAY, e);
    }
    try {
        result.setRetrySleepDelay(config.getInt(RETRY_SLEEP_DELAY, RETRY_SLEEP_DELAY_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, RETRY_SLEEP_DELAY, e);
    }
    try {
        result.setMaxRetries(config.getInt(MAX_RETRIES, MAX_RETRIES_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, MAX_RETRIES, e);
    }
    return result;
}

From source file:com.comcast.viper.flume2storm.location.DynamicLocationServiceConfiguration.java

/**
 * @param config//from w  w w.ja  v a 2 s .  c  om
 *          The configuration to use
 * @return The newly built {@link DynamicLocationServiceConfiguration} based
 *         on the configuration specified
 * @throws F2SConfigurationException
 *           If the configuration is invalid
 */
public static DynamicLocationServiceConfiguration from(Configuration config) throws F2SConfigurationException {
    DynamicLocationServiceConfiguration result = new DynamicLocationServiceConfiguration();
    result.setConnectionStr(config.getString(CONNECTION_STRING, CONNECTION_STRING_DEFAULT));
    result.setSessionTimeout(config.getInt(SESSION_TIMEOUT, SESSION_TIMEOUT_DEFAULT));
    result.setConnectionTimeout(config.getInt(CONNECTION_TIMEOUT, CONNECTION_TIMEOUT_DEFAULT));
    result.setReconnectionDelay(config.getInt(RECONNECTION_DELAY, RECONNECTION_DELAY_DEFAULT));
    result.setTerminationTimeout(config.getInt(TERMINATION_TIMEOUT, TERMINATION_TIMEOUT_DEFAULT));
    result.setBasePath(config.getString(BASE_PATH, BASE_PATH_DEFAULT));
    result.setServiceName(config.getString(SERVICE_NAME, SERVICE_NAME_DEFAULT));
    return result;
}

From source file:com.comcast.viper.flume2storm.zookeeper.ZkClientConfiguration.java

/**
 * Builds a new {@link ZkClientConfiguration} based on a Configuration
 * /*from  w  w  w .  j a  va2 s.c o m*/
 * @param config
 *          The configuration to use
 * @return The newly built {@link ZkClientConfiguration} based on the
 *         configuration specified
 * @throws F2SConfigurationException
 *           If the configuration is invalid
 */
public static ZkClientConfiguration from(Configuration config) throws F2SConfigurationException {
    ZkClientConfiguration result = new ZkClientConfiguration();
    result.connectionStr = config.getString(CONNECTION_STRING, CONNECTION_STRING_DEFAULT);
    result.sessionTimeout = config.getInt(SESSION_TIMEOUT, SESSION_TIMEOUT_DEFAULT);
    result.connectionTimeout = config.getInt(CONNECTION_TIMEOUT, CONNECTION_TIMEOUT_DEFAULT);
    result.reconnectionDelay = config.getInt(RECONNECTION_DELAY, RECONNECTION_DELAY_DEFAULT);
    result.terminationTimeout = config.getInt(TERMINATION_TIMEOUT, TERMINATION_TIMEOUT_DEFAULT);
    return result;
}

From source file:com.boozallen.cognition.ingest.accumulo.utils.AccumuloConnectionUtils.java

public static AccumuloConnectionConfig extractConnectionConfiguration(Configuration conf) {
    AccumuloConnectionConfig config = new AccumuloConnectionConfig();
    config.instance = conf.getString(INSTANCE);
    config.zooServers = conf.getString(ZOO_SERVERS);
    config.user = conf.getString(USER);//from w  ww .  j  a v a 2s . c  om
    config.key = conf.getString(KEY);
    config.maxMem = conf.getLong(MAX_MEM, MAX_MEM_DEFAULT);
    config.maxLatency = conf.getLong(MAX_LATENCY, MAX_LATENCY_DEFAULT);
    config.maxWriteThreads = conf.getInt(MAX_WRITE_THREADS, MAX_WRITE_THREADS_DEFAULT);
    return config;
}

From source file:com.manydesigns.portofino.dispatcher.DispatcherLogic.java

public static void init(Configuration portofinoConfiguration) {
    int maxSize, refreshCheckFrequency;
    maxSize = portofinoConfiguration.getInt(PAGE_CACHE_SIZE, 1000);
    refreshCheckFrequency = portofinoConfiguration.getInt(PAGE_CACHE_CHECK_FREQUENCY, 5);
    initPageCache(maxSize, refreshCheckFrequency);
    maxSize = portofinoConfiguration.getInt(CONFIGURATION_CACHE_SIZE, 1000);
    refreshCheckFrequency = portofinoConfiguration.getInt(CONFIGURATION_CACHE_CHECK_FREQUENCY, 5);
    initConfigurationCache(maxSize, refreshCheckFrequency);
}