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:org.seedstack.seed.web.internal.WebResourceServlet.java

@Inject
WebResourceServlet(final Application application, final WebResourceResolver webResourceResolver) {
    Configuration configuration = application.getConfiguration();

    this.servletInitTime = System.currentTimeMillis();

    this.webResourceResolver = webResourceResolver;

    int cacheSize = configuration.getInt(WebPlugin.WEB_PLUGIN_PREFIX + ".resources.cache.max-size",
            DEFAULT_CACHE_SIZE);/* ww  w  .j a  v  a 2  s.c om*/
    this.resourceInfoCache = CacheBuilder.newBuilder().maximumSize(cacheSize)
            .concurrencyLevel(configuration.getInt(WebPlugin.WEB_PLUGIN_PREFIX + ".resources.cache.concurrency",
                    DEFAULT_CACHE_CONCURRENCY))
            .initialCapacity(configuration.getInt(WebPlugin.WEB_PLUGIN_PREFIX + ".resources.cache.initial-size",
                    cacheSize / 4))
            .build(new CacheLoader<ResourceRequest, Optional<ResourceInfo>>() {
                @Override
                public Optional<ResourceInfo> load(ResourceRequest key) {
                    ResourceInfo resourceInfo = webResourceResolver.resolveResourceInfo(key);
                    if (resourceInfo == null) {
                        return Optional.absent();
                    } else {
                        return Optional.of(resourceInfo);
                    }
                }
            });
}

From source file:org.seedstack.seed.ws.internal.jms.WSJmsPlugin.java

