List of usage examples for org.apache.commons.configuration Configuration getInteger
Integer getInteger(String key, Integer defaultValue);
From source file:org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration.java
private static Optional<PoolingOptions> readPoolingOptions(Configuration configuration) { Optional<Integer> maxConnections = Optional .ofNullable(configuration.getInteger("cassandra.pooling.local.max.connections", null)); Optional<Integer> maxRequests = Optional .ofNullable(configuration.getInteger("cassandra.pooling.local.max.requests", null)); Optional<Integer> poolingTimeout = Optional .ofNullable(configuration.getInteger("cassandra.pooling.timeout", null)); Optional<Integer> heartbeatTimeout = Optional .ofNullable(configuration.getInteger("cassandra.pooling.heartbeat.timeout", null)); Optional<Integer> maxQueueSize = Optional .ofNullable(configuration.getInteger("cassandra.pooling.max.queue.size", null)); if (!maxConnections.isPresent() && !maxRequests.isPresent() && !poolingTimeout.isPresent() && !heartbeatTimeout.isPresent() && !maxQueueSize.isPresent()) { return Optional.empty(); }// w w w. ja v a 2 s. co m PoolingOptions result = new PoolingOptions(); maxConnections.ifPresent(value -> { result.setMaxConnectionsPerHost(HostDistance.LOCAL, value); result.setMaxConnectionsPerHost(HostDistance.REMOTE, value); }); maxRequests.ifPresent(value -> { result.setMaxRequestsPerConnection(HostDistance.LOCAL, value); result.setMaxRequestsPerConnection(HostDistance.REMOTE, value); }); poolingTimeout.ifPresent(result::setPoolTimeoutMillis); heartbeatTimeout.ifPresent(result::setHeartbeatIntervalSeconds); maxQueueSize.ifPresent(result::setMaxQueueSize); return Optional.of(result); }
From source file:org.apache.james.backends.cassandra.init.configuration.QueryLoggerConfiguration.java
private static Optional<Integer> getOptionalIntegerFromConf(Configuration configuration, String key) { return Optional.ofNullable(configuration.getInteger(key, null)); }
From source file:org.apache.james.backends.es.ElasticSearchConfiguration.java
public static ElasticSearchConfiguration fromProperties(Configuration configuration) throws ConfigurationException { return builder().addHosts(getHosts(configuration)) .clusterName(configuration.getString(ELASTICSEARCH_CLUSTER_NAME)) .nbShards(configuration.getInteger(ELASTICSEARCH_NB_SHARDS, DEFAULT_NB_SHARDS)) .nbReplica(configuration.getInteger(ELASTICSEARCH_NB_REPLICA, DEFAULT_NB_REPLICA)) .minDelay(Optional//from w w w .java 2 s . c o m .ofNullable(configuration.getInteger(ELASTICSEARCH_RETRY_CONNECTION_MIN_DELAY, null))) .maxRetries(Optional .ofNullable(configuration.getInteger(ELASTICSEARCH_RETRY_CONNECTION_MAX_RETRIES, null))) .build(); }
From source file:org.apache.james.backends.es.ElasticSearchConfiguration.java
private static ImmutableList<Host> getHosts(Configuration propertiesReader) throws ConfigurationException { AbstractConfiguration.setDefaultListDelimiter(','); Optional<String> masterHost = Optional .ofNullable(propertiesReader.getString(ELASTICSEARCH_MASTER_HOST, null)); Optional<Integer> masterPort = Optional.ofNullable(propertiesReader.getInteger(ELASTICSEARCH_PORT, null)); List<String> multiHosts = Arrays.asList(propertiesReader.getStringArray(ELASTICSEARCH_HOSTS)); validateHostsConfigurationOptions(masterHost, masterPort, multiHosts); if (masterHost.isPresent()) { return ImmutableList.of(Host.from(masterHost.get(), masterPort.get())); } else {/*from w w w.jav a 2 s . c om*/ return multiHosts.stream().map(ipAndPort -> Host.parse(ipAndPort, DEFAULT_PORT_AS_OPTIONAL)) .collect(Guavate.toImmutableList()); } }
From source file:org.apache.james.modules.mailbox.TikaConfigurationReader.java
public static TikaConfiguration readTikaConfiguration(Configuration configuration) { AbstractConfiguration.setDefaultListDelimiter(','); Optional<Boolean> enabled = Optional.ofNullable(configuration.getBoolean(TIKA_ENABLED, null)); Optional<Boolean> cacheEnabled = Optional.ofNullable(configuration.getBoolean(TIKA_CACHE_ENABLED, null)); Optional<String> host = Optional.ofNullable(configuration.getString(TIKA_HOST, null)); Optional<Integer> port = Optional.ofNullable(configuration.getInteger(TIKA_PORT, null)); Optional<Integer> timeoutInMillis = Optional.ofNullable(configuration.getInteger(TIKA_TIMEOUT_IN_MS, null)); Optional<Duration> cacheEvictionPeriod = Optional .ofNullable(configuration.getString(TIKA_CACHE_EVICTION_PERIOD, null)) .map(rawString -> TimeConverter.getMilliSeconds(rawString, TimeConverter.Unit.SECONDS)) .map(Duration::ofMillis); Optional<Long> cacheWeight = Optional.ofNullable(configuration.getString(TIKA_CACHE_WEIGHT_MAX, null)) .map(Throwing.function(Size::parse)).map(Size::asBytes); Set<String> contentTypeBlacklist = StreamUtils .ofNullable(configuration.getStringArray(TIKA_CONTENT_TYPE_BLACKLIST)).map(String::trim) .collect(ImmutableSet.toImmutableSet()); return TikaConfiguration.builder().enable(enabled).host(host).port(port).timeoutInMillis(timeoutInMillis) .cacheEnable(cacheEnabled).cacheEvictionPeriod(cacheEvictionPeriod).cacheWeightInBytes(cacheWeight) .contentTypeBlacklist(contentTypeBlacklist).build(); }
From source file:org.apache.james.modules.spamassassin.SpamAssassinConfigurationLoader.java
private static Host getHost(Configuration propertiesReader) { return Host.from(propertiesReader.getString(SPAMASSASSIN_HOST, DEFAULT_HOST), propertiesReader.getInteger(SPAMASSASSIN_PORT, DEFAULT_PORT)); }
From source file:org.apache.james.queue.rabbitmq.view.cassandra.configuration.CassandraMailQueueViewConfiguration.java
public static CassandraMailQueueViewConfiguration from(Configuration configuration) { int bucketCount = configuration.getInteger(BUCKET_COUNT_PROPERTY, DEFAULT_BUCKET_COUNT); int updateBrowseStartPace = configuration.getInteger(UPDATE_BROWSE_START_PACE_PROPERTY, DEFAULT_UPDATE_BROWSE_START_PACE); Optional<String> sliceWindowAsString = Optional .ofNullable(configuration.getString(SLICE_WINDOW_PROPERTY, null)); return builder().bucketCount(bucketCount).updateBrowseStartPace(updateBrowseStartPace) .sliceWindow(sliceWindowAsString.map(TimeConverter::getMilliSeconds).map(Duration::ofMillis) .orElse(DEFAULT_SLICE_WINDOW)) .build();/* w ww . java 2 s . c o m*/ }
From source file:org.apache.servicecomb.foundation.vertx.AddressResolverConfig.java
private static int getPositiveIntProperty(Configuration configSource, int defaultValue, String... keys) { configSource = guardConfigSource(configSource); if (configSource == null) { return defaultValue; }//from w w w. ja v a 2 s . com for (String key : keys) { Integer val = configSource.getInteger(key, null); if (val != null && val <= 0) { LOGGER.warn("Address resover key:{}'s value:{} is not positive, please check!", key, val); continue; } if (val != null) { return val; } } return defaultValue; }
From source file:org.apache.servicecomb.foundation.vertx.TestAddressResolverConfig.java
@Test public void testGetResoverFromResource(@Mocked Configuration finalConfig) { ArchaiusUtils.resetConfig();/*from w w w .j a v a2 s. com*/ ArchaiusUtils.setProperty("addressResolver.servers", "8.8.8.8,8.8.4.4"); new Expectations() { { finalConfig.getStringArray("addressResolver.servers"); result = new String[] { "6.6.6.6", "6.6.4.4" }; finalConfig.getStringArray("addressResolver.searchDomains"); result = new String[] { "default.svc.local.cluster" }; finalConfig.getInteger("addressResolver.queryTimeout", null); result = 2000; finalConfig.getInteger("addressResolver.maxQueries", null); result = -2; } }; AddressResolverOptions aroc = AddressResolverConfig.getAddressResover("test", finalConfig); Assert.assertThat(aroc.getServers(), is(Arrays.asList("6.6.6.6", "6.6.4.4"))); Assert.assertThat(aroc.getSearchDomains(), is(Arrays.asList("default.svc.local.cluster"))); Assert.assertEquals(aroc.getQueryTimeout(), 2000); Assert.assertNotEquals(aroc.getMaxQueries(), -2); }
From source file:org.apache.whirr.service.mongodb.BaseMongoDBClusterActionHandler.java
@Override protected void beforeBootstrap(ClusterActionEvent event) throws IOException { ClusterSpec clusterSpec = event.getClusterSpec(); Configuration config = getConfiguration(clusterSpec); addStatement(event,// w w w . ja v a 2s . c o m call("configure_hostnames", MongoDBConstants.PARAM_PROVIDER, clusterSpec.getProvider())); this.noJournal = config.getBoolean(MongoDBConstants.CFG_KEY_NOJOURNAL, null); this.replicaSetName = config.getString(MongoDBConstants.CFG_KEY_REPLSETNAME, null); this.authPassword = config.getString(MongoDBConstants.CFG_KEY_AUTH_PW, null); this.authUsername = config.getString(MongoDBConstants.CFG_KEY_AUTH_USER, null); this.bindIp = config.getString(MongoDBConstants.CFG_KEY_BINDIP, null); this.noPreAlloc = config.getBoolean(MongoDBConstants.CFG_KEY_NOPREALLOC, null); this.smallFiles = config.getBoolean(MongoDBConstants.CFG_KEY_SMALLFILES, null); this.noTableScan = config.getBoolean(MongoDBConstants.CFG_KEY_NOTABLESCAN, null); this.oplogSize = config.getInteger(MongoDBConstants.CFG_KEY_OPLOGSIZE, null); this.nsSize = config.getInteger(MongoDBConstants.CFG_KEY_NSSIZE, null); this.slowMs = config.getInteger(MongoDBConstants.CFG_KEY_SLOWMS, null); this.rest = config.getBoolean(MongoDBConstants.CFG_KEY_REST, null); this.noHttpInterface = config.getBoolean(MongoDBConstants.CFG_KEY_NOHTTP, null); this.journalCommitInterval = config.getInteger(MongoDBConstants.CFG_KEY_JOURNALINTERVAL, null); this.noUnixSockets = config.getBoolean(MongoDBConstants.CFG_KEY_NOUNIX, null); this.objCheck = config.getBoolean(MongoDBConstants.CFG_KEY_OBJCHECK, null); }