Example usage for org.apache.commons.configuration SubnodeConfiguration getInteger

List of usage examples for org.apache.commons.configuration SubnodeConfiguration getInteger

Introduction

In this page you can find the example usage for org.apache.commons.configuration SubnodeConfiguration getInteger.

Prototype

public Integer getInteger(String key, Integer defaultValue) 

Source Link

Usage

From source file:net.datenwerke.sandbox.util.SandboxParser.java

public void configureSandboxService(SandboxService sandboxService, Configuration config) {
    if (!(config instanceof HierarchicalConfiguration))
        throw new IllegalArgumentException("Expected HierarchicalConfiguration format");

    HierarchicalConfiguration conf = (HierarchicalConfiguration) config;

    /* general properties */
    SubnodeConfiguration properties = null;
    try {//from   w  w w  .  j ava2 s . c  o  m
        properties = conf.configurationAt("security.properties");
    } catch (IllegalArgumentException e) {
    }
    if (null != properties) {
        /* remote */
        boolean remoteConfig = properties.getBoolean("remote.configureService", false);
        if (remoteConfig) {
            boolean remote = properties.getBoolean("remote[@enable]", false);
            if (remote) {
                Integer poolsize = properties.getInteger("remote.jvm[@poolsize]", 2);
                Integer freelancersize = properties.getInteger("remote.jvm[@freelancersize]", 2);

                String vmArgs = properties.getString("remote.jvm.vmargs", null);
                Integer rmiMinPort = properties.getInteger("remote.jvm.rmi[@minport]", 10000);
                Integer rmiMaxPort = properties.getInteger("remote.jvm.rmi[@maxport]", 10200);

                sandboxService.shutdownJvmPool();
                JvmPoolImpl jvmPoolImpl = new JvmPoolImpl(
                        new JvmPoolConfigImpl(poolsize, freelancersize, new JvmInstantiatorImpl(rmiMinPort,
                                rmiMaxPort, null != vmArgs && "".equals(vmArgs.trim()) ? null : vmArgs)));
                sandboxService.initJvmPool(jvmPoolImpl);
            } else {
                sandboxService.shutdownJvmPool();
            }
        }

        /* daemons */
        Integer monitorCheckInterval = properties.getInteger("monitor[@checkinterval]", 10);
        sandboxService.setMonitorDaemonCheckInterval(monitorCheckInterval);
        Integer monitorWatchdogCheckInterval = properties.getInteger("monitor[@watchdogCheckinterval]", 10000);
        sandboxService.setMonitorWatchdogCheckInterval(monitorWatchdogCheckInterval);

        /* codesource */
        boolean enableCodesource = properties.getBoolean("codesource[@enable]", false);
        sandboxService.setCodesourceSecurityChecks(enableCodesource);
    }

    /* sandboxes */
    parse(config);
    for (Entry<String, SandboxContext> e : getRestrictionSets().entrySet())
        sandboxService.registerContext(e.getKey(), e.getValue());
}

From source file:edu.kit.dama.scheduler.servlet.JobSchedulerInitializerListener.java

/**
 * Load configuration from XML-File// ww  w  .j av  a 2s  .com
 */
private void loadConfiguration() {

    URL configURL;
    HierarchicalConfiguration hc;

    try {
        configURL = DataManagerSettings.getConfigurationURL();
        LOGGER.debug("Loading configuration from {}", configURL);
        hc = new HierarchicalConfiguration(new XMLConfiguration(configURL));
        LOGGER.debug("Configuration successfully loaded");
    } catch (ConfigurationException ex) {
        // error in configuration
        // reason see debug log message:
        LOGGER.warn("Failed to load configuration, using default values.", ex);
        loadDefaultConfiguration();
        return;
    }

    SubnodeConfiguration configurationAt = hc.configurationAt(CONFIG_ROOT);

    if (configurationAt != null) {

        String jobStoreDriverParam = null;
        try {
            jobStoreDriverParam = configurationAt.getString(JOB_STORE_DRIVER, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_DRIVER);
        }
        if (jobStoreDriverParam != null) {
            jobStoreDriver = jobStoreDriverParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_DRIVER,
                    DEFAULT_JOB_STORE_DRIVER);
            jobStoreDriver = DEFAULT_JOB_STORE_DRIVER;
        }

        String jobStoreConnectionStringParam = null;
        try {
            jobStoreConnectionStringParam = configurationAt.getString(JOB_STORE_CONNECTION_STRING, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_CONNECTION_STRING);
        }
        if (jobStoreConnectionStringParam != null) {
            jobStoreConnectionString = jobStoreConnectionStringParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_CONNECTION_STRING,
                    DEFAULT_JOB_STORE_CONNECTION_STRING);
            jobStoreConnectionString = DEFAULT_JOB_STORE_CONNECTION_STRING;
        }

        String jobStoreUserParam = null;
        try {
            jobStoreUserParam = configurationAt.getString(JOB_STORE_USER, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_USER);
        }
        if (jobStoreUserParam != null) {
            jobStoreUser = jobStoreUserParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_USER, DEFAULT_JOB_STORE_USER);
            jobStoreUser = DEFAULT_JOB_STORE_USER;
        }
        String jobStorePasswordParam = null;
        try {
            jobStorePasswordParam = configurationAt.getString(JOB_STORE_PASSWORD, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_PASSWORD);
        }
        if (jobStoreUserParam != null) {
            jobStorePassword = jobStorePasswordParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_PASSWORD,
                    DEFAULT_JOB_STORE_PASSWORD);
            jobStorePassword = DEFAULT_JOB_STORE_PASSWORD;
        }

        Boolean waitOnShutdownParam = null;
        try {
            waitOnShutdownParam = configurationAt.getBoolean(CONFIG_WAIT_ON_SHUTDOWN, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", CONFIG_WAIT_ON_SHUTDOWN);
        }
        if (waitOnShutdownParam != null) {
            waitOnShutdown = waitOnShutdownParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", CONFIG_WAIT_ON_SHUTDOWN,
                    DEFAULT_WAIT_ON_SHUTDOWN);
            waitOnShutdown = DEFAULT_WAIT_ON_SHUTDOWN;
        }

        Boolean addDefaultSchedulesParam = null;
        try {
            addDefaultSchedulesParam = configurationAt.getBoolean(ADD_DEFAULT_SCHEDULES, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", ADD_DEFAULT_SCHEDULES);
        }
        if (addDefaultSchedulesParam != null) {
            addDefaultSchedules = addDefaultSchedulesParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", ADD_DEFAULT_SCHEDULES,
                    DEFAULT_ADD_DEFAULT_SCHEDULES);
            addDefaultSchedules = DEFAULT_ADD_DEFAULT_SCHEDULES;
        }

        Integer startDelaySecondsParam = null;
        try {
            startDelaySecondsParam = configurationAt.getInteger(CONFIG_START_DELAY_SECONDS, null);
        } catch (ConversionException ex) {
            LOGGER.error("Failed to parse parameter '{}'.", CONFIG_START_DELAY_SECONDS);
        }
        if (startDelaySecondsParam != null) {
            startDelaySeconds = startDelaySecondsParam;
        } else {
            LOGGER.info("No parameter '{}' defined, defaulting to {}.", CONFIG_START_DELAY_SECONDS,
                    DEFAULT_START_DELAY_SECONDS);
            startDelaySeconds = DEFAULT_START_DELAY_SECONDS;
        }
    } else {
        LOGGER.info("No scheduler configuration node found in datamanager config. Using default values.");
    }
}