@Override
public InitState init(InitContext initContext) {
    Configuration wsConfiguration = null;

    for (Plugin plugin : initContext.pluginsRequired()) {
        if (plugin instanceof JmsPlugin) {
            jmsPlugin = (JmsPlugin) plugin;
        }//from w  ww  . j a v  a  2s.  co m

        if (plugin instanceof WSPlugin) {
            wsPlugin = (WSPlugin) plugin;
        }

        if (plugin instanceof ApplicationPlugin) {
            wsConfiguration = ((ApplicationPlugin) plugin).getApplication().getConfiguration()
                    .subset(WS_CONFIGURATION_PREFIX);
        }
    }

    if (wsConfiguration == null) {
        throw new PluginException("Missing required application plugin");
    }

    int cacheSize = wsConfiguration.getInt("jms.transport-cache.max-size", DEFAULT_CACHE_SIZE);
    final Configuration finalWsConfiguration = wsConfiguration;
    connectionCache = CacheBuilder.newBuilder().maximumSize(cacheSize)
            .concurrencyLevel(wsConfiguration.getInt("transport-cache.concurrency", DEFAULT_CACHE_CONCURRENCY))
            .initialCapacity(wsConfiguration.getInt("transport-cache.initial-size", cacheSize / 4))
            .build(new CacheLoader<SoapJmsUri, Connection>() {
                private AtomicInteger atomicInteger = new AtomicInteger(0);

                @Override
                public Connection load(SoapJmsUri soapJmsUri) throws NamingException, JMSException {
                    String lookupVariant = soapJmsUri.getLookupVariant();
                    JmsFactory jmsFactory = jmsPlugin.getJmsFactory();
                    Connection connection;

                    if (SoapJmsUri.JNDI_LOOKUP_VARIANT.equals(lookupVariant)) {
                        String jndiConnectionFactoryName = soapJmsUri.getParameter("jndiConnectionFactoryName");
                        if (StringUtils.isBlank(jndiConnectionFactoryName)) {
                            throw new IllegalArgumentException(
                                    "Missing jndiConnectionFactoryName parameter for JMS URI "
                                            + soapJmsUri.toString());
                        }

                        String connectionName = soapJmsUri.getConnectionName();
                        if (connectionName == null) {
                            connectionName = String.format(ANONYMOUS_CONNECTION_PATTERN,
                                    atomicInteger.getAndIncrement());
                        }

                        ConnectionDefinition connectionDefinition = jmsFactory.createConnectionDefinition(
                                connectionName, soapJmsUri.getConfiguration(finalWsConfiguration),
                                (ConnectionFactory) SoapJmsUri.getContext(soapJmsUri)
                                        .lookup(jndiConnectionFactoryName));

                        connection = jmsFactory.createConnection(connectionDefinition);
                        jmsPlugin.registerConnection(connection, connectionDefinition);
                    } else if (SoapJmsUri.SEED_QUEUE_LOOKUP_VARIANT.equals(lookupVariant)
                            || SoapJmsUri.SEED_TOPIC_LOOKUP_VARIANT.equals(lookupVariant)) {
                        String connectionName = soapJmsUri.getConnectionName();

                        if (StringUtils.isBlank(connectionName)) {
                            throw new IllegalArgumentException(
                                    "Missing connectionName parameter for JMS URI " + soapJmsUri.toString());
                        }

                        connection = jmsPlugin.getConnection(connectionName);
                    } else {
                        throw new IllegalArgumentException("Unsupported lookup variant " + lookupVariant
                                + " for JMS URI " + soapJmsUri.toString());
                    }

                    if (connection == null) {
                        throw new PluginException(
                                "Unable to resolve connection for JMS URI " + soapJmsUri.toString());
                    }

                    return connection;
                }
            });

    for (Map.Entry<String, EndpointDefinition> endpointEntry : wsPlugin
            .getEndpointDefinitions(SUPPORTED_BINDINGS).entrySet()) {
        EndpointDefinition endpointDefinition = endpointEntry.getValue();
        String endpointName = endpointEntry.getKey();
        String serviceName = endpointDefinition.getServiceName().getLocalPart();
        String portName = endpointDefinition.getPortName().getLocalPart();
        String serviceNameAndServicePort = serviceName + "-" + portName;

        SoapJmsUri uri;
        try {
            uri = SoapJmsUri.parse(new URI(endpointDefinition.getUrl()));
            uri.setEndpointName(endpointName);
        } catch (URISyntaxException e) {
            throw new PluginException("Unable to parse endpoint URI", e);
        }

        Configuration endpointConfiguration = uri.getConfiguration(wsConfiguration);
        Connection connection;
        try {
            connection = connectionCache.get(uri);
        } catch (Exception e) {
            throw new PluginException("Unable to create JMS connection for WS " + serviceNameAndServicePort, e);
        }

        Session session;
        try {
            session = connection.createSession(endpointConfiguration.getBoolean("transactional", true),
                    Session.AUTO_ACKNOWLEDGE);
        } catch (JMSException e) {
            throw new PluginException("Unable to create JMS session for WS " + serviceNameAndServicePort, e);
        }

        Destination destination;
        try {
            destination = SoapJmsUri.getDestination(uri, session);
        } catch (Exception e) {
            throw new PluginException("Unable to create JMS destination for WS " + serviceNameAndServicePort,
                    e);
        }

        WSJmsMessageListener messageListener = new WSJmsMessageListener(uri,
                new JmsAdapter(wsPlugin.createWSEndpoint(endpointDefinition, null)), session);

        String messageListenerName = String.format(LISTENER_NAME_PATTERN, endpointName);
        try {
            Class<? extends MessagePoller> poller = getPoller(endpointConfiguration);

            jmsPlugin.registerMessageListener(
                    new MessageListenerInstanceDefinition(messageListenerName, uri.getConnectionName(), session,
                            destination, endpointConfiguration.getString("selector"), messageListener, poller));
        } catch (Exception e) {
            throw SeedException.wrap(e, WSJmsErrorCodes.UNABLE_TO_REGISTER_MESSAGE_LISTENER)
                    .put("messageListenerName", messageListenerName);
        }
        wsJmsMessageListeners.add(messageListener);
    }

    return InitState.INITIALIZED;
}

From source file:org.sonar.plugins.cpd.CpdSensor.java

int getMinimumTokens(Project project) {
    Configuration conf = project.getConfiguration();
    return conf.getInt("sonar.cpd." + project.getLanguageKey() + ".minimumTokens",
            conf.getInt("sonar.cpd.minimumTokens", CoreProperties.CPD_MINIMUM_TOKENS_DEFAULT_VALUE));
}

From source file:org.sonar.plugins.cpd.PmdEngine.java

@VisibleForTesting
static int getMinimumTokens(Project project) {
    Configuration conf = project.getConfiguration();
    return conf.getInt("sonar.cpd." + project.getLanguageKey() + ".minimumTokens",
            conf.getInt("sonar.cpd.minimumTokens", CoreProperties.CPD_MINIMUM_TOKENS_DEFAULT_VALUE));
}

From source file:org.sonar.plugins.dbcleaner.api.PurgeUtils.java

public static int getMinimumPeriodInHours(Configuration conf) {
    int hours = DEFAULT_MINIMUM_PERIOD_IN_HOURS;
    if (conf != null) {
        hours = conf.getInt(PROP_KEY_MINIMUM_PERIOD_IN_HOURS, DEFAULT_MINIMUM_PERIOD_IN_HOURS);
    }/*from ww  w  . j a  va2  s  . co m*/
    return hours;
}

