List of usage examples for org.apache.commons.configuration Configuration getKeys
Iterator getKeys(String prefix);
From source file:com.wingnest.blueprints.impls.jpa.internal.wrappers.EntityManagerFactoryWrapper.java
@SuppressWarnings("rawtypes") private static Map getProperties(Configuration configuration) { Iterator<String> it = configuration.getKeys(BLUEPRINTS_JPAGRAPH_PERSISTENCE_UNIT_PROPERTIES); Properties props = new Properties(); while (it.hasNext()) { String key = it.next();/* w ww .j a v a2 s. co m*/ String newkey = key.substring(BLUEPRINTS_JPAGRAPH_PERSISTENCE_UNIT_PROPERTIES.length() + 1) .replaceAll("\\.\\.", "."); String value = configuration.getString(key); props.put(newkey, value); logger.debug("EntityManagerFactory getProperties : key = " + newkey + ", value = " + value); } return props; }
From source file:io.servicecomb.serviceregistry.config.ConfigurePropertyUtils.java
public static Map<String, String> getPropertiesWithPrefix(Configuration configuration, String prefix) { Map<String, String> propertiesMap = new HashMap<>(); Iterator<String> keysIterator = configuration.getKeys(prefix); while (keysIterator.hasNext()) { String key = keysIterator.next(); propertiesMap.put(key.substring(prefix.length() + 1), String.valueOf(configuration.getProperty(key))); }/*w w w. j a v a 2 s.co m*/ return propertiesMap; }
From source file:com.wingnest.rexster.config.JpaGraphConfiguration.java
@Override public Graph configureGraphInstance(GraphConfigurationContext confContext) throws GraphConfigurationException { Configuration properties = confContext.getProperties(); String unitName = properties.getString(TOKEN_JPA_GRAPH_UNIT_NAME); Iterator<String> it = properties.getKeys(TOKEN_PROPERTIES); Properties props = new Properties(); while (it.hasNext()) { String key = it.next();/*from ww w .j a v a 2 s . com*/ String newkey = key.substring(TOKEN_PROPERTIES.length() + 1).replaceAll("\\.\\.", "."); props.put(newkey, properties.getString(key)); } return new JpaGraph(unitName, props); }
From source file:io.mindmaps.graql.internal.analytics.DegreeVertexProgram.java
@Override public void loadState(final Graph graph, final Configuration configuration) { this.selectedTypes = new HashSet<>(); configuration.getKeys(TYPE).forEachRemaining(key -> selectedTypes.add(configuration.getString(key))); }
From source file:io.mindmaps.graql.internal.analytics.DegreeAndPersistVertexProgram.java
@Override public void loadState(final Graph graph, final Configuration configuration) { this.selectedTypes = new HashSet<>(); configuration.getKeys(TYPE).forEachRemaining(key -> selectedTypes.add(configuration.getString(key))); keySpace = configuration.getString(KEYSPACE); }
From source file:io.mindmaps.graql.internal.analytics.CountMapReduce.java
@Override public void loadState(final Graph graph, final Configuration configuration) { this.memoryKey = configuration.getString(COUNT_MEMORY_KEY, DEFAULT_MEMORY_KEY); this.selectedTypes = new HashSet<>(); configuration.getKeys(TYPE).forEachRemaining(key -> selectedTypes.add(configuration.getString(key))); }
From source file:com.boozallen.cognition.lens.LensAPI.java
/** * Helper method for creating the spark context from the given cognition configuration * @return a new configured spark context *///from ww w . j a v a2 s .c om public SparkContext createSparkContext() { SparkConf conf = new SparkConf(); Configuration config = cognition.getProperties(); conf.set("spark.serializer", KryoSerializer.class.getName()); conf.setAppName(config.getString("app.name")); conf.setMaster(config.getString("master")); Iterator<String> iterator = config.getKeys("spark"); while (iterator.hasNext()) { String key = iterator.next(); conf.set(key, config.getString(key)); } SparkContext sc = new SparkContext(conf); for (String jar : config.getStringArray("jars")) { sc.addJar(jar); } return sc; }
From source file:com.netflix.config.ConcurrentCompositeConfiguration.java
/** * Get the list of the keys contained in the sub configurations that match the * specified prefix./*from w w w .j ava 2 s . com*/ * */ @Override public Iterator<String> getKeys(String prefix) { Set<String> keys = new LinkedHashSet<String>(); for (Iterator<String> it = overrideProperties.getKeys(prefix); it.hasNext();) { keys.add(it.next()); } for (Configuration config : configList) { for (Iterator<String> it = config.getKeys(prefix); it.hasNext();) { keys.add(it.next()); } } return keys.iterator(); }
From source file:com.nesscomputing.service.discovery.client.DiscoveryClientModule.java
@Provides @Singleton//ww w . j a va 2s. c om @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; }
From source file:org.ambraproject.web.VirtualJournalContextFilter.java
/** * Process all <${journal-name}><rules><${http-header-name}>s looking for a match. * This method is only used to fetch rules from configuration and find matching journal based on request. * * @param configuration <code>Configuration</code> that contains the rules. * @param request <code>HttpServletRequest</code> to apply the rules against. * @return VirtualJournalContext. May be <code>null</code>. *///from w ww .jav a 2 s . c o m private String findMatchingVirtualJournal(Configuration configuration, HttpServletRequest request) { String virtualJournal = null; // process all <virtualjournal><journals> entries looking for a match final List<String> journals = configuration.getList(CONF_VIRTUALJOURNALS_JOURNALS); final Iterator<String> onJournal = journals.iterator(); while (onJournal.hasNext() && virtualJournal == null) { final String journal = onJournal.next(); if (log.isTraceEnabled()) { log.trace("processing virtual journal: " + journal); } // get the <rules> for this journal final String rulesPrefix = CONF_VIRTUALJOURNALS + "." + journal + ".rules"; final Iterator rules = configuration.getKeys(rulesPrefix); while (rules.hasNext()) { final String rule = (String) rules.next(); final String httpHeader = rule.substring(rulesPrefix.length() + 1); final String httpValue = configuration.getString(rule); if (log.isTraceEnabled()) { log.trace("processing rule: " + httpHeader + " = " + httpValue); } // test Request HTTP header value against match final String reqHttpValue = request.getHeader(httpHeader); if (log.isTraceEnabled()) { log.trace("testing Request: " + httpHeader + "=" + reqHttpValue); } if (reqHttpValue == null) { if (httpValue == null) { virtualJournal = journal; break; } continue; } if (reqHttpValue.matches(httpValue)) { virtualJournal = journal; break; } } } // return match or null return virtualJournal; }