From source file:org.sonar.plugins.dbcleaner.period.Periods.java

static Date getDate(Configuration conf, String propertyKey, String defaultNumberOfMonths) {
    int months = conf.getInt(propertyKey, Integer.parseInt(defaultNumberOfMonths));
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(GregorianCalendar.MONTH, -months);
    return calendar.getTime();
}

From source file:org.sonar.plugins.php.core.AbstractPhpConfiguration.java

/**
 * @param project//from   ww  w.  j  a  va 2s .c o  m
 */
protected AbstractPhpConfiguration(Project project) {
    this.project = project;
    Configuration configuration = getProject().getConfiguration();
    this.reportFileName = configuration.getString(getReportFileNameKey(), getDefaultReportFileName());
    this.reportFileRelativePath = configuration.getString(getReportFileRelativePathKey(),
            getDefaultReportFilePath());
    this.argumentLine = configuration.getString(getArgumentLineKey(), getDefaultArgumentLine());
    this.analyzeOnly = configuration.getBoolean(getShouldAnalyzeOnlyKey(), false);
    this.timeout = configuration.getInt(getTimeoutKey(), DEFAULT_TIMEOUT);
    if (isStringPropertySet(getSkipKey())) { // NOSONAR Use of non final method, that is not final for mocking purposes
        skip = project.getConfiguration().getBoolean(getSkipKey());
    } else if (isStringPropertySet(getShouldRunKey())) { // NOSONAR Use of non final method, that is not final for mocking purposes
        skip = !project.getConfiguration().getBoolean(getShouldRunKey());
    }
    String dynamicAnalysis = configuration.getString("sonar.dynamicAnalysis", "true");
    if (!"false".equalsIgnoreCase(dynamicAnalysis)) {
        isDynamicAnalysis = true;
    }
}

From source file:org.topazproject.mulgara.resolver.TransactionLogger.java

/** 
 * Create a new logger instance. //from   www .  j a v  a 2  s .  c  om
 * 
 * @param config  the configuration to use
 * @param base    the prefix under which the current <var>config</var> was retrieved
 * @param sf      ignored
 * @param dbURI   ignored
 * @throws IOException 
 */
public TransactionLogger(Configuration config, String base, SessionFactory sf, URI dbURI) throws IOException {
    super(getFlushIval(config), 0, "TransactionLogger-Worker", true, logger);

    config = config.subset("transactionLogger");
    base += ".transactionLogger";

    String fileName = config.getString("log.fileName", null);
    long maxSize = config.getLong("log.maxSize", -1L);
    long maxAge = config.getLong("log.maxAge", -1L);
    int bufSize = config.getInt("writeBufferSize", -1);

    if (fileName == null)
        throw new IllegalArgumentException("Missing configuration entry '" + base + ".log.fileName'");

    txLog = new TxLog(fileName, maxSize, maxAge, bufSize);
    worker.start();
}

From source file:org.wso2.andes.server.cassandra.CassandraConnection.java

@Override
public void initialize(Configuration configuration) throws AndesException {

    try {/*ww w .j  av  a  2s  . co  m*/
        String userName = (String) configuration.getProperty(USERNAME_KEY);
        String password = (String) configuration.getProperty(PASSWORD_KEY);
        Object connections = configuration.getProperty(CONNECTION_STRING);
        int replicationFactor = configuration.getInt(REPLICATION_FACTOR, 1);
        String strategyClass = configuration.getString(STRATERGY_CLASS);
        String readConsistancyLevel = configuration.getString(READ_CONSISTENCY_LEVEL);
        String writeConsistancyLevel = configuration.getString(WRITE_CONSISTENCY_LEVEL);
        String connectionString = "";

        if (connections instanceof ArrayList) {
            ArrayList<String> cons = (ArrayList<String>) connections;

            for (String c : cons) {
                connectionString += c + ",";
            }
            connectionString = connectionString.substring(0, connectionString.length() - 1);
        } else if (connectionString instanceof String) {
            connectionString = (String) connections;
            if (connectionString.indexOf(":") > 0) {
                String host = connectionString.substring(0, connectionString.indexOf(":"));
                int port = AndesUtils.getInstance().getCassandraPort();
                connectionString = host + ":" + port;
            }
        }
        String clusterName = (String) configuration.getProperty(CLUSTER_KEY);
        cluster = CassandraDataAccessHelper.createCluster(userName, password, clusterName, connectionString);
        createKeySpace(replicationFactor, strategyClass);

        ConfigurableConsistencyLevel configurableConsistencyLevel = new ConfigurableConsistencyLevel();
        if (readConsistancyLevel == null || readConsistancyLevel.isEmpty()) {
            configurableConsistencyLevel.setDefaultReadConsistencyLevel(HConsistencyLevel.QUORUM);
        } else {
            configurableConsistencyLevel
                    .setDefaultReadConsistencyLevel(HConsistencyLevel.valueOf(readConsistancyLevel));
        }
        if (writeConsistancyLevel == null || writeConsistancyLevel.isEmpty()) {
            configurableConsistencyLevel.setDefaultWriteConsistencyLevel(HConsistencyLevel.QUORUM);
        } else {
            configurableConsistencyLevel
                    .setDefaultWriteConsistencyLevel(HConsistencyLevel.valueOf(writeConsistancyLevel));
        }

        keyspace.setConsistencyLevelPolicy(configurableConsistencyLevel);

        //start Cassandra connection live check
        checkCassandraConnection();

    } catch (CassandraDataAccessException e) {
        log.error("Cannot Initialize Cassandra Connection", e);
        throw new AndesException(e);
    }
}

From source file:org.wso2.andes.server.cassandra.CQLConnection.java

@Override
public void initialize(Configuration configuration) throws AndesException {

    try {//w ww .ja v  a  2 s.co  m
        String userName = (String) configuration.getProperty(USERNAME_KEY);
        String password = (String) configuration.getProperty(PASSWORD_KEY);
        Object connections = configuration.getProperty(CONNECTION_STRING);
        int replicationFactor = configuration.getInt(REPLICATION_FACTOR, 1);
        String strategyClass = configuration.getString(STRATERGY_CLASS);
        String readConsistancyLevel = configuration.getString(READ_CONSISTENCY_LEVEL);
        String writeConsistancyLevel = configuration.getString(WRITE_CONSISTENCY_LEVEL);

        int port = 9042;
        boolean isExternalCassandraServerRequired = ClusterResourceHolder.getInstance()
                .getClusterConfiguration().getIsExternalCassandraserverRequired();

        List<String> hosts = new ArrayList<String>();

        if (connections instanceof ArrayList && isExternalCassandraServerRequired) {
            List<String> cons = (ArrayList<String>) connections;
            for (String connection : cons) {
                String host = connection.split(":")[0];
                port = Integer.parseInt(connection.split(":")[1]);
                hosts.add(host);
            }

        } else if (connections instanceof String && isExternalCassandraServerRequired) {
            String connectionString = (String) connections;
            if (connectionString.indexOf(":") > 0) {
                String host = connectionString.split(":")[0];
                hosts.add(host);
                port = Integer.parseInt(connectionString.split(":")[1]);
            }
        } else {
            String defaultHost = "localhost";
            int defaultPort = AndesUtils.getInstance().getCassandraPort();
            port = defaultPort;
            hosts.add(defaultHost);
        }

        String clusterName = (String) configuration.getProperty(CLUSTER_KEY);
        ClusterConfiguration clusterConfig = new ClusterConfiguration(userName, password, clusterName, hosts,
                port);

        log.info("Initializing Cassandra Message Store: HOSTS=" + hosts + " PORT=" + port);

        cluster = CQLDataAccessHelper.createCluster(clusterConfig);
        GenericCQLDAO.setCluster(cluster);
        createKeySpace(replicationFactor, strategyClass);

        /*ConfigurableConsistencyLevel configurableConsistencyLevel = new ConfigurableConsistencyLevel();
        if (readConsistancyLevel == null || readConsistancyLevel.isEmpty()) {
        configurableConsistencyLevel.setDefaultReadConsistencyLevel(HConsistencyLevel.QUORUM);
        } else {
        configurableConsistencyLevel.setDefaultReadConsistencyLevel(HConsistencyLevel.valueOf(readConsistancyLevel));
        }
        if (writeConsistancyLevel == null || writeConsistancyLevel.isEmpty()) {
        configurableConsistencyLevel.setDefaultWriteConsistencyLevel(HConsistencyLevel.QUORUM);
        } else {
        configurableConsistencyLevel.setDefaultWriteConsistencyLevel(HConsistencyLevel.valueOf(writeConsistancyLevel));
        }
                
        keyspace.setConsistencyLevelPolicy(configurableConsistencyLevel);
        */
        //start Cassandra connection live check
        checkCassandraConnection();

    } catch (CassandraDataAccessException e) {
        log.error("Cannot Initialize Cassandra Connection", e);
        throw new AndesException(e);
    }